Skip to content

Commit 4300a6b

Browse files
authored
feat(moss): support vLLM diarized responses (#3566)
Signed-off-by: LauraGPT <18321252+LauraGPT@users.noreply.github.com>
2 parents f0c5b4a + 14e154a commit 4300a6b

8 files changed

Lines changed: 314 additions & 70 deletions

File tree

‎docs/moss_transcribe_diarize.md‎

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ This guide was verified against:
2121
- source: `OpenMOSS/MOSS-Transcribe-Diarize@cb765f2b0fe6f7a298aa2002e2281ae693d1f3c3`
2222
- model: `OpenMOSS-Team/MOSS-Transcribe-Diarize@e8681d68e7042738ffca8ac8212bc8fcb1131ab8`
2323
- license: Apache-2.0 in the pinned upstream source and model metadata
24-
- vLLM nightly index: `68b4a1d582818e67adc903bf1b8fc5a5447da2fa`
24+
- vLLM release: `v0.27.1@6e448d0ea9bf3d88d898b65449ca6dc2aec170ac`
25+
- vLLM CUDA 12.9 x86_64 wheel SHA-256:
26+
`bf0d52faa2a51e7a01c6856a7a8a2d1307fd0ff711415d34168a67ffac0fa47b`
2527

2628
Pin all three revisions. The model uses `trust_remote_code`; do not execute a
2729
floating model revision in a production service.
@@ -76,36 +78,48 @@ model = AutoModel(
7678
backend="vllm",
7779
vllm_base_url="http://127.0.0.1:8898/v1",
7880
vllm_model="moss-transcribe-diarize",
81+
vllm_response_format="diarized_json",
7982
disable_update=True,
8083
)
8184
result = model.generate("audio.wav")[0]
8285
```
8386

8487
The vLLM adapter sends the documented OpenAI-compatible multipart request and
85-
normalizes the returned raw text. Authentication can be supplied with
86-
`vllm_api_key`; keep it in a secret store rather than source code.
88+
normalizes the official speaker-attributed `segments` directly into
89+
`sentence_info`. Authentication can be supplied with `vllm_api_key`; keep it
90+
in a secret store rather than source code.
91+
92+
`vllm_response_format="diarized_json"` is the structured production path on
93+
the pinned vLLM revision. The compatibility default remains `json` so existing
94+
clients keep the exact tagged generation in `raw_text`; in structured mode,
95+
`raw_text` is the cleaned `text` returned by vLLM and the authoritative speaker
96+
metadata is in `sentence_info`.
8797

8898
## Choose a serving path
8999

90100
| Path | Environment | Response contract | Use when |
91101
|---|---|---|---|
92-
| vLLM | CUDA 12 (`cu129`) or CUDA 13 (`cu130`) | `response_format=json` returns raw `[start][Sxx]text[end]` text | You already operate vLLM or need its scheduler |
102+
| vLLM | CUDA 12 (`cu129`) or CUDA 13 (`cu130`) | `response_format=diarized_json` returns OpenAI-compatible speaker segments; `response_format=json` keeps raw `[start][Sxx]text[end]` text | You already operate vLLM or need its scheduler |
93103
| SGLang Omni | CUDA 13 in the current upstream guide | `response_format=verbose_json` returns parsed segments | You need structured speaker segments directly from the API |
94104
| Transformers | PyTorch process | Python objects and raw tagged text | Evaluation, debugging, or custom preprocessing |
95105

96106
The two HTTP backends share `/v1/audio/transcriptions`, but their documented
97-
response formats are not interchangeable. Do not promise vLLM `segments`
98-
without testing the exact vLLM revision.
107+
response formats are not interchangeable. The pinned vLLM revision supports
108+
`diarized_json`; test the exact server revision before promising `segments`.
99109

100110
## vLLM
101111

102-
Create an isolated environment and install the upstream-pinned nightly build:
112+
Create an isolated environment and install the verified vLLM release:
103113

104114
```bash
105115
uv venv --python 3.12 .venv-moss
106-
uv pip install --python .venv-moss/bin/python -U 'vllm[audio]' \
107-
--torch-backend=auto \
108-
--extra-index-url https://wheels.vllm.ai/68b4a1d582818e67adc903bf1b8fc5a5447da2fa/cu129
116+
curl -fL \
117+
https://github.com/vllm-project/vllm/releases/download/v0.27.1/vllm-0.27.1%2Bcu129-cp38-abi3-manylinux_2_28_x86_64.whl \
118+
-o vllm-0.27.1+cu129-cp38-abi3-manylinux_2_28_x86_64.whl
119+
echo "bf0d52faa2a51e7a01c6856a7a8a2d1307fd0ff711415d34168a67ffac0fa47b vllm-0.27.1+cu129-cp38-abi3-manylinux_2_28_x86_64.whl" \
120+
| sha256sum -c -
121+
uv pip install --python .venv-moss/bin/python --torch-backend=auto \
122+
"vllm[audio] @ file://$PWD/vllm-0.27.1+cu129-cp38-abi3-manylinux_2_28_x86_64.whl"
109123
```
110124

111125
The `audio` extra is required. A plain `vllm` install can start the server but
@@ -124,13 +138,13 @@ CUDA_VISIBLE_DEVICES=0 .venv-moss/bin/vllm serve \
124138
--port 8898
125139
```
126140

127-
Submit audio and validate the speaker-tagged text:
141+
Submit audio and validate the official speaker-attributed response:
128142

129143
```bash
130144
curl -fsS http://127.0.0.1:8898/v1/audio/transcriptions \
131145
-F file=@audio.wav \
132146
-F model=moss-transcribe-diarize \
133-
-F response_format=json \
147+
-F response_format=diarized_json \
134148
-F temperature=0 \
135149
| tee moss-transcription.json
136150

@@ -140,19 +154,36 @@ import json
140154
with open("moss-transcription.json", encoding="utf-8") as stream:
141155
payload = json.load(stream)
142156
text = payload.get("text", "")
157+
segments = payload.get("segments", [])
143158
assert text.strip(), payload
144-
assert "[S01]" in text, text
145-
print(text)
159+
assert segments, payload
160+
assert all(
161+
isinstance(item.get("speaker"), str)
162+
and item.get("text")
163+
and item.get("start") <= item.get("end")
164+
for item in segments
165+
), payload
166+
print(text, sorted({item["speaker"] for item in segments}))
146167
PY
147168
```
148169

170+
For an audit of the model's compact tagged generation, repeat the request with
171+
`response_format=json` and verify `[S01]` appears in the returned `text`.
172+
149173
For long recordings, test `max_completion_tokens` against the longest expected
150174
meeting. A larger limit can increase memory use and tail latency.
151175

152176
### Reproduced vLLM contract
153177

154-
The FunASR ecosystem validation used vLLM
155-
`0.23.1rc1.dev949+g68b4a1d58`, Torch `2.11.0+cu129`, and one H100 80GB:
178+
The structured-response validation used vLLM 0.27.1, Torch
179+
`2.13.0+cu129`, and one H100 80GB. The 15.1685-second two-speaker probe
180+
(`43dccc068506439cb633b382b6b98185baa837363d08cc5f7152ca89b0fdc3c8`)
181+
returned two `diarized_json` segments labelled `S01` and `S02`; the same
182+
request through the FunASR adapter returned two monotonic `sentence_info`
183+
entries with the same speakers.
184+
185+
Earlier raw-response validation on vLLM
186+
`0.23.1rc1.dev949+g68b4a1d58`, Torch `2.11.0+cu129`, and one H100 80GB found:
156187

157188
- the bundled 6.000-second sample
158189
(`ea03e1f473ad1618a03da3327a545369cb8f6f06cb0f4115535e5a866167d47e`)
@@ -165,6 +196,12 @@ This proves the pinned API and speaker-return contract on those inputs. It is
165196
not a diarization accuracy result, overlap test, throughput benchmark, or
166197
production capacity claim.
167198

199+
The older nightly commit
200+
`68b4a1d582818e67adc903bf1b8fc5a5447da2fa` predates vLLM
201+
[`#48543`](https://github.com/vllm-project/vllm/pull/48543). It accepts
202+
`response_format=json` but returns HTTP 400 for `diarized_json`; upgrade to the
203+
verified release instead of silently retrying an expensive transcription.
204+
168205
The FunASR adapter was also tested on both `backend="hf"` and
169206
`backend="vllm"` with model revision
170207
`e8681d68e7042738ffca8ac8212bc8fcb1131ab8`. The 15.1685-second two-speaker

‎docs/moss_transcribe_diarize_zh.md‎

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ MOSS-Transcribe-Diarize 会联合生成转写、时间戳和 `[S01]` 等说话
1919
- 源码:`OpenMOSS/MOSS-Transcribe-Diarize@cb765f2b0fe6f7a298aa2002e2281ae693d1f3c3`
2020
- 模型:`OpenMOSS-Team/MOSS-Transcribe-Diarize@e8681d68e7042738ffca8ac8212bc8fcb1131ab8`
2121
- 许可证:固定上游源码和模型元数据中的 Apache-2.0
22-
- vLLM nightly 索引:`68b4a1d582818e67adc903bf1b8fc5a5447da2fa`
22+
- vLLM 发布版:`v0.27.1@6e448d0ea9bf3d88d898b65449ca6dc2aec170ac`
23+
- vLLM CUDA 12.9 x86_64 wheel SHA-256:
24+
`bf0d52faa2a51e7a01c6856a7a8a2d1307fd0ff711415d34168a67ffac0fa47b`
2325

2426
三者都要固定。模型依赖 `trust_remote_code`,生产服务不要执行浮动的模型 revision。
2527

@@ -68,34 +70,46 @@ model = AutoModel(
6870
backend="vllm",
6971
vllm_base_url="http://127.0.0.1:8898/v1",
7072
vllm_model="moss-transcribe-diarize",
73+
vllm_response_format="diarized_json",
7174
disable_update=True,
7275
)
7376
result = model.generate("audio.wav")[0]
7477
```
7578

76-
vLLM 适配器发送官方文档中的 OpenAI-compatible multipart 请求,并统一解析返回文本。
77-
认证可通过 `vllm_api_key` 提供;请放在 secret store,不要写入源码。
79+
vLLM 适配器发送官方文档中的 OpenAI-compatible multipart 请求,并把官方返回的
80+
speaker `segments` 直接映射到 `sentence_info`。认证可通过 `vllm_api_key` 提供;
81+
请放在 secret store,不要写入源码。
82+
83+
固定 vLLM revision 的生产结构化路径是
84+
`vllm_response_format="diarized_json"`。为保持已有客户端兼容,默认值仍是 `json`,
85+
此时 `raw_text` 保留原始标签生成;结构化模式下,`raw_text` 是 vLLM 返回的清理后
86+
`text`,权威说话人信息位于 `sentence_info`。
7887

7988
## 选择服务后端
8089

8190
| 路径 | 环境 | 响应契约 | 适用场景 |
8291
|---|---|---|---|
83-
| vLLM | CUDA 12(`cu129`)或 CUDA 13(`cu130`) | `response_format=json` 返回原始 `[start][Sxx]text[end]` 文本 | 已运行 vLLM,或需要其调度能力 |
92+
| vLLM | CUDA 12(`cu129`)或 CUDA 13(`cu130`) | `response_format=diarized_json` 返回 OpenAI-compatible 说话人 segments;`response_format=json` 保留原始 `[start][Sxx]text[end]` 文本 | 已运行 vLLM,或需要其调度能力 |
8493
| SGLang Omni | 当前上游指南为 CUDA 13 | `response_format=verbose_json` 返回解析后的 segments | API 需要直接返回结构化说话人分段 |
8594
| Transformers | PyTorch 进程 | Python 对象和原始标签文本 | 评测、排障或自定义预处理 |
8695

8796
两个 HTTP 后端都使用 `/v1/audio/transcriptions`,但官方文档中的响应格式不能混为
88-
一谈。没有对 exact vLLM revision 做验证时,不要承诺 vLLM 返回 `segments`。
97+
一谈。固定的 vLLM revision 支持 `diarized_json`;承诺 `segments` 前仍要验证实际
98+
部署的 exact server revision。
8999

90100
## vLLM
91101

92-
创建隔离环境并安装上游固定的 nightly build:
102+
创建隔离环境并安装已验证的 vLLM 发布版:
93103

94104
```bash
95105
uv venv --python 3.12 .venv-moss
96-
uv pip install --python .venv-moss/bin/python -U 'vllm[audio]' \
97-
--torch-backend=auto \
98-
--extra-index-url https://wheels.vllm.ai/68b4a1d582818e67adc903bf1b8fc5a5447da2fa/cu129
106+
curl -fL \
107+
https://github.com/vllm-project/vllm/releases/download/v0.27.1/vllm-0.27.1%2Bcu129-cp38-abi3-manylinux_2_28_x86_64.whl \
108+
-o vllm-0.27.1+cu129-cp38-abi3-manylinux_2_28_x86_64.whl
109+
echo "bf0d52faa2a51e7a01c6856a7a8a2d1307fd0ff711415d34168a67ffac0fa47b vllm-0.27.1+cu129-cp38-abi3-manylinux_2_28_x86_64.whl" \
110+
| sha256sum -c -
111+
uv pip install --python .venv-moss/bin/python --torch-backend=auto \
112+
"vllm[audio] @ file://$PWD/vllm-0.27.1+cu129-cp38-abi3-manylinux_2_28_x86_64.whl"
99113
```
100114

101115
必须安装 `audio` extra。只安装 plain `vllm` 时服务可以启动,但因为没有音频解码器,
@@ -113,13 +127,13 @@ CUDA_VISIBLE_DEVICES=0 .venv-moss/bin/vllm serve \
113127
--port 8898
114128
```
115129

116-
提交音频并验证说话人标签文本:
130+
提交音频并验证官方结构化说话人响应:
117131

118132
```bash
119133
curl -fsS http://127.0.0.1:8898/v1/audio/transcriptions \
120134
-F file=@audio.wav \
121135
-F model=moss-transcribe-diarize \
122-
-F response_format=json \
136+
-F response_format=diarized_json \
123137
-F temperature=0 \
124138
| tee moss-transcription.json
125139

@@ -129,18 +143,34 @@ import json
129143
with open("moss-transcription.json", encoding="utf-8") as stream:
130144
payload = json.load(stream)
131145
text = payload.get("text", "")
146+
segments = payload.get("segments", [])
132147
assert text.strip(), payload
133-
assert "[S01]" in text, text
134-
print(text)
148+
assert segments, payload
149+
assert all(
150+
isinstance(item.get("speaker"), str)
151+
and item.get("text")
152+
and item.get("start") <= item.get("end")
153+
for item in segments
154+
), payload
155+
print(text, sorted({item["speaker"] for item in segments}))
135156
PY
136157
```
137158

159+
如需审计模型原始紧凑标签生成,请把请求改为 `response_format=json`,并验证返回
160+
`text` 中包含 `[S01]`。
161+
138162
长音频需要按业务最长会议验证 `max_completion_tokens`。增大上限也会影响显存和尾延迟。
139163

140164
### 已复现的 vLLM 契约
141165

142-
FunASR 生态验证使用 vLLM `0.23.1rc1.dev949+g68b4a1d58`、Torch
143-
`2.11.0+cu129` 和一张 H100 80GB:
166+
结构化响应验证使用 vLLM 0.27.1、Torch `2.13.0+cu129` 和一张 H100 80GB。
167+
15.1685 秒双说话人样例
168+
(`43dccc068506439cb633b382b6b98185baa837363d08cc5f7152ca89b0fdc3c8`)
169+
返回两个 `diarized_json` segments,标签为 `S01`、`S02`;同一请求通过 FunASR
170+
适配器后,返回两个时间单调且说话人一致的 `sentence_info`。
171+
172+
较早的 raw-response 验证使用 vLLM `0.23.1rc1.dev949+g68b4a1d58`、Torch
173+
`2.11.0+cu129` 和一张 H100 80GB,结果如下:
144174

145175
- 仓库内 6.000 秒样例
146176
(`ea03e1f473ad1618a03da3327a545369cb8f6f06cb0f4115535e5a866167d47e`)
@@ -152,6 +182,11 @@ FunASR 生态验证使用 vLLM `0.23.1rc1.dev949+g68b4a1d58`、Torch
152182
这证明固定版本对这些输入满足 API 和说话人返回契约,不是 diarization 精度、重叠语音、
153183
吞吐或生产容量结论。
154184

185+
旧 nightly commit `68b4a1d582818e67adc903bf1b8fc5a5447da2fa` 早于 vLLM
186+
[`#48543`](https://github.com/vllm-project/vllm/pull/48543):它支持
187+
`response_format=json`,但 `diarized_json` 会返回 HTTP 400。应升级到已验证发布版,
188+
不要静默重试一次成本较高的转写请求。
189+
155190
FunASR 适配器还分别使用 `backend="hf"` 和 `backend="vllm"`,按模型 revision
156191
`e8681d68e7042738ffca8ac8212bc8fcb1131ab8` 做了真实测试。15.1685 秒的双说话人
157192
样例(`43dccc068506439cb633b382b6b98185baa837363d08cc5f7152ca89b0fdc3c8`)通过

0 commit comments

Comments
 (0)