Views
No views yet
encoder, adapter, lm_head)1from transformers import AutoModelForCausalLM, AutoTokenizer
2from llmcompressor import oneshot
3from llmcompressor.modifiers.quantization import QuantizationModifier
4from llmcompressor.utils import dispatch_for_generation
5
6MODEL_ID = "stepfun-ai/Step-Audio-R1"
7
8# Load model
9model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto")
10tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
11
12# Configure the quantization algorithm and scheme
13# Quantize weights to FP4 with per group 16 via PTQ
14recipe = QuantizationModifier(targets="Linear", scheme="NVFP4A16", ignore=["lm_head", "re:encoder.*", "re:adapter.*"])
15
16# Apply quantization
17oneshot(model=model, recipe=recipe)
18
19# Save to disk in compressed-tensors format
20SAVE_DIR = "Step-Audio-R1-NVFP4A16"
21model.save_pretrained(SAVE_DIR, save_compressed=True)
22tokenizer.save_pretrained(SAVE_DIR)1git lfs install
2git clone https://huggingface.co/stepfun-ai/Step-Audio-R1hf download stepfun-ai/Step-Audio-R1 --local-dir ./Step-Audio-R1docker pull stepfun2025/vllm:step-audio-2-v20250909Step-Audio-R1 folder in the current directory.1docker run --rm -ti --gpus all \
2 -v $(pwd)/Step-Audio-R1:/Step-Audio-R1 \
3 -p 9999:9999 \
4 stepfun2025/vllm:step-audio-2-v20250909 \
5 -- vllm serve /Step-Audio-R1 \
6 --served-model-name Step-Audio-R1 \
7 --port 9999 \
8 --max-model-len 16384 \
9 --max-num-seqs 32 \
10 --tensor-parallel-size 4 \
11 --chat-template '{%- macro render_content(content) -%}{%- if content is string -%}{{- content.replace("<audio_patch>\n", "<audio_patch>") -}}{%- elif content is mapping -%}{{- content['"'"'value'"'"'] if '"'"'value'"'"' in content else content['"'"'text'"'"'] -}}{%- elif content is iterable -%}{%- for item in content -%}{%- if item.type == '"'"'text'"'"' -%}{{- item['"'"'value'"'"'] if '"'"'value'"'"' in item else item['"'"'text'"'"'] -}}{%- elif item.type == '"'"'audio'"'"' -%}<audio_patch>{%- endif -%}{%- endfor -%}{%- endif -%}{%- endmacro -%}{%- if tools -%}{{- '"'"'<|BOT|>system\n'"'"' -}}{%- if messages[0]['"'"'role'"'"'] == '"'"'system'"'"' -%}{{- render_content(messages[0]['"'"'content'"'"']) + '"'"'<|EOT|>'"'"' -}}{%- endif -%}{{- '"'"'<|BOT|>tool_json_schemas\n'"'"' + tools|tojson + '"'"'<|EOT|>'"'"' -}}{%- else -%}{%- if messages[0]['"'"'role'"'"'] == '"'"'system'"'"' -%}{{- '"'"'<|BOT|>system\n'"'"' + render_content(messages[0]['"'"'content'"'"']) + '"'"'<|EOT|>'"'"' -}}{%- endif -%}{%- endif -%}{%- for message in messages -%}{%- if message["role"] == "user" -%}{{- '"'"'<|BOT|>human\n'"'"' + render_content(message["content"]) + '"'"'<|EOT|>'"'"' -}}{%- elif message["role"] == "assistant" -%}{{- '"'"'<|BOT|>assistant\n'"'"' + (render_content(message["content"]) if message["content"] else '"'"''"'"') -}}{%- set is_last_assistant = true -%}{%- for m in messages[loop.index:] -%}{%- if m["role"] == "assistant" -%}{%- set is_last_assistant = false -%}{%- endif -%}{%- endfor -%}{%- if not is_last_assistant -%}{{- '"'"'<|EOT|>'"'"' -}}{%- endif -%}{%- elif message["role"] == "function_output" -%}{%- else -%}{%- if not (loop.first and message["role"] == "system") -%}{{- '"'"'<|BOT|>'"'"' + message["role"] + '"'"'\n'"'"' + render_content(message["content"]) + '"'"'<|EOT|>'"'"' -}}{%- endif -%}{%- endif -%}{%- endfor -%}{%- if add_generation_prompt -%}{{- '"'"'<|BOT|>assistant\n<think>\n'"'"' -}}{%- endif -%}' \
12 --enable-log-requests \
13 --interleave-mm-strings \
14 --trust-remote-codelocalhost:9999.1git clone https://github.com/stepfun-ai/vllm.git
2cd vllm1python3 -m venv .venv
2source .venv/bin/activate1# Use pre-compiled C++ extensions (Recommended)
2VLLM_USE_PRECOMPILED=1 pip install -e .git checkout step-audio-2-mini1# Ensure you are in the vllm directory and the virtual environment is activated
2source .venv/bin/activate
3
4python3 -m vllm.entrypoints.openai.api_server \
5 --model ../Step-Audio-R1 \
6 --served-model-name Step-Audio-R1 \
7 --port 9999 \
8 --host 0.0.0.0 \
9 --max-model-len 65536 \
10 --max-num-seqs 128 \
11 --tensor-parallel-size 4 \
12 --gpu-memory-utilization 0.85 \
13 --trust-remote-code \
14 --enable-log-requests \
15 --interleave-mm-strings \
16 --chat-template '{%- macro render_content(content) -%}{%- if content is string -%}{{- content.replace("<audio_patch>\n", "<audio_patch>") -}}{%- elif content is mapping -%}{{- content['"'"'value'"'"'] if '"'"'value'"'"' in content else content['"'"'text'"'"'] -}}{%- elif content is iterable -%}{%- for item in content -%}{%- if item.type == '"'"'text'"'"' -%}{{- item['"'"'value'"'"'] if '"'"'value'"'"' in item else item['"'"'text'"'"'] -}}{%- elif item.type == '"'"'audio'"'"' -%}<audio_patch>{%- endif -%}{%- endfor -%}{%- endif -%}{%- endmacro -%}{%- if tools -%}{{- '"'"'<|BOT|>system\n'"'"' -}}{%- if messages[0]['"'"'role'"'"'] == '"'"'system'"'"' -%}{{- render_content(messages[0]['"'"'content'"'"']) + '"'"'<|EOT|>'"'"' -}}{%- endif -%}{{- '"'"'<|BOT|>tool_json_schemas\n'"'"' + tools|tojson + '"'"'<|EOT|>'"'"' -}}{%- else -%}{%- if messages[0]['"'"'role'"'"'] == '"'"'system'"'"' -%}{{- '"'"'<|BOT|>system\n'"'"' + render_content(messages[0]['"'"'content'"'"']) + '"'"'<|EOT|>'"'"' -}}{%- endif -%}{%- endif -%}{%- for message in messages -%}{%- if message["role"] == "user" -%}{{- '"'"'<|BOT|>human\n'"'"' + render_content(message["content"]) + '"'"'<|EOT|>'"'"' -}}{%- elif message["role"] == "assistant" -%}{{- '"'"'<|BOT|>assistant\n'"'"' + (render_content(message["content"]) if message["content"] else '"'"''"'"') -}}{%- set is_last_assistant = true -%}{%- for m in messages[loop.index:] -%}{%- if m["role"] == "assistant" -%}{%- set is_last_assistant = false -%}{%- endif -%}{%- endfor -%}{%- if not is_last_assistant -%}{{- '"'"'<|EOT|>'"'"' -}}{%- endif -%}{%- elif message["role"] == "function_output" -%}{%- else -%}{%- if not (loop.first and message["role"] == "system") -%}{{- '"'"'<|BOT|>'"'"' + message["role"] + '"'"'\n'"'"' + render_content(message["content"]) + '"'"'<|EOT|>'"'"' -}}{%- endif -%}{%- endif -%}{%- endfor -%}{%- if add_generation_prompt -%}{{- '"'"'<|BOT|>assistant\n<think>\n'"'"' -}}{%- endif -%}'localhost:9999.1# Clone the repository containing example scripts
2git clone https://github.com/stepfun-ai/Step-Audio-R1.git r1-scripts
3
4# Run the example
5cd r1-scripts
6python examples-vllm_r1.py@article{tian2025step,
title={Step-Audio-R1 Technical Report},
author={Tian, Fei and Zhang, Xiangyu Tony and Zhang, Yuxin and Zhang, Haoyang and Li, Yuxin and Liu, Daijiao and Deng, Yayue and Wu, Donghang and Chen, Jun and Zhao, Liang and others},
journal={arXiv preprint arXiv:2511.15848},
year={2025}
}