Bug: cmvn readers raise IndexError on blank lines and return empty statistics without error
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- python
- Área
- machine-learning
Línea de trabajo
Start with funasr/frontends/wav_frontend.py:15 load_cmvn and funasr/frontends/default.py:390 MultiChannelFrontend._load_cmvn. Reproduce using the shipped am.mvn with a trailing blank line, an interrupted section, and compact tags, then verify both readers handle separators and truncated input without IndexError. Done means valid statistics still parse and files yielding no statistics raise a ValueError naming the cmvn file.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
🐛 Bug
FunASR has two cmvn readers in the installed package, and both walk the file line by line while indexing the result without any check:
funasr/frontends/wav_frontend.py:15 load_cmvn— used byWavFrontend/WavFrontendOnline, i.e. the frontend of the Paraformer and SenseVoice models most people load first;funasr/frontends/default.py:390 MultiChannelFrontend._load_cmvn— used byMultiChannelFrontend(emotion2vec / campplus).
for i in range(len(lines)):
line_item = lines[i].split()
if line_item[0] == "<AddShift>": # blank line -> IndexError
line_item = lines[i + 1].split() # tag on the last line -> IndexError
if line_item[0] == "<LearnRateCoef>":
Two distinct symptoms come out of this, both measured on main @ 66d7a4c2:
cmvn_file content |
wav_frontend.load_cmvn |
MultiChannelFrontend._load_cmvn |
|---|---|---|
runtime/triton_gpu/model_repo_sense_voice_small/feature_extractor/am.mvn (a real artifact this repository ships) |
OK, shape (2, 560) |
OK, shape (560,) |
| the same file plus one trailing blank line | IndexError: list index out of range |
IndexError: list index out of range |
a blank (or whitespace-only) line between <AddShift> and its <LearnRateCoef> line |
IndexError: list index out of range |
IndexError: list index out of range |
<AddShift> 2 2 as the last line (truncated file) |
IndexError: list index out of range |
IndexError: list index out of range |
statistics present but the tags do not start a line on their own, e.g. the whole <Nnet> on one line |
returns a tensor of shape (2, 0) — no error |
returns two empty arrays — no error |
The first four crash while the frontend is being constructed, so AutoModel(...) or a training run dies with a bare IndexError that never mentions the cmvn file. The fifth is worse because it is silent: load_cmvn returns empty statistics, WavFrontend builds without complaint, and the failure only appears at the first inference.
To Reproduce
- Install with:
pip install -e .(source checkout ofmain@66d7a4c2) - Copy the cmvn artifact the repository already ships and append a blank line:
cp runtime/triton_gpu/model_repo_sense_voice_small/feature_extractor/am.mvn /tmp/am.mvn && printf '\n' >> /tmp/am.mvn - Run the code sample below.
- See error:
IndexError: list index out of range
Code sample
from funasr.frontends.wav_frontend import WavFrontend
WavFrontend(cmvn_file="am.mvn", fs=16000, win_length=400, hop_length=160, n_mels=80)
# IndexError: list index out of range -- only when the file has an extra blank line;
# without the blank line the same call succeeds.
# silent variant: tags do not start a line on their own
from funasr.frontends.wav_frontend import load_cmvn
open("compact.mvn", "w").write(
"<Nnet> <AddShift> <LearnRateCoef> 1 [ -1.0 -2.0 ] </LearnRateCoef> "
"<Rescale> <LearnRateCoef> 1 [ 0.5 0.5 ] </LearnRateCoef> </Nnet>\n"
)
cmvn = load_cmvn("compact.mvn") # shape (2, 0), no error
Measured with n_mels=3 on the compact file, the frontend then builds fine and the first input_feats += self.mean / apply_cmvn call fails at inference time:
RuntimeError: The size of tensor a (3) must match the size of tensor b (0) at non-singleton dimension 1
MultiChannelFrontend behaves the same way (input_feats += self.mean against an empty registered buffer, funasr/frontends/default.py:355).
Expected behavior
A cmvn file that contains valid statistics should load regardless of blank or whitespace-only separator lines, and a file that yields no statistics should raise an error naming the file instead of returning empty arrays. Files that parse correctly today must keep parsing identically — the am.mvn above is the regression case.
Error logs
File ".../funasr/frontends/wav_frontend.py", line 27, in load_cmvn
if line_item[0] == "<AddShift>":
IndexError: list index out of range
Environment
- OS: Windows 11 (also reproduces on Linux — the loop is platform-independent)
- Python version: 3.13.7
- FunASR version: source,
main@66d7a4c2 - PyTorch / torchaudio version: 2.14.1+cpu / matching
- numpy: 2.5.3
- Install method: source (
pip install -e .) - Device:
cpu - No GPU, no model download needed — the reproduction uses the cmvn text file the repository already ships.
Audio details
Not applicable: no audio is involved, the defect is in the plain-text cmvn parser.
Suggested fix
For the two package readers:
- drop blank/whitespace-only lines before pairing a section tag with the line below it — that also makes
<AddShift>+ blank line +<LearnRateCoef>parse, and matches how this repository already reads other plain-text inputs (funasr/bin/realtime_ws.py:1363skips blank hotword lines,funasr/utils/compute_det_ctc.py:59skips blank stat lines); - bound the one-line lookahead so a truncated file cannot raise
IndexError; - raise a
ValueErrornaming the file when neither<AddShift>nor<Rescale>produced statistics, instead of handing back empty arrays — the same "say which cmvn file is wrong" convention the sibling runtime loader already uses (runtime/python/onnxruntime/funasr_onnx/utils/frontend.py:148raisesFileNotFoundError("cmvn file not exits")).
Five more copies of the same loop exist under runtime/ (runtime/python/libtorch/, runtime/python/onnxruntime/, runtime/triton_gpu/, export_lfr_cmvn_pe_onnx.py); they are standalone export/deployment helpers rather than the installed package, so I would scope any PR to the two package readers.
Filed with an AI coding agent, based on the measurements above that I ran locally on this machine.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 2.1k
- Merge medio
- 18 h 3 min
- PR fusionados (30 d)
- 88
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de modelscope/FunASR
-
AutoModel passes the original source rate to already-resampled speaker segmentsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
modelscope/FunASR#3762 ·
Los mantenedores suelen responder en 1 día
-
Bug: blank lines in wav.scp / jsonl file lists crash prepare_data_iterator (IndexError / JSONDecodeError)Posiblemente ocupada @Lesereingrape la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
modelscope/FunASR#3757 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
modelscope/FunASR#3730 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
modelscope/FunASR#3704 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
没有vllm时使用fun-asr-nano每次都重新加载模型Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug needs feedback
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
modelscope/FunASR#3401 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de modelscope/FunASR
Issues similares
-
[Bug]: Bedrock request metadata forwarding does not work for /embeddingsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug llm translation
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Arkansas 2025 tax is $1.70 high above $100,000 net taxable income ($3,809 + 3.9% rule)Posiblemente ocupada @PavelMakarchuk la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
PolicyEngine/policyengine-us#9828 ·
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
jellyfin/jellyfin-mpv-shim#800 ·
Los mantenedores suelen responder en 1 día
-
skillfs: one malformed chat-log line aborts the entire skill-usage analysis (skill_usage_from_chat_logs.py)Posiblemente ocupada @zjncs la tomó hoy. Abiertocomponent:skillfs
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
agentic-os-org/ANOLISA#6116 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
P4: low query
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
jeffknupp/association#336 ·