Skip to content

Add Whisper HF export (encoder, cross_kv, static-cache decoder) (#23901) - #23901

Merged
meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
JakeStevens:export-D125295057
Oct 28, 2026
Merged

meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
JakeStevens:export-D125295057

Conversation

@JakeStevens

@JakeStevens JakeStevens commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Add examples/audio/export_hf_whisper.py to export WhisperForConditionalGeneration directly through Transformers into one .ptn with three methods: encoder maps mel features to hidden states, cross_kv projects per-layer cross-attention keys then values, and decoder consumes token IDs, explicit cache positions, and those projections to produce logits. Self-attention uses zero-initialized mutable static-cache buffers. Positions and the causal mask derive from cache_position, so the runner needs no attention-mask input.

--dump_dir writes runner inputs and an eager greedy transcript with a fresh decoder, preserving the exported cache buffers. An unspecified forced language token is resolved from the example features through Transformers language detection, retaining subsequent forced-token positions. Sparse forced prefixes are rejected. Generation is capped at max_target_positions and skips the unused decoder call after the last requested token.

The export format is independent of the runtime engine. The exporter and the existing LLM example share lowering reports through examples/hf_llm/hf_utils.py. Tests validate native delegation, zero-initialized decoder caches, three-method packaging, and eager numerics. Runtime execution support and runner integration follow in later diffs.

Random-weight loading uses checkpoint generation settings when present, warns when the file is absent, and propagates malformed-config errors. Vector generation supports an unset EOS token by using an empty stop set.

Authored with assistance from Codex.

Reviewed By: digantdesai

Differential Revision: D125295057

@pytorch-bot

pytorch-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 New Failure, 6 Cancelled Jobs, 1 Unrelated Failure

As of commit 1ac7b5a with merge base 4e439f6 (image):

NEW FAILURE - The following job has failed:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@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 Oct 15, 2026
@meta-codesync

meta-codesync Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

@JakeStevens has exported this pull request. If you are a Meta employee, you can view the originating Diff in D125295057.

@github-actions

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.

@meta-codesync meta-codesync Bot changed the title Add Whisper HF export (encoder, cross_kv, static-cache decoder) Add Whisper HF export (encoder, cross_kv, static-cache decoder) (#23901) Oct 15, 2026
JakeStevens added a commit to JakeStevens/executorch that referenced this pull request Oct 15, 2026
…rch#23901)

Summary:
Pull Request resolved: pytorch#23901

Add `export_hf_whisper.py` to export `WhisperForConditionalGeneration` directly through Transformers into one `.ptn` with three methods: `encoder` maps mel features to hidden states, `cross_kv` projects per-layer cross-attention keys then values, and `decoder` consumes token IDs, explicit cache positions, and those projections to produce logits. Self-attention uses zero-initialized mutable static-cache buffers. Positions and the causal mask derive from `cache_position`, so the runner needs no attention-mask input.

`--dump_dir` writes runner inputs and an eager greedy transcript with a fresh decoder, preserving the exported cache buffers. An unspecified forced language token is resolved from the example features through Transformers language detection, retaining subsequent forced-token positions. Sparse forced prefixes are rejected. Generation is capped at `max_target_positions` and skips the unused decoder call after the last requested token.

The export format is independent of the runtime engine. Tests validate native delegation, zero-initialized decoder caches, three-method packaging, and eager numerics. Runtime execution support and runner integration follow in later diffs.

Random-weight loading uses checkpoint generation settings when present, warns when the file is absent, and propagates malformed-config errors. Vector generation supports an unset EOS token by using an empty stop set.

Authored with assistance from Codex.

Differential Revision: D125295057

@digantdesai digantdesai 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.

Review automatically exported from Phabricator review in Meta.

JakeStevens added a commit to JakeStevens/executorch that referenced this pull request Oct 27, 2026
…rch#23901)

Summary:

Add `examples/audio/export_hf_whisper.py` to export `WhisperForConditionalGeneration` directly through Transformers into one `.ptn` with three methods: `encoder` maps mel features to hidden states, `cross_kv` projects per-layer cross-attention keys then values, and `decoder` consumes token IDs, explicit cache positions, and those projections to produce logits. Self-attention uses zero-initialized mutable static-cache buffers. Positions and the causal mask derive from `cache_position`, so the runner needs no attention-mask input.

`--dump_dir` writes runner inputs and an eager greedy transcript with a fresh decoder, preserving the exported cache buffers. An unspecified forced language token is resolved from the example features through Transformers language detection, retaining subsequent forced-token positions. Sparse forced prefixes are rejected. Generation is capped at `max_target_positions` and skips the unused decoder call after the last requested token.

The export format is independent of the runtime engine. The exporter and the existing LLM example share lowering reports through `examples/hf_llm/hf_utils.py`. Tests validate native delegation, zero-initialized decoder caches, three-method packaging, and eager numerics. Runtime execution support and runner integration follow in later diffs.

Random-weight loading uses checkpoint generation settings when present, warns when the file is absent, and propagates malformed-config errors. Vector generation supports an unset EOS token by using an empty stop set.

Authored with assistance from Codex.

Reviewed By: digantdesai

Differential Revision: D125295057
JakeStevens added a commit to JakeStevens/executorch that referenced this pull request Oct 27, 2026
…rch#23901)

Summary:

Add `examples/audio/export_hf_whisper.py` to export `WhisperForConditionalGeneration` directly through Transformers into one `.ptn` with three methods: `encoder` maps mel features to hidden states, `cross_kv` projects per-layer cross-attention keys then values, and `decoder` consumes token IDs, explicit cache positions, and those projections to produce logits. Self-attention uses zero-initialized mutable static-cache buffers. Positions and the causal mask derive from `cache_position`, so the runner needs no attention-mask input.

`--dump_dir` writes runner inputs and an eager greedy transcript with a fresh decoder, preserving the exported cache buffers. An unspecified forced language token is resolved from the example features through Transformers language detection, retaining subsequent forced-token positions. Sparse forced prefixes are rejected. Generation is capped at `max_target_positions` and skips the unused decoder call after the last requested token.

The export format is independent of the runtime engine. The exporter and the existing LLM example share lowering reports through `examples/hf_llm/hf_utils.py`. Tests validate native delegation, zero-initialized decoder caches, three-method packaging, and eager numerics. Runtime execution support and runner integration follow in later diffs.

Random-weight loading uses checkpoint generation settings when present, warns when the file is absent, and propagates malformed-config errors. Vector generation supports an unset EOS token by using an empty stop set.

Authored with assistance from Codex.

Reviewed By: digantdesai

Differential Revision: D125295057
JakeStevens added a commit to JakeStevens/executorch that referenced this pull request Oct 28, 2026
…rch#23901)

Summary:

Add `examples/audio/export_hf_whisper.py` to export `WhisperForConditionalGeneration` directly through Transformers into one `.ptn` with three methods: `encoder` maps mel features to hidden states, `cross_kv` projects per-layer cross-attention keys then values, and `decoder` consumes token IDs, explicit cache positions, and those projections to produce logits. Self-attention uses zero-initialized mutable static-cache buffers. Positions and the causal mask derive from `cache_position`, so the runner needs no attention-mask input.

`--dump_dir` writes runner inputs and an eager greedy transcript with a fresh decoder, preserving the exported cache buffers. An unspecified forced language token is resolved from the example features through Transformers language detection, retaining subsequent forced-token positions. Sparse forced prefixes are rejected. Generation is capped at `max_target_positions` and skips the unused decoder call after the last requested token.

The export format is independent of the runtime engine. The exporter and the existing LLM example share lowering reports through `examples/hf_llm/hf_utils.py`. Tests validate native delegation, zero-initialized decoder caches, three-method packaging, and eager numerics. Runtime execution support and runner integration follow in later diffs.

Random-weight loading uses checkpoint generation settings when present, warns when the file is absent, and propagates malformed-config errors. Vector generation supports an unset EOS token by using an empty stop set.

Authored with assistance from Codex.

Reviewed By: digantdesai

Differential Revision: D125295057
JakeStevens added a commit to JakeStevens/executorch that referenced this pull request Oct 28, 2026
…rch#23901)

Summary:

Add `examples/audio/export_hf_whisper.py` to export `WhisperForConditionalGeneration` directly through Transformers into one `.ptn` with three methods: `encoder` maps mel features to hidden states, `cross_kv` projects per-layer cross-attention keys then values, and `decoder` consumes token IDs, explicit cache positions, and those projections to produce logits. Self-attention uses zero-initialized mutable static-cache buffers. Positions and the causal mask derive from `cache_position`, so the runner needs no attention-mask input.

`--dump_dir` writes runner inputs and an eager greedy transcript with a fresh decoder, preserving the exported cache buffers. An unspecified forced language token is resolved from the example features through Transformers language detection, retaining subsequent forced-token positions. Sparse forced prefixes are rejected. Generation is capped at `max_target_positions` and skips the unused decoder call after the last requested token.

The export format is independent of the runtime engine. The exporter and the existing LLM example share lowering reports through `examples/hf_llm/hf_utils.py`. Tests validate native delegation, zero-initialized decoder caches, three-method packaging, and eager numerics. Runtime execution support and runner integration follow in later diffs.

Random-weight loading uses checkpoint generation settings when present, warns when the file is absent, and propagates malformed-config errors. Vector generation supports an unset EOS token by using an empty stop set.

Authored with assistance from Codex.

Reviewed By: digantdesai

Differential Revision: D125295057
JakeStevens added a commit to JakeStevens/executorch that referenced this pull request Oct 28, 2026
…rch#23901)

Summary:

Add `examples/audio/export_hf_whisper.py` to export `WhisperForConditionalGeneration` directly through Transformers into one `.ptn` with three methods: `encoder` maps mel features to hidden states, `cross_kv` projects per-layer cross-attention keys then values, and `decoder` consumes token IDs, explicit cache positions, and those projections to produce logits. Self-attention uses zero-initialized mutable static-cache buffers. Positions and the causal mask derive from `cache_position`, so the runner needs no attention-mask input.

`--dump_dir` writes runner inputs and an eager greedy transcript with a fresh decoder, preserving the exported cache buffers. An unspecified forced language token is resolved from the example features through Transformers language detection, retaining subsequent forced-token positions. Sparse forced prefixes are rejected. Generation is capped at `max_target_positions` and skips the unused decoder call after the last requested token.

The export format is independent of the runtime engine. The exporter and the existing LLM example share lowering reports through `examples/hf_llm/hf_utils.py`. Tests validate native delegation, zero-initialized decoder caches, three-method packaging, and eager numerics. Runtime execution support and runner integration follow in later diffs.

Random-weight loading uses checkpoint generation settings when present, warns when the file is absent, and propagates malformed-config errors. Vector generation supports an unset EOS token by using an empty stop set.

Authored with assistance from Codex.

Reviewed By: digantdesai

Differential Revision: D125295057
…rch#23901)

Summary:
Pull Request resolved: pytorch#23901

Add `examples/audio/export_hf_whisper.py` to export `WhisperForConditionalGeneration` directly through Transformers into one `.ptn` with three methods: `encoder` maps mel features to hidden states, `cross_kv` projects per-layer cross-attention keys then values, and `decoder` consumes token IDs, explicit cache positions, and those projections to produce logits. Self-attention uses zero-initialized mutable static-cache buffers. Positions and the causal mask derive from `cache_position`, so the runner needs no attention-mask input.

`--dump_dir` writes runner inputs and an eager greedy transcript with a fresh decoder, preserving the exported cache buffers. An unspecified forced language token is resolved from the example features through Transformers language detection, retaining subsequent forced-token positions. Sparse forced prefixes are rejected. Generation is capped at `max_target_positions` and skips the unused decoder call after the last requested token.

The export format is independent of the runtime engine. The exporter and the existing LLM example share lowering reports through `examples/hf_llm/hf_utils.py`. Tests validate native delegation, zero-initialized decoder caches, three-method packaging, and eager numerics. Runtime execution support and runner integration follow in later diffs.

Random-weight loading uses checkpoint generation settings when present, warns when the file is absent, and propagates malformed-config errors. Vector generation supports an unset EOS token by using an empty stop set.

Authored with assistance from Codex.

Reviewed By: digantdesai

Differential Revision: D125295057
@meta-codesync
meta-codesync Bot merged commit cc2c9f1 into pytorch:main Oct 28, 2026
214 of 222 checks passed
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. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants