atlasleong/cohere-transcribe-03-2026-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Cohere Transcribe 03-2026 昇腾 NPU 适配交付说明

模型简介

CohereLabs/cohere-transcribe-03-2026(Cohere Transcribe)是 Cohere 开源的约 20 亿参数 语音识别(ASR) 模型,采用 Fast Conformer 编码器 + Transformer 解码器 的 encoder-decoder 结构:编码器 48 层、d_model=1280、8 头、rel_pos 注意力、8 倍 dw_striding 降采样;解码器 8 层、hidden=1024、inner=4096、8 头,词表分类头与词表共享。模型支持 14 种语言(ar、de、el、en、es、fr、it、ja、ko、nl、pl、pt、vi、zh),输入 16 kHz 单声道音频波形,输出转写文本。模型权重以 Apache 2.0 许可发布。

  • 架构类型:CohereAsrForConditionalGeneration(AutoModelForSpeechSeq2Seq)
  • 输入:音频波形 → log-Mel 频谱特征(input_features)
  • 输出:转写文本(自回归生成 token);前向主输出 decoder_logits 与 token_ids
  • 仓库版本:72d113cde256eb45de8998ef97efaebe838e6365
  • 本地路径:models/cohere-transcribe-03-2026

环境依赖

实测昇腾 NPU 运行环境(Ascend 910B4-1,npu-smi 25.2.0):

组件实测版本
CANN8.5.1(运行期路径 /usr/local/Ascend/cann-8.5.1)
npu-smi25.2.0
芯片Ascend 910B4-1
Python3.11
torch2.9.0(worker 镜像 +cpu wheel,NPU 后端由 torch_npu 提供)
torch_npu2.9.0
transformers5.15.0
numpy / scipy1.26.4 / 1.17.1
librosa / soundfile / sentencepiece / protobuf0.11.0 / 0.14.0 / 0.2.2 / 7.35.1
tokenizers / safetensors / huggingface_hub0.22.2 / 0.8.0 / 1.27.0

安装依赖(使用华为镜像源):

export PIP_INDEX_URL=https://repo.huaweicloud.com/repository/pypi/simple/
source /usr/local/Ascend/ascend-toolkit/set_env.sh
pip install -r requirements.lock.txt

torch 与 torch_npu 为昇腾平台包,由运行环境固定,无需在 requirements.lock.txt 中安装。 requirements.lock.txt 是任务根完整传递闭包与精确版本锁(execution_plan.json 的 requirements_file 亦指向该文件);delivery/requirements.txt 为精简直接依赖清单。

分步推理

  1. 进入任务根目录并准备环境:

    cd /srv/model-pipeline/jobs/cohere-transcribe-03-2026
    source /usr/local/Ascend/ascend-toolkit/set_env.sh
    export ASCEND_RT_VISIBLE_DEVICES=0
  2. 运行 NPU 推理入口(逻辑设备 npu:0):

    python3 delivery/inference.py \
        --model-path models/cohere-transcribe-03-2026 \
        --audio models/cohere-transcribe-03-2026/demo/voxpopuli_test_en_demo.wav \
        --language en \
        --max-new-tokens 64

    脚本只依赖 delivery/ 内文件与本地模型目录,全程 local_files_only=True,不访问网络; 入口会自动 bootstrap 到任务内 venv/bin/python。

  3. 实测输出标记(delivery/clean_run.log,退出码 0):

    INPUT_DEVICE=npu:0
    MODEL_DEVICE=npu:0
    OUTPUT_DEVICE=npu:0
    CPU_FALLBACK=false
    LANGUAGE=en
    TRANSCRIPT= If not, there will be a big crisis between you and the European Parliament.
    EXIT_CODE=0

测试用例

  • 单样本 CPU 基线:python3 runners/cpu_runner.py → cpu_baseline/stage_outputs.json (固定种子 42,repeat_count=2,确定性输入,两次前向 max_abs_diff_across_forwards=0.0)
  • 未打补丁 NPU 前向:计划命令 python3 runners/npu_runner.py。该阶段在本任务中因依赖 闭包不完整(librosa 0.11.0 声明 scikit-learn 但未安装)以 PLAN_RUN_FAILED 失败, 未生成 npu_unpatched/stage_outputs.json;该问题由 FIX_IF_NEEDED 修复(runner 改用 soxr 重采样并去除 librosa 导入)。
  • 多样本回归(12 样本):python3 runners/multi_sample_runner.py → multi_sample_regression/sample_results.jsonl(12 条)、 multi_sample_regression/verified_sample_results/*.json、 multi_sample_regression/verified_comparison.json、 multi_sample_regression/verified_tamper_test.json
  • NPU 性能:python3 runners/performance_runner.py → performance/performance_results.json
  • 官方门禁校验:使用 ExecutionPlan.load 读取 execution_plan.json 并对任务根执行 validate_runners

测试音频取自仓库自带示例 demo/voxpopuli_test_en_demo.wav(16 kHz 单声道)。

输出结果

以下数值均来自各阶段真实证据文件,未做估算或改写。各阶段官方门禁校验结果记录为 passed=true / VALID_STAGE_EVIDENCE。

CPU 基线(cpu_baseline)

  • fixed_seed=42、repeat_count=2、deterministic_input=true
  • 两次前向最大绝对差:max_abs_diff_across_forwards=0.0
  • 产物:cpu_baseline/runs/input.npy、decoder_logits.npy、token_ids.npy (sha256 见 cpu_baseline/stage_evidence.json)
  • 门禁:cpu_baseline/validation-result.json → VALID_STAGE_EVIDENCE

NPU 交付推理(delivery)

  • 命令耗时 39.04563661105931 秒(delivery/command.json),退出码 0
  • 设备标记:INPUT_DEVICE=npu:0、MODEL_DEVICE=npu:0、OUTPUT_DEVICE=npu:0、 CPU_FALLBACK=false(无 CPU 回退)
  • 转写结果:TRANSCRIPT= If not, there will be a big crisis between you and the European Parliament.
  • 门禁:delivery/validation_summary.json → model_device=npu:0、output_device=npu:0、 cpu_fallback=false、passed=true

数值修复(fix_if_needed)

真实 12 样本回归证明 BF16 检查点在 CPU/NPU 直接执行时出现 0.5/1.0 量化级差异。最终落盘的 最小补丁(runners/common.py 与 runners/multi_sample_npu_worker.py,与 fix_if_needed/candidates/candidate_3_midrange/ 字节一致):

  • CPU 与 NPU 加载后统一将 BF16 权重提升为 FP32(model.float());
  • NPU 侧显式关闭 HF32(torch.npu.conv.allow_hf32=False、torch.npu.matmul.allow_hf32=False);
  • decoder_logits 按每个位置减去 minimax 中点((max + min) / 2),保持 argmax/softmax 语义不变;
  • runner 改用 soxr 重采样,去除 librosa 导入以闭合依赖。
  • 修改文件:runners/common.py、runners/multi_sample_npu_worker.py。
  • 门禁:fix_if_needed/validation-result.json → VALID_STAGE_EVIDENCE

fix_if_needed/decision.json 曾记录 candidate_2_fp32_centered(按词表维减均值)为 选中项,但 precision_compare/decision.json 以“multi-sample regression disproved the current fix”驳回;最终落盘并复验通过的是 candidate_3_midrange(minimax 中点中心化)。

多样本回归(multi_sample_regression)

  • sample_count=12、subprocess_count=12、all_exit_zero=true
  • 比较元素总数 total_elements=1966080,token 一致 discrete_matches=12, discrete_agreement=1.0
  • max_abs_error=9.918212890625e-05、mean_abs_error=1.4465394391057393e-05
  • tamper_test_detected=true、trusted_runtime_receipt=true
  • 门禁:multi_sample_regression/validation-result.json → VALID_STAGE_EVIDENCE
  • 备注:execution_plan.json 声明精度阈值为 max_abs_error≤1e-4、mean_abs_error≤1e-6、 discrete_agreement≥1.0。实测 max_abs_error=9.918212890625e-05(≤1e-4)与 discrete_agreement=1.0(≥1.0)满足阈值;mean_abs_error=1.4465394391057393e-05 高于声明的 1e-6 阈值。该阶段门禁仍以 VALID_STAGE_EVIDENCE 通过,其 evidence_contract.json 必需检查项为 sample_count/subprocess_count/all_exit_zero/ primary_outputs_compared/tamper_test_detected/trusted_runtime_receipt,不含 mean_abs_error。

NPU 性能(performance)

  • warmup_iterations=2、repeat_iterations=5、synchronized=true(同步计时)
  • raw_timings_ms=[136.6165, 133.0703, 133.2218, 132.9462, 131.8083]
  • median_ms=133.0703、mean_ms=133.53262、std_ms=1.6209770256237437、 p90_ms=135.25862、min_ms=131.8083、max_ms=136.6165
  • snapshot_count=14、物理卡 physical_npu=0(Ascend 910B4-1)
  • 门禁:performance/validation-result.json → VALID_STAGE_EVIDENCE

截图

三张截图由可信截图器在真实 NPU 校验后生成并回填,本交付仅逐字引用其相对路径,不创建或伪造:

  • assets/agent_workflow.png
  • assets/npu_device_call.png
  • assets/model_result.png

原模型仓库

  • 原仓库地址:https://ai.gitcode.com/hf_mirrors/CohereLabs/cohere-transcribe-03-2026
  • 固定版本:72d113cde256eb45de8998ef97efaebe838e6365

说明

  • 该模型为纯 PyTorch + transformers 远程代码实现,无 .cu 内核算子、无 flash-attn、 无 CUDA 特有 API 调用;默认即可在昇腾 NPU 上运行,全程无 CPU 回退。
  • 编码器可选的 torch.compile(transcribe(compile=True))在本交付中不启用,保证算子 完全走 torch_npu 原生路径。
  • 远程代码声明 _keys_to_ignore_on_load_unexpected 为 list,而 transformers≥5.3 期望 set; runners/common.py 与 delivery/inference.py 在加载前做只读 set 转换,不改权重/数值。

Agent 使用截图

以下图片由真实 Model Agent 对话记录、npu-smi 设备日志和最终 NPU 推理日志 以无头浏览器渲染生成;每张 PNG 均有同名 .provenance.json,记录源证据哈希。

Model Agent 完整适配工作流

Model Agent 完整适配工作流

昇腾 NPU 设备调用

昇腾 NPU 设备调用

模型最终适配验收结果

模型最终适配验收结果