Skip to content

Openvino whisper support - #21556

Open
suryasidd wants to merge 2 commits into
pytorch:mainfrom
suryasidd:openvino_whisper_support
Open

Openvino whisper support#21556
suryasidd wants to merge 2 commits into
pytorch:mainfrom
suryasidd:openvino_whisper_support

Conversation

@suryasidd

Copy link
Copy Markdown
Collaborator

Summary

Enabled whisper support for Executorch OV Backend

Test plan

By exporting and running inference from the README.md file.

Copilot AI review requested due to automatic review settings August 3, 2026 19:01
@pytorch-bot

pytorch-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21556

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure, 1 Cancelled Job

As of commit a83d689 with merge base e8feb9e (image):

NEW FAILURE - The following job has failed:

CANCELLED JOB - The following job was cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 3, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: suryasidd / name: Surya Siddharth Pemmaraju (a83d689)
  • ✅ login: suryasidd / name: suryasidd (95986f7)

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds an OpenVINO-compatible Whisper example by exporting Whisper into three ExecuTorch programs (encoder / cross-KV / decoder-with-cache) and providing scripts + docs to export and run inference.

Changes:

  • Introduces Whisper model split modules (encoder, cross-attention KV projection, decoder with self-attention cache).
  • Adds export and runtime scripts to generate and run encoder.pte, cross_kv.pte, decoder.pte plus metadata.json.
  • Adds example README and Python dependencies for the Whisper OpenVINO example.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
examples/openvino/whisper/whisper_model.py Implements the 3-way Whisper split and cached attention modules for export.
examples/openvino/whisper/export_whisper.py Exports and lowers the split modules to the OpenVINO backend and writes metadata.
examples/openvino/whisper/run_whisper.py Loads the exported programs and runs end-to-end greedy decoding.
examples/openvino/whisper/requirements.txt Adds Python dependencies needed to export/run the example.
examples/openvino/whisper/README.md Documents setup, export, and inference steps for the example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +49 to +57
features = processor(
audio_array,
sampling_rate=sampling_rate,
return_tensors="pt",
).input_features
max_frames = 3000
if features.shape[2] > max_frames:
features = features[:, :, :max_frames].contiguous()
return features
Comment on lines +96 to +107
def __init__(self, max_context_length, n_heads, head_dim, dtype):
super().__init__()
self.max_context_length = max_context_length
shape = (1, n_heads, max_context_length, head_dim)
self.register_buffer("k_cache", torch.zeros(shape, dtype=dtype))
self.register_buffer("v_cache", torch.zeros(shape, dtype=dtype))

def update(self, cache_position, k_val, v_val):
# cache_position: [S] (long), k_val/v_val: [B, H, S, D].
self.k_cache.index_copy_(2, cache_position, k_val)
self.v_cache.index_copy_(2, cache_position, v_val)
return self.k_cache, self.v_cache
Comment on lines +136 to +145
# Additive mask: 0 for valid positions [0..step], -inf for future positions.
base_mask = torch.full((1, 1, 1, max_cache), float("-inf"))
tokens = [start_token]
decode_start = time.perf_counter()
for step in range(args.max_new_tokens):
ids = torch.tensor([[tokens[-1]]], dtype=torch.long)
pos = torch.tensor([step], dtype=torch.long)
mask = base_mask.clone()
mask[..., : step + 1] = 0.0
logits = dec_method.execute([ids, pos, mask, *cross_k, *cross_v])[0]
Comment on lines +84 to +90
for i, (k_proj, v_proj) in enumerate(zip(self.k_projs, self.v_projs)):
H, D = self.num_heads_list[i], self.head_dim_list[i]
k = k_proj(encoder_hidden_states).view(B, T_enc, H, D).transpose(1, 2)
v = v_proj(encoder_hidden_states).view(B, T_enc, H, D).transpose(1, 2)
k_list.append(k.contiguous())
v_list.append(v.contiguous())
return tuple(k_list), tuple(v_list)
Comment on lines +1 to +4
transformers
soundfile
librosa
datasets
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants