[Feature]: PyTorch backend: let a Whisper request carry a precomputed log-mel spectrogram

未关闭
#22,906 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@lminer 已经在做这个了。

开始于 2026年10月26日。

  • #21045 来自 @lminer —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
12/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
停滞
技术栈
python, pytorch

调研方向

The request path for audio items lives in WhisperInputProcessor, which pads audio to the 30-second window before the encoder computes the log-mel spectrogram; WhisperEncoder.forward already accepts a precomputed spectrogram. Read how the processor handles the audio item, then check the shape validation against num_mel_bins. Done means a request with an input_features item reaches the encoder without recomputing mel and is rejected cleanly on wrong shapes, but this issue already has a linked open pull request (#21045) implementing it.

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

描述

Pytorch
🚀 The feature, motivation and pitch

On the PyTorch backend, a Whisper request can only carry audio: a file path or URL, an (array, sample_rate) tuple, or an {"array", "sampling_rate"} mapping. WhisperInputProcessor pads it to the 30-second window and the engine computes the log-mel spectrogram itself.

Some clients already have the spectrogram, because feature extraction runs elsewhere in their pipeline or is shared between models. They have no way to send it, so the audio has to be kept around and the log-mel computed a second time. WhisperEncoder.forward already accepts a spectrogram and skips the log-mel step for it; only the request path is missing.

The request: let the audio item be {"input_features": ...}, the array the checkpoint's WhisperFeatureExtractor returns for one window, as numpy or torch.

  • Each request picks its form by its item, so one LLM serves audio and spectrogram requests, also in the same batch. Nothing is configured on the LLM.
  • The shape is checked against the checkpoint (num_mel_bins by the extractor's frame count), and other shapes are rejected with a clear message.
  • A spectrogram that is already on the GPU stays there.
  • Encoder CUDA graphs, the decoder prompt and the max_tokens cap work the same way for both forms.
mel = extractor(wave, sampling_rate=sample_rate, truncation=False, return_tensors="np")["input_features"]
llm.generate([
    {"prompt": "", "multi_modal_data": {"audio": [(wave, sample_rate)]}},
    {"prompt": "", "multi_modal_data": {"audio": {"input_features": mel}}},
])
Alternatives
  • Choosing the form once per LLM. That forces a deployment to pick one form and to run two instances to serve both.
  • Sending the audio and letting the engine recompute the spectrogram, as today. That works, but repeats work the client has done and requires keeping the audio.
Additional context

#21045 implements this.

Before submitting a new issue...
  • Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
主要语言
Python
星标
15.2k
派生
3k
平均合并
2 天 21 小时
30 天内合并 PR
477

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

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

NVIDIA/TensorRT-LLM 的其他 Issue

查看 NVIDIA/TensorRT-LLM 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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