feat: Add GGUF loading support for Llama 4 (text)#45546
Open
garybadwal wants to merge 1 commit intohuggingface:mainfrom
Open
feat: Add GGUF loading support for Llama 4 (text)#45546garybadwal wants to merge 1 commit intohuggingface:mainfrom
garybadwal wants to merge 1 commit intohuggingface:mainfrom
Conversation
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: ggml |
SunMarc
reviewed
Apr 21, 2026
Comment on lines
+1134
to
+1155
|
|
||
| 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", |
Member
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.
Comment on lines
+1163
to
+1172
| 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) | ||
|
|
Comment on lines
+1185
to
+1188
| # 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)) |
Author
|
Thanks @SunMarc, I'll check these and add more strong test case in this. Again thank you for your precision time. 🫡 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.