feat: Add GGUF loading support for Llama 4 (text)#45546
feat: Add GGUF loading support for Llama 4 (text)#45546garybadwal wants to merge 3 commits intohuggingface:mainfrom
Conversation
|
|
||
| def test_llama4_config_mapping(self): | ||
| """Test that Llama 4 GGUF config mapping is correctly registered.""" | ||
| from transformers.integrations.ggml import GGUF_CONFIG_MAPPING | ||
|
|
||
| self.assertIn("llama4", GGUF_CONFIG_MAPPING) | ||
| mapping = GGUF_CONFIG_MAPPING["llama4"] | ||
|
|
||
| expected_mappings = { | ||
| "context_length": "max_position_embeddings", | ||
| "block_count": "num_hidden_layers", | ||
| "feed_forward_length": "intermediate_size_mlp", | ||
| "expert_feed_forward_length": "intermediate_size", | ||
| "embedding_length": "hidden_size", | ||
| "rope.freq_base": "rope_theta", | ||
| "attention.key_length": "head_dim", | ||
| "attention.head_count": "num_attention_heads", | ||
| "attention.head_count_kv": "num_key_value_heads", | ||
| "attention.layer_norm_rms_epsilon": "rms_norm_eps", | ||
| "vocab_size": "vocab_size", | ||
| "expert_count": "num_local_experts", | ||
| "expert_used_count": "num_experts_per_tok", |
There was a problem hiding this comment.
those tests are a bit weak, not sure that passing the expected_mappings is a good enough test. we need to test the model and the tokenizer.
| def test_llama4_architecture_mapping(self): | ||
| """Test that Llama 4 text-only GGUFs route to GGUFLlamaConverter and Llama4TensorProcessor.""" | ||
| from transformers.integrations.ggml import GGUF_TO_FAST_CONVERTERS, GGUFLlamaConverter | ||
| from transformers.modeling_gguf_pytorch_utils import TENSOR_PROCESSORS, Llama4TensorProcessor | ||
|
|
||
| self.assertIn("llama4_text", GGUF_TO_FAST_CONVERTERS) | ||
| self.assertEqual(GGUF_TO_FAST_CONVERTERS["llama4_text"], GGUFLlamaConverter) | ||
| self.assertIn("llama4", TENSOR_PROCESSORS) | ||
| self.assertEqual(TENSOR_PROCESSORS["llama4"], Llama4TensorProcessor) | ||
|
|
| # Llama 4 is large and heavily quantised; we only check that the load path works end-to-end | ||
| # and produces a non-empty decoded string rather than asserting exact text. | ||
| decoded = tokenizer.decode(out[0], skip_special_tokens=True) | ||
| self.assertTrue(len(decoded) > len(self.example_text)) |
|
Thanks @SunMarc, I'll check these and add more strong test case in this. Again thank you for your precision time. 🫡 |
…move deprecated config mappings
|
[For maintainers] Suggested jobs to run (before merge) run-slow: ggml |
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45546&sha=44761d |
|
Hey @SunMarc, thanks for the feedback! I've addressed all three comments:
Regarding the CI failure, it's in My PR only touches ggml.py, |
What does this PR do?
Fixes #33260
Adds GGUF loading support for the Llama 4 text backbone (
llama4_text), the last major Llama-family architecture that still raisedGGUF model with architecture llama4 is not supported yet.Users can now do:Scope is text-only, matches what llama.cpp's convert_hf_to_gguf.py emits for Llama 4 (vision tensors are skipped there), and is consistent with the existing gemma3_text GGUF path.
Code Agent Policy
The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.
PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.
This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read
CONTRIBUTING.md.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@SunMarc — you own #33260 and the GGUF loader; would appreciate your review.
cc @MekkCyber @Isotr0py — you weighed in on #36144 (DeepSeek GGUF) and have context on the GGUF MoE pipeline.
cc @ArthurZucker — as maintainer of the Llama 4 text model in case anything about the MoE / tokenizer path looks off.