-
Notifications
You must be signed in to change notification settings - Fork 31.9k
[Bugfix] Fix reloading of pixtral/llava configs #36077
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
Merged
zucchini-nlp
merged 9 commits into
huggingface:main
from
kylesayrs:redhat/fix-llava-config
Feb 14, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
79eb7ff
add is_composition flag to LlavaConfig
kylesayrs 3157d34
Merge branch 'main' into redhat/fix-llava-config
kylesayrs f549ead
WIP: pixtral text config
kylesayrs f5ebcb1
fix style
kylesayrs 1f0ae96
add test
kylesayrs a53d5f9
use is_composition for pixtral
kylesayrs 3ab1c99
Revert "use is_composition for pixtral"
kylesayrs abb0192
Revert "Revert "use is_composition for pixtral""
kylesayrs 95b1a84
Merge branch 'main' into redhat/fix-llava-config
kylesayrs 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
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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import tempfile | ||
| import unittest | ||
|
|
||
| from transformers import LlavaConfig | ||
|
|
||
|
|
||
| class LlavaConfigTest(unittest.TestCase): | ||
| def test_llava_reload(self): | ||
| """ | ||
| Simple test for reloading default llava configs | ||
| """ | ||
| with tempfile.TemporaryDirectory() as tmp_dir: | ||
| config = LlavaConfig() | ||
| config.save_pretrained(tmp_dir) | ||
|
|
||
| reloaded = LlavaConfig.from_pretrained(tmp_dir) | ||
| assert config.to_dict() == reloaded.to_dict() | ||
|
|
||
| def test_pixtral_reload(self): | ||
| """ | ||
| Simple test for reloading pixtral configs | ||
| """ | ||
| vision_config = { | ||
| "model_type": "pixtral", | ||
| "head_dim": 64, | ||
| "hidden_act": "silu", | ||
| "image_size": 1024, | ||
| "is_composition": True, | ||
| "patch_size": 16, | ||
| "rope_theta": 10000.0, | ||
| "tie_word_embeddings": False, | ||
| } | ||
|
|
||
| text_config = { | ||
| "model_type": "mistral", | ||
| "hidden_size": 5120, | ||
| "head_dim": 128, | ||
| "num_attention_heads": 32, | ||
| "intermediate_size": 14336, | ||
| "is_composition": True, | ||
| "max_position_embeddings": 1024000, | ||
| "num_hidden_layers": 40, | ||
| "num_key_value_heads": 8, | ||
| "rms_norm_eps": 1e-05, | ||
| "rope_theta": 1000000000.0, | ||
| "sliding_window": None, | ||
| "vocab_size": 131072, | ||
| } | ||
|
|
||
| with tempfile.TemporaryDirectory() as tmp_dir: | ||
| config = LlavaConfig(vision_config=vision_config, text_config=text_config) | ||
| config.save_pretrained(tmp_dir) | ||
|
|
||
| reloaded = LlavaConfig.from_pretrained(tmp_dir) | ||
| assert config.to_dict() == reloaded.to_dict() | ||
|
|
||
| def test_arbitrary_reload(self): | ||
| """ | ||
| Simple test for reloading arbirarily composed subconfigs | ||
| """ | ||
| default_values = LlavaConfig().to_dict() | ||
| default_values["vision_config"]["model_type"] = "qwen2_vl" | ||
| default_values["text_config"]["model_type"] = "opt" | ||
|
|
||
| with tempfile.TemporaryDirectory() as tmp_dir: | ||
| config = LlavaConfig(**default_values) | ||
| config.save_pretrained(tmp_dir) | ||
|
|
||
| reloaded = LlavaConfig.from_pretrained(tmp_dir) | ||
| assert config.to_dict() == reloaded.to_dict() | ||
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.
do we need this to be 128 to trigger the same error as currently?
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.
It's actually the head_dim on the
text_configthat triggers the issueThere 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.
oh right, my bad, didn't notice this was vision