Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

compute_wer_by_line raises OverflowError at 32,768 tokens with NumPy 2.3.5

未关闭 适合新手
#3,781 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@carey-bk 已经在做这个了。

开始于 2026年10月19日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
numpy, python

调研方向

阅读 funasr/metrics/wer.py,尤其是 compute_wer_by_line 和第 137–144 行的矩阵初始化。在两个输入方向上,分别用 32,768 个 token 对比一个 token,复现报告中的边界情况,然后检查矩阵的整数表示和现有的错误计数结果。两个案例都能在不溢出的情况下返回预期的编辑距离以及插入或删除计数,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug needs triage

🐛 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
平均合并
1 天 46 分钟
30 天内合并 PR
36

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelscope/FunASR 的其他 Issue

查看 modelscope/FunASR 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。