compute_wer_by_line raises OverflowError at 32,768 tokens with NumPy 2.3.5
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- numpy, python
- 領域
- backend, performance
調査の方向性
funasr/metrics/wer.pyを読み、特にcompute_wer_by_lineと137~144行目の行列の初期化を確認してください。両方の入力方向で、32,768個のトークンと1個のトークンの境界ケースを再現し、その後、行列の整数表現と既存の誤ったカウント結果を確認してください。両方のケースで、オーバーフローせずに期待される編集距離と挿入数または削除数が返されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
🐛 Bug
compute_wer_by_line uses an np.int16 edit-distance matrix. When either input reaches 32,768 tokens, initializing the first row or column raises OverflowError: Python integer 32768 out of bounds for int16 under NumPy 2.3.5.
This can be reproduced with one input containing 32,768 tokens and the other containing only one token. The matrix has just 65,538 cells; the failure does not require two long inputs or a large quadratic allocation. All tokens can be identical, so the expected edit distance is 32,767, which itself fits in int16. The initialization still tries to store 32,768.
Environment
- Repository: modelscope/FunASR
- Commit:
879a219c717123fdec6024e8e56c734a7aace2ff - Source: funasr/metrics/wer.py
- Python 3.12.14
- NumPy 2.3.5
To Reproduce
Save the code sample below as repro_wer.py in the checkout root and run python repro_wer.py.
Code sample
From a checkout of the commit above with NumPy 2.3.5 installed, run the following. This loads the exact upstream function via Python's AST so the reproduction does not require unrelated ASR dependencies or importing the full FunASR package.
import ast
from pathlib import Path
import numpy as np
path = Path("funasr/metrics/wer.py")
tree = ast.parse(path.read_text())
function = next(
node for node in tree.body
if isinstance(node, ast.FunctionDef)
and node.name == "compute_wer_by_line"
)
namespace = {"np": np}
exec(compile(ast.Module(body=[function], type_ignores=[]), str(path), "exec"), namespace)
compute_wer_by_line = namespace["compute_wer_by_line"]
for n in (32766, 32767, 32768, 32769):
for hyp, ref in ((["a"] * n, ["a"]), (["a"], ["a"] * n)):
try:
result = compute_wer_by_line(hyp, ref)
print(len(hyp), len(ref), "wrong:", result["wrong"])
except OverflowError as exc:
print(len(hyp), len(ref), type(exc).__name__ + ":", exc)
Error logs
Observed output:
32766 1 wrong: 32765
1 32766 wrong: 32765
32767 1 wrong: 32766
1 32767 wrong: 32766
32768 1 OverflowError: Python integer 32768 out of bounds for int16
1 32768 OverflowError: Python integer 32768 out of bounds for int16
32769 1 OverflowError: Python integer 32768 out of bounds for int16
1 32769 OverflowError: Python integer 32768 out of bounds for int16
The exception occurs at cost_matrix[i][0] = i (line 142) when the hypothesis is long, or cost_matrix[0][j] = j (line 144) when the reference is long, before the main dynamic-programming loop.
Expected behavior
For the 32,768-vs-1 identical-token case, return an edit distance of 32,767 with one correct token and 32,767 insertions (long hypothesis) or deletions (long reference), instead of failing during initialization.
The cost matrix should use an integer representation that can safely hold the initialized lengths and edit costs for supported inputs.
Scope of verification
This report verifies the function from the pinned commit above on Python 3.12.14 / NumPy 2.3.5. Both input directions were tested at 32,766, 32,767, 32,768 and 32,769 tokens, with the other input fixed at one token. Passing controls were also checked for correct, insertion, deletion and substitution counts. Earlier NumPy versions, full ASR inference and the CLI were not tested. No claim is made here about behavior on other NumPy versions or later FunASR revisions.
Audio details
Not applicable: synthetic token lists only, no model, audio, GPU, PyTorch or torchaudio used. Source function loaded without importing the full package.
Would a focused change to the edit-distance matrix integer representation be welcome for this boundary? I am reporting the reproduction before making changes.
- 主要言語
- Python
- スター
- 20.8k
- フォーク
- 2.1k
- 平均マージ
- 23時間 48分
- マージ済み PR(30日)
- 38
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelscope/FunASR のほかの issue
-
`SentencepiecesTokenizer.ids2tokens` ignores `token_list` - root cause of the paraformer-en gibberish in #3040対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
modelscope/FunASR#3780 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelscope/FunASR#3762 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Bug: blank lines in wav.scp / jsonl file lists crash prepare_data_iterator (IndexError / JSONDecodeError)対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンneeds feedback
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
modelscope/FunASR#3757 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
modelscope/FunASR#3730 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
modelscope/FunASR#3704 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
modelscope/FunASR の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ansys/pyansys-common-mcp#213 ·
メンテナーはふだん 3 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
freedomofpress/dangerzone#1594 ·
メンテナーはふだん 3 日以内に返信
-
priority:P1 status:in-review type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
randomparity/kdive#3317 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area:ci
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
mesonbuild/meson#16281 ·
メンテナーはふだん 1 日以内に返信