Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24635
Note: Links to docs will display an error until the docs builds have been completed. ❌ 134 New Failures, 8 Unrelated Failures, 10 Unclassified FailuresAs of commit c3d3ba5 with merge base c7f7931 ( NEW FAILURES - The following jobs have failed:
UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
01fcf32 to
05200ca
Compare
| directory (or only its config, with random weights), wraps it with the cache | ||
| adapter from ``transformers.integrations.executorch``, and exports the | ||
| ``(input_ids [1, T], cache_position [T])`` signature. Reports which operators | ||
| the native partitioner leaves behind. ``--gguf`` takes the weights from a GGUF |
There was a problem hiding this comment.
nit: sentence is cut in half here
There was a problem hiding this comment.
Fixed: this PR had accidentally dropped "the native partitioner leaves behind." from that sentence; restored it.
| config = model.config.get_text_config() | ||
| # The cache op attends every position it holds, so a windowed layer | ||
| # would silently attend past its window. | ||
| if "sliding_attention" in (getattr(config, "layer_types", None) or ()): |
There was a problem hiding this comment.
Claude says MistralConfig has layer_types=None and a sliding_window (4096 by default), so this check lets it through. Could it also reject when layer_types is unset but sliding_window is set?
https://huggingface.co/mistralai/Mistral-7B-v0.1/blob/main/config.json
There was a problem hiding this comment.
Good catch, thanks. --offgraph_cache now also rejects configs with no layer_types and a non-None sliding_window; Mistral, Mixtral, Phi3 and Starcoder2 window every layer in that case. When layer_types is set it stays authoritative, since Qwen2/3 and SmolLM3 can carry a sliding_window value they don't use.
05200ca to
655cb68
Compare
9cc9b4d to
57123b7
Compare
Add --offgraph_cache to the native HF LLM export. Attention routes through kvcache::update_and_attend, so the exported graph holds no KV cache buffers; the runtime supplies the cache. The native partitioner accepts the op, and golden samples come from the reference sequence cache. Also add the missing __main__ guard, without which python -m on the export script silently did nothing.
655cb68 to
c3d3ba5
Compare
Stack
Off-graph KV cache for the native ggml engine, through serving Muse Glimmer on it. Review bottom-up; each PR builds and passes its tests on its own.
Summary
Adds
--offgraph_cacheto the native backend's HF LLM export (backends/native/examples/hf_llm/export_hf_llm.py). With it, attention runs throughkvcache::update_and_attend, so the exported.ptnholds no KV cache buffers; the runtime supplies the cache.torch.ops.kvcache.update_and_attend.default.OffGraphLastTokenLMwraps the model withuse_cache=Falseand positions taken fromcache_position. While computing golden samples, it installs the referenceSequenceReferenceCachein the PythonREGISTRY; export only traces the op and needs no cache.--max_context_lengthand--kv_cache_dtypeonly describe an in-graph cache, so combining them with--offgraph_cacheis rejected.use_sliding_window) and chunked layers (Llama 4). The cache op attends every position it holds, so they would silently attend past their span, in eager and at runtime alike.REGISTRYonly insidecache_scope(), and uninstalled on exit.if __name__ == "__main__"guard. Without it,python -m ...export_hf_llmexited without exporting anything.Example (Llama 3.2 1B, Q4_K_M GGUF):
Test plan
test_export_hf_llm.pyadds five tests:test_offgraph_cache_matches_the_static_cache: off-graph eager logits match the static cache within 1e-5. The exported graph has oneupdate_and_attendper layer, noindex_copy_, and no mutated buffers.test_offgraph_cache_excludes_in_graph_cache_flags.test_offgraph_cache_rejects_sliding_window_layers(tiny Gemma 3).test_offgraph_cache_rejects_other_attention_layer_types(chunked_attention).test_offgraph_cache_scope_uninstalls_its_reference_cache.pytest backends/native/examples/hf_llm/test_export_hf_llm.py backends/native/test/test_partitioner.py backends/native/test/test_serialize.py: 132 passed.