-
Notifications
You must be signed in to change notification settings - Fork 591
Register llama3-8b for HuggingFace conversion #4974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ecnal-cienet
wants to merge
1
commit into
feat/convert-post-training-tunix-onload
Choose a base branch
from
feat/hf-convert-model-registry
base: feat/convert-post-training-tunix-onload
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1640,6 +1640,40 @@ def __init__(self, **kwargs): | |||||||||||||||||||||
| mixtral_8x7b_config = transformers.MixtralConfig(**mixtral_8x7b_dict) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # from https://huggingface.co/mistralai/Mistral-7B-v0.1/blob/main/config.json | ||||||||||||||||||||||
| # | ||||||||||||||||||||||
| # Not registered in HF_MODEL_CONFIGS. Wiring mistral-7b to the Llama family's mapping, hooks and | ||||||||||||||||||||||
| # shapes converts cleanly -- 291/291 arrays, every name and shape matching the repo -- and produces | ||||||||||||||||||||||
| # numerically wrong weights: forward_pass_logit_checker measured KL 1.32e-01 mean / 3.03e-01 max | ||||||||||||||||||||||
| # against the 3e-3 the repo's own conversion tests use. Setting rope_max_timescale to v0.1's 10000 | ||||||||||||||||||||||
| # rather than the config's 1e6 made it worse (1.58e-01 / 3.65e-01), so the rope timescale is not | ||||||||||||||||||||||
| # what differs. Mistral needs its own mapping, and until it has one, the KeyError from converting | ||||||||||||||||||||||
| # it is the honest outcome: a structurally perfect checkpoint full of wrong numbers is worse. | ||||||||||||||||||||||
| mistral_7b_dict = { | ||||||||||||||||||||||
| "architectures": ["MistralForCausalLM"], | ||||||||||||||||||||||
| "bos_token_id": 1, | ||||||||||||||||||||||
| "eos_token_id": 2, | ||||||||||||||||||||||
| "hidden_act": "silu", | ||||||||||||||||||||||
| "hidden_size": 4096, | ||||||||||||||||||||||
| "initializer_range": 0.02, | ||||||||||||||||||||||
| "intermediate_size": 14336, | ||||||||||||||||||||||
| "max_position_embeddings": 32768, | ||||||||||||||||||||||
| "model_type": "mistral", | ||||||||||||||||||||||
| "num_attention_heads": 32, | ||||||||||||||||||||||
| "num_hidden_layers": 32, | ||||||||||||||||||||||
| "num_key_value_heads": 8, | ||||||||||||||||||||||
| "rms_norm_eps": 1e-05, | ||||||||||||||||||||||
| "rope_theta": 10000.0, | ||||||||||||||||||||||
| "sliding_window": 4096, | ||||||||||||||||||||||
| "tie_word_embeddings": False, | ||||||||||||||||||||||
| "torch_dtype": "bfloat16", | ||||||||||||||||||||||
| "transformers_version": "4.34.0.dev0", | ||||||||||||||||||||||
| "use_cache": True, | ||||||||||||||||||||||
| "vocab_size": 32000, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| mistral_7b_config = transformers.MistralConfig(**mistral_7b_dict) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # from https://huggingface.co/mistralai/Mixtral-8x22B-Instruct-v0.1/blob/main/config.json | ||||||||||||||||||||||
| mixtral_8x22b_dict = { | ||||||||||||||||||||||
| "architectures": ["MixtralForCausalLM"], | ||||||||||||||||||||||
|
|
@@ -1913,6 +1947,11 @@ def __init__(self, **kwargs): | |||||||||||||||||||||
| "qwen3-vl-2b": qwen3_vl_2b_config, | ||||||||||||||||||||||
| "qwen3-vl-4b": qwen3_vl_4b_config, | ||||||||||||||||||||||
| "qwen3-vl-30b-a3b": qwen3_vl_30b_a3b_config, | ||||||||||||||||||||||
| # Llama 3 and 3.1 8B are the same architecture, and their MaxText configs are identical, so | ||||||||||||||||||||||
| # the same HF config describes both for conversion purposes. It does carry 3.1's | ||||||||||||||||||||||
| # rope_scaling and 131072 context, which only matter to a consumer reading the written | ||||||||||||||||||||||
| # config.json rather than to the weight mapping itself. | ||||||||||||||||||||||
| "llama3-8b": llama31_8b_config, | ||||||||||||||||||||||
|
Comment on lines
+1950
to
+1954
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the newly defined
Suggested change
|
||||||||||||||||||||||
| "llama3.1-8b": llama31_8b_config, | ||||||||||||||||||||||
| "llama3.1-8b-Instruct": llama31_8b_config, | ||||||||||||||||||||||
| "llama3.1-70b": llama31_70b_config, | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure that the generated
config.jsonfor Llama 3 8B is correct, we should define a dedicatedllama3_8b_configthat does not include the Llama 3.1rope_scalingand has the correctmax_position_embeddingsof 8192. Reusing the Llama 3.1 config directly will cause downstream Hugging Face consumers to load the model with incorrect RoPE scaling and context length, leading to wrong outputs.