NeMo
Safetensors
GGUF
English
audio
audio-annotation
speech-recognition
speaker-diarization
emotion-recognition
sound-event-detection
vocal-burst
pipeline
mirror
imatrix
conversational
Instructions to use laion/universal-audio-annotation-pipeline with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- NeMo
How to use laion/universal-audio-annotation-pipeline with NeMo:
# tag did not correspond to a valid NeMo domain.
- llama-cpp-python
How to use laion/universal-audio-annotation-pipeline with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="laion/universal-audio-annotation-pipeline", filename="models/gemma-4-12b-it-gguf/gemma-4-12b-it-Q8_0.gguf", )
llm.create_chat_completion( messages = "No input example has been defined for this model task." )
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use laion/universal-audio-annotation-pipeline with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf laion/universal-audio-annotation-pipeline:Q8_0 # Run inference directly in the terminal: llama-cli -hf laion/universal-audio-annotation-pipeline:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf laion/universal-audio-annotation-pipeline:Q8_0 # Run inference directly in the terminal: llama-cli -hf laion/universal-audio-annotation-pipeline:Q8_0
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf laion/universal-audio-annotation-pipeline:Q8_0 # Run inference directly in the terminal: ./llama-cli -hf laion/universal-audio-annotation-pipeline:Q8_0
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf laion/universal-audio-annotation-pipeline:Q8_0 # Run inference directly in the terminal: ./build/bin/llama-cli -hf laion/universal-audio-annotation-pipeline:Q8_0
Use Docker
docker model run hf.co/laion/universal-audio-annotation-pipeline:Q8_0
- LM Studio
- Jan
- Ollama
How to use laion/universal-audio-annotation-pipeline with Ollama:
ollama run hf.co/laion/universal-audio-annotation-pipeline:Q8_0
- Unsloth Studio
How to use laion/universal-audio-annotation-pipeline with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for laion/universal-audio-annotation-pipeline to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for laion/universal-audio-annotation-pipeline to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for laion/universal-audio-annotation-pipeline to start chatting
- Pi
How to use laion/universal-audio-annotation-pipeline with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf laion/universal-audio-annotation-pipeline:Q8_0
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "laion/universal-audio-annotation-pipeline:Q8_0" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use laion/universal-audio-annotation-pipeline with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf laion/universal-audio-annotation-pipeline:Q8_0
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default laion/universal-audio-annotation-pipeline:Q8_0
Run Hermes
hermes
- Docker Model Runner
How to use laion/universal-audio-annotation-pipeline with Docker Model Runner:
docker model run hf.co/laion/universal-audio-annotation-pipeline:Q8_0
- Lemonade
How to use laion/universal-audio-annotation-pipeline with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull laion/universal-audio-annotation-pipeline:Q8_0
Run and chat with the model
lemonade run user.universal-audio-annotation-pipeline-Q8_0
List all available models
lemonade list
File size: 20,187 Bytes
ce6d303 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 | # MOSS-Audio SGLang Usage Guide
Quick Jump: [English](#english-version) | [中文](#chinese-version)
---
<a id="english-version"></a>
### Installation
```bash
git clone -b moss-audio https://github.com/OpenMOSS/sglang.git
cd sglang
pip install -e "python[all]"
pip install nvidia-cudnn-cu12==9.16.0.29
```
If you have already downloaded the model locally, such as `./weights/MOSS-Audio`, `./weights/MOSS-Audio-Instruct`, or `./weights/MOSS-Audio-Thinking`, you can directly pass that local path to `--model-path`.
### Notes
All MOSS-Audio model weights already include a multimodal chat template (`chat_template.jinja`), so you do not need to provide an extra template file. Both `/generate` and `/v1/chat/completions` can be used directly.
All commands below assume you are already running inside an environment where `sglang` has been installed.
If you are using `torch==2.9.1+cu128`, it is recommended to install `nvidia-cudnn-cu12==9.16.0.29` first. Otherwise, `sglang` may refuse to start because of a known CuDNN compatibility check.
### Launch Modes
#### Mode 1: Basic Service
Use this mode for audio transcription and text chat via `/generate` and `/v1/chat/completions`.
```bash
sglang serve \
--model-path ./weights/MOSS-Audio-4B-Thinking \
--trust-remote-code
```
#### Mode 2: Separate Reasoning
Based on Mode 1, this mode automatically splits `<think>...</think>` from the main response into the `reasoning_content` field.
```bash
sglang serve \
--model-path /path/to/moss-audio-model \
--trust-remote-code \
--reasoning-parser qwen3
```
#### Mode 3: Separate Reasoning + Thinking Budget Control (Recommended)
Based on Mode 2, this mode adds thinking budget control using the instruction injection approach described in the Qwen3 technical report.
```bash
sglang serve \
--model-path /path/to/moss-audio-model \
--trust-remote-code \
--reasoning-parser qwen3-instruction-injection \
--enable-custom-logit-processor
```
### Launch Arguments
| Argument | Description |
|---|---|
| `--reasoning-parser qwen3` | Split `<think>...</think>` using the Qwen3 format |
| `--reasoning-parser qwen3-instruction-injection` | Same as above, but also strips the transition sentence injected by thinking budget control |
| `--enable-custom-logit-processor` | Allows requests to pass a custom logit processor, required for thinking budget control |
### Request Patterns
#### 1. Native `/generate` (Available in all modes)
##### Basic audio transcription
```bash
curl -X POST http://localhost:30000/generate \
-H "Content-Type: application/json" \
-d '{
"text": "Please transcribe this audio.",
"audio_data": "/path/to/audio.wav",
"sampling_params": {
"max_new_tokens": 1024,
"temperature": 0.0
}
}'
```
Response:
```json
{
"text": "<think>\n</think>\n\nHere we go...",
"meta_info": {
"prompt_tokens": 403,
"completion_tokens": 88
}
}
```
##### `/generate` + post-processing reasoning split
Generate first, then split with `/separate_reasoning`:
```bash
curl -X POST http://localhost:30000/separate_reasoning \
-H "Content-Type: application/json" \
-d '{
"text": "<think>\nreasoning content\n</think>\n\nfinal answer content",
"reasoning_parser": "qwen3"
}'
```
Response:
```json
{
"reasoning_text": "reasoning content",
"text": "final answer content"
}
```
#### 2. OpenAI Chat `/v1/chat/completions` (Available in all modes)
##### Audio transcription + separated reasoning
```bash
curl -X POST http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "default",
"messages": [
{
"role": "user",
"content": [
{
"type": "audio_url",
"audio_url": {
"url": "/path/to/audio.wav"
}
},
{
"type": "text",
"text": "Please transcribe this audio."
}
]
}
],
"max_tokens": 1024,
"temperature": 0.0,
"separate_reasoning": true
}'
```
Response:
```json
{
"choices": [
{
"message": {
"role": "assistant",
"content": "Here we go...",
"reasoning_content": null
}
}
],
"usage": {
"prompt_tokens": 403,
"completion_tokens": 88
}
}
```
##### Pure text reasoning
```bash
curl -X POST http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "default",
"messages": [
{
"role": "user",
"content": "There are 3 people in a room. 2 leave, and then 5 enter. How many people are in the room now? Please reason step by step."
}
],
"max_tokens": 2048,
"temperature": 0.0,
"separate_reasoning": true
}'
```
Response:
```json
{
"choices": [
{
"message": {
"role": "assistant",
"content": "There are 6 people in the room in the end. ...",
"reasoning_content": "Let me solve this step by step. ..."
}
}
]
}
```
### Thinking Control
#### Method 1: Template-level switch (`enable_thinking`)
Use the chat template to control whether the model enters thinking mode. This only applies to pure text chat requests. Audio requests take the shortcut branch in the template, so this switch does not affect them.
```json
{
"model": "default",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 1024,
"chat_template_kwargs": {
"enable_thinking": false
}
}
```
#### Method 2: Thinking Budget (sampling-level control, requires Mode 3)
Use a custom logit processor to limit the number of tokens spent in thinking. Based on the Qwen3 technical report, once the budget is reached, a natural-language transition sentence is injected so the model can smoothly switch to answer mode.
##### Get the serialized processor string
```python
from sglang.srt.sampling.custom_logit_processor import Qwen3InstructionInjectionThinkingBudgetLogitProcessor
processor_str = Qwen3InstructionInjectionThinkingBudgetLogitProcessor.to_str()
print(processor_str)
```
##### Use it in OpenAI Chat
```bash
curl -X POST http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "default",
"messages": [
{
"role": "user",
"content": "Please explain quantum entanglement."
}
],
"max_tokens": 2048,
"temperature": 0.0,
"separate_reasoning": true,
"custom_logit_processor": "<processor_str>",
"custom_params": {
"thinking_budget": 50
}
}'
```
Replace `<processor_str>` with the string produced in the previous step.
##### Use it in `/generate`
```bash
curl -X POST http://localhost:30000/generate \
-H "Content-Type: application/json" \
-d '{
"text": "Please explain quantum entanglement.",
"sampling_params": {
"max_new_tokens": 2048,
"temperature": 0.0,
"custom_params": {
"thinking_budget": 50
}
},
"custom_logit_processor": "<processor_str>"
}'
```
##### Meaning of `thinking_budget`
| Value | Effect |
|---|---|
| `0` | No thinking allowed; inject the transition sentence immediately after `<think>` and close it |
| `50` | Allow up to 50 thinking tokens |
| `200` | Allow a longer chain of thought |
| not provided | No limit; the model can think freely |
#### Method 3: Streaming + hidden reasoning
```bash
curl -N http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "default",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 1024,
"stream": true,
"separate_reasoning": true,
"stream_reasoning": false
}'
```
In SSE, reasoning content is emitted through `delta.reasoning_content`, while the final answer is emitted through `delta.content`. When `stream_reasoning=false`, reasoning tokens are not streamed out token by token.
### Thinking Budget Processor Comparison
| | `Qwen3ThinkingBudgetLogitProcessor` | `Qwen3InstructionInjectionThinkingBudgetLogitProcessor` |
|---|---|---|
| Truncation style | Force `\n` → `</think>` | Inject the official Qwen3 transition sentence + `</think>` |
| Number of injected tokens | 2 | 24 |
| Whether the model "understands" the cutoff | No | Yes |
| Whether duplicated `</think>` may appear | Yes | No |
| Matching parser | `--reasoning-parser qwen3` | `--reasoning-parser qwen3-instruction-injection` |
Recommended combination: `Qwen3InstructionInjectionThinkingBudgetLogitProcessor` + `qwen3-instruction-injection`.
### Reasoning Parser Comparison
| | `qwen3` | `qwen3-instruction-injection` |
|---|---|---|
| Basic split behavior | Split by `<think>...</think>` | Same as left |
| Transition sentence cleanup | No | Strip the injected transition sentence from `reasoning_content` |
| Recommended scenario | When not using thinking budget | When using instruction injection budget |
### Quick Reference
#### Audio transcription (minimal)
```bash
sglang serve --model-path /path/to/moss-audio-model --trust-remote-code
curl -X POST http://localhost:30000/generate \
-H "Content-Type: application/json" \
-d '{"text":"Please transcribe this audio.","audio_data":"/path/to/audio.wav","sampling_params":{"max_new_tokens":1024,"temperature":0.0}}'
```
#### Audio transcription + separated thinking + budget control (full example)
```bash
sglang serve \
--model-path /path/to/moss-audio-model \
--trust-remote-code \
--reasoning-parser qwen3-instruction-injection \
--enable-custom-logit-processor
```
```python
from sglang.srt.sampling.custom_logit_processor import Qwen3InstructionInjectionThinkingBudgetLogitProcessor
import requests
processor_str = Qwen3InstructionInjectionThinkingBudgetLogitProcessor.to_str()
resp = requests.post("http://localhost:30000/v1/chat/completions", json={
"model": "default",
"messages": [
{
"role": "user",
"content": [
{"type": "audio_url", "audio_url": {"url": "/path/to/audio.wav"}},
{"type": "text", "text": "Please transcribe this audio."}
]
}
],
"max_tokens": 1024,
"temperature": 0.0,
"separate_reasoning": True,
"custom_logit_processor": processor_str,
"custom_params": {"thinking_budget": 50}
})
data = resp.json()
print("content:", data["choices"][0]["message"]["content"])
print("reasoning:", data["choices"][0]["message"]["reasoning_content"])
```
---
<a id="chinese-version"></a>
## 中文版
### 安装
```bash
git clone -b moss-audio https://github.com/OpenMOSS/sglang.git
cd sglang
pip install -e "python[all]"
pip install nvidia-cudnn-cu12==9.16.0.29
```
如果你已经把模型下载到本地,例如 `./weights/MOSS-Audio`、`./weights/MOSS-Audio-Instruct` 或 `./weights/MOSS-Audio-Thinking`,后面的 `--model-path` 可以直接写这些本地路径。
### 说明
所有 MOSS-Audio 模型权重均自带多模态 chat 模板(`chat_template.jinja`),无需额外指定模板文件。`/generate` 和 `/v1/chat/completions` 两种接口均可直接使用。
下面所有命令默认假设你已经在安装好 `sglang` 的环境中执行。
如果你使用的是 `torch==2.9.1+cu128`,建议先安装 `nvidia-cudnn-cu12==9.16.0.29`,否则 `sglang` 可能会因为已知的 CuDNN 兼容性检查而拒绝启动。
### 启动模式
#### 模式 1:基础服务
适用于 `/generate` 和 `/v1/chat/completions` 的音频转写与文本对话。
```bash
sglang serve \
--model-path /path/to/moss-audio-model \
--trust-remote-code
```
#### 模式 2:Reasoning 分离
在模式 1 基础上,自动将 `<think>...</think>` 从正文中拆分到 `reasoning_content` 字段。
```bash
sglang serve \
--model-path /path/to/moss-audio-model \
--trust-remote-code \
--reasoning-parser qwen3
```
#### 模式 3:Reasoning 分离 + Thinking Budget 控制(推荐)
在模式 2 基础上增加 thinking budget 控制能力,使用基于 Qwen3 技术报告的指令注入方案。
```bash
sglang serve \
--model-path /path/to/moss-audio-model \
--trust-remote-code \
--reasoning-parser qwen3-instruction-injection \
--enable-custom-logit-processor
```
### 启动参数说明
| 参数 | 作用 |
|---|---|
| `--reasoning-parser qwen3` | 按 Qwen3 格式拆分 `<think>...</think>` |
| `--reasoning-parser qwen3-instruction-injection` | 同上,额外清理 thinking budget 注入的过渡句 |
| `--enable-custom-logit-processor` | 允许请求传入自定义 logit processor(thinking budget 需要) |
### 请求方式
#### 1. 原生 `/generate`(所有模式可用)
##### 基础音频转写
```bash
curl -X POST http://localhost:30000/generate \
-H "Content-Type: application/json" \
-d '{
"text": "请转录这段音频。",
"audio_data": "/path/to/audio.wav",
"sampling_params": {
"max_new_tokens": 1024,
"temperature": 0.0
}
}'
```
返回:
```json
{
"text": "<think>\n</think>\n\n开始了开始了...",
"meta_info": {
"prompt_tokens": 403,
"completion_tokens": 88
}
}
```
##### `/generate` + 后置 reasoning 拆分
先生成,再用 `/separate_reasoning` 拆分:
```bash
curl -X POST http://localhost:30000/separate_reasoning \
-H "Content-Type: application/json" \
-d '{
"text": "<think>\n思考内容\n</think>\n\n正文内容",
"reasoning_parser": "qwen3"
}'
```
返回:
```json
{
"reasoning_text": "思考内容",
"text": "正文内容"
}
```
#### 2. OpenAI Chat `/v1/chat/completions`(所有模式可用)
##### 音频转写 + reasoning 分离
```bash
curl -X POST http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "default",
"messages": [
{
"role": "user",
"content": [
{
"type": "audio_url",
"audio_url": {
"url": "/path/to/audio.wav"
}
},
{
"type": "text",
"text": "请转录这段音频。"
}
]
}
],
"max_tokens": 1024,
"temperature": 0.0,
"separate_reasoning": true
}'
```
返回:
```json
{
"choices": [
{
"message": {
"role": "assistant",
"content": "开始了开始了...",
"reasoning_content": null
}
}
],
"usage": {
"prompt_tokens": 403,
"completion_tokens": 88
}
}
```
##### 纯文本推理
```bash
curl -X POST http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "default",
"messages": [
{
"role": "user",
"content": "一个房间里有3个人,2个人离开了,又进来了5个人。现在有多少人?请一步一步推理。"
}
],
"max_tokens": 2048,
"temperature": 0.0,
"separate_reasoning": true
}'
```
返回:
```json
{
"choices": [
{
"message": {
"role": "assistant",
"content": "最终房间里有9人。...",
"reasoning_content": "好,我现在来解决这个问题。..."
}
}
]
}
```
### Thinking 控制
#### 方式 1:模板级开关(`enable_thinking`)
通过 chat template 控制模型是否进入 thinking 模式。仅对纯文本 chat 请求生效;音频请求走模板的短路分支,此开关不生效。
```json
{
"model": "default",
"messages": [{"role": "user", "content": "你好"}],
"max_tokens": 1024,
"chat_template_kwargs": {
"enable_thinking": false
}
}
```
#### 方式 2:Thinking Budget(采样层控制,需要模式 3)
通过 custom logit processor 在采样时限制 thinking 的 token 数量。基于 Qwen3 技术报告,当 budget 到达时注入一段自然语言过渡句,让模型自然切换到 answer 模式。
##### 获取 processor 序列化字符串
```python
from sglang.srt.sampling.custom_logit_processor import Qwen3InstructionInjectionThinkingBudgetLogitProcessor
processor_str = Qwen3InstructionInjectionThinkingBudgetLogitProcessor.to_str()
print(processor_str)
```
##### 在 OpenAI Chat 中使用
```bash
curl -X POST http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "default",
"messages": [
{
"role": "user",
"content": "请解释量子纠缠。"
}
],
"max_tokens": 2048,
"temperature": 0.0,
"separate_reasoning": true,
"custom_logit_processor": "<processor_str>",
"custom_params": {
"thinking_budget": 50
}
}'
```
`<processor_str>` 替换为上一步生成的字符串。
##### 在 `/generate` 中使用
```bash
curl -X POST http://localhost:30000/generate \
-H "Content-Type: application/json" \
-d '{
"text": "请解释量子纠缠。",
"sampling_params": {
"max_new_tokens": 2048,
"temperature": 0.0,
"custom_params": {
"thinking_budget": 50
}
},
"custom_logit_processor": "<processor_str>"
}'
```
##### `thinking_budget` 值的含义
| 值 | 效果 |
|---|---|
| `0` | 不允许 thinking,`<think>` 后立刻注入过渡句并闭合 |
| `50` | 允许最多 50 个 token 的思考 |
| `200` | 允许较长的思考链 |
| 不传 | 不限制,模型自由思考 |
#### 方式 3:流式 + 隐藏 reasoning
```bash
curl -N http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "default",
"messages": [{"role": "user", "content": "你好"}],
"max_tokens": 1024,
"stream": true,
"separate_reasoning": true,
"stream_reasoning": false
}'
```
SSE 中 reasoning 内容走 `delta.reasoning_content`,正文走 `delta.content`。`stream_reasoning=false` 时不会逐 token 流出 reasoning。
### Thinking Budget Processor 对比
| | `Qwen3ThinkingBudgetLogitProcessor` | `Qwen3InstructionInjectionThinkingBudgetLogitProcessor` |
|---|---|---|
| 截断方式 | 强制 `\n` → `</think>` | 注入 Qwen3 官方过渡句 + `</think>` |
| 注入 token 数 | 2 | 24 |
| 模型是否“理解”截断 | 否 | 是 |
| 是否产生重复 `</think>` | 是 | 否 |
| 搭配 parser | `--reasoning-parser qwen3` | `--reasoning-parser qwen3-instruction-injection` |
推荐使用 `Qwen3InstructionInjectionThinkingBudgetLogitProcessor` + `qwen3-instruction-injection`。
### Reasoning Parser 对比
| | `qwen3` | `qwen3-instruction-injection` |
|---|---|---|
| 基础拆分 | 按 `<think>...</think>` 拆 | 同左 |
| 过渡句清理 | 不清理 | 从 `reasoning_content` 中 strip 注入的过渡句 |
| 适用场景 | 不使用 thinking budget 时 | 使用 instruction injection budget 时 |
### 快速参考
#### 音频转写(最简)
```bash
sglang serve --model-path /path/to/moss-audio-model --trust-remote-code
curl -X POST http://localhost:30000/generate \
-H "Content-Type: application/json" \
-d '{"text":"请转录这段音频。","audio_data":"/path/to/audio.wav","sampling_params":{"max_new_tokens":1024,"temperature":0.0}}'
```
#### 音频转写 + thinking 分离 + budget 控制(完整)
```bash
sglang serve \
--model-path /path/to/moss-audio-model \
--trust-remote-code \
--reasoning-parser qwen3-instruction-injection \
--enable-custom-logit-processor
```
```python
from sglang.srt.sampling.custom_logit_processor import Qwen3InstructionInjectionThinkingBudgetLogitProcessor
import requests
processor_str = Qwen3InstructionInjectionThinkingBudgetLogitProcessor.to_str()
resp = requests.post("http://localhost:30000/v1/chat/completions", json={
"model": "default",
"messages": [
{
"role": "user",
"content": [
{"type": "audio_url", "audio_url": {"url": "/path/to/audio.wav"}},
{"type": "text", "text": "请转录这段音频。"}
]
}
],
"max_tokens": 1024,
"temperature": 0.0,
"separate_reasoning": True,
"custom_logit_processor": processor_str,
"custom_params": {"thinking_budget": 50}
})
data = resp.json()
print("content:", data["choices"][0]["message"]["content"])
print("reasoning:", data["choices"][0]["message"]["reasoning_content"])
```
|