Skip to content

feat(audio): add flag for Whisper chunking (#19772) #19961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions vllm/entrypoints/openai/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,11 +1726,20 @@ class TranscriptionRequest(OpenAIBaseModel):

prompt: str = Field(default="")
"""An optional text to guide the model's style or continue a previous audio
segment.

The [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting)
segment. The [prompt](https://platform.openai.com/docs/guides/speech-to-text#prompting)
should match the audio language.
"""

reuse_initial_prompt: bool = Field(
default=False,
description=(
"If True, the same `prompt` is appended to every audio chunk "
"after the first one. If False (default), only the first chunk "
"receives the prompt."
),
)



response_format: AudioResponseFormat = Field(default="json")
"""
Expand Down
17 changes: 11 additions & 6 deletions vllm/entrypoints/openai/serving_transcription.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,21 @@ async def _preprocess_transcription(
chunks = [y] if duration < 30 else self._split_audio(y, sr)
prompts = []
for i, chunk in enumerate(chunks):
# Decide whether to pass the original prompt to this chunk
if i == 0 or request.reuse_initial_prompt:
decoder_prompt = (
f"<|startoftranscript|>{lang_token}<|transcribe|>"
f"<|notimestamps|>{request.prompt}"
)
else:
decoder_prompt = ""
Comment on lines +216 to +223
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic could be simplified by directly assigning the appropriate prompt based on the condition, instead of using an if/else block to assign to decoder_prompt.

            decoder_prompt = (
                f"<|startoftranscript|>{lang_token}<|transcribe|>"
                f"<|notimestamps|>{request.prompt}"
                if i == 0 or request.reuse_initial_prompt
                else ""
            )


prompt = {
"encoder_prompt": {
"prompt": "",
"multi_modal_data": {
"audio": (chunk, sr),
},
"multi_modal_data": {"audio": (chunk, sr)},
},
"decoder_prompt":
f"<|startoftranscript|>{lang_token}<|transcribe|><|notimestamps|>{request.prompt}"
if i == 0 else ""
"decoder_prompt": decoder_prompt,
}
prompts.append(cast(PromptType, prompt))
return prompts, duration
Expand Down
Loading