Repository navigation
Add Whisper HF export (encoder, cross_kv, static-cache decoder) (#23901) - #23901
JakeStevens wants to merge 3 commits into
Conversation
🔗 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. ❌ 5 New Failures, 2 Unrelated FailuresAs of commit eccf758 with merge base e683360 ( NEW FAILURES - The following jobs have failed:
BROKEN TRUNK - The following jobs 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. |
|
@JakeStevens has exported this pull request. If you are a Meta employee, you can view the originating Diff in D125295057. |
This PR needs a
|
…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
5543487 to
679f1a1
Compare
digantdesai
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
…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
679f1a1 to
e77b21d
Compare
Summary: Add `EXECUTORCH_BUILD_NATIVE_LLM_RUNNER` to build and install `run_hf_llm_vulkan` and `run_hf_llm_ggml` for the enabled engines. Share gflags setup with the vision runner, resolve tokenizers with regex lookahead support, and add `native_llm_runner_utils_test`. Document building and running the GGML CPU LLM runner. Authored with assistance from Codex. Reviewed By: digantdesai Differential Revision: D125479665
Summary: Exported methods can reuse a constant name with different immutable tensors, causing `to_native` to reject the combined program. Namespace every immutable constant as `<method>/<key>`, including single-method programs, and update its graph references, including quantization metadata and nested graphs. Identical tensors still deduplicate when saving the `.ptn`. Keys mutated by any method use shared `state/<key>` names throughout the program, preserving state shared by readers and writers. Update non-persistent buffer bindings and mutation outputs consistently, and reserve the `state` method namespace. Reject differing values for shared mutable keys and collisions between final names. Authored with assistance from OpenAI Codex. Reviewed By: digantdesai Differential Revision: D125294428
…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
e77b21d to
eccf758
Compare
Summary:
Add
examples/audio/export_hf_whisper.pyto exportWhisperForConditionalGenerationdirectly through Transformers into one.ptnwith three methods:encodermaps mel features to hidden states,cross_kvprojects per-layer cross-attention keys then values, anddecoderconsumes 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 fromcache_position, so the runner needs no attention-mask input.--dump_dirwrites 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 atmax_target_positionsand 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