-
Notifications
You must be signed in to change notification settings - Fork 257
[EXPERIMENT][WIP] Fix Eagle3 VLM draft model export/load (qwen3_vl_eagle3) #1901
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
mlukasze
wants to merge
1
commit into
huggingface:main
Choose a base branch
from
mlukasze:enable/AngelSlim-Qwen3-VL-4B-Instruct_eagle3
base: main
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.
+43
−2
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
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 |
|---|---|---|
|
|
@@ -895,6 +895,19 @@ def _from_pretrained( | |
| trust_remote_code (`bool`, *optional*, defaults to `False`): | ||
| Whether to trust remote code when loading model tokenizer/processor during quantization. | ||
| """ | ||
| if config.model_type not in MODEL_TYPE_TO_CLS_MAPPING: | ||
| archs = getattr(config, "architectures", None) or [] | ||
| if archs and "eagle3" in archs[0].lower(): | ||
| raise ValueError( | ||
| f"Model with architecture '{archs[0]}' (model_type='{config.model_type}') is a standalone " | ||
| "Eagle3 speculative-decoding draft model, not a multi-component VLM, even though its " | ||
| "config declares a VLM-oriented `modal_type`/`target_model_type`. Please load it with " | ||
| "`OVModelForCausalLM` instead of `OVModelForVisualCausalLM`." | ||
| ) | ||
| raise ValueError( | ||
| f"Unsupported model_type '{config.model_type}' for `OVModelForVisualCausalLM`. Supported " | ||
| f"model types are: {sorted(MODEL_TYPE_TO_CLS_MAPPING)}." | ||
| ) | ||
|
Comment on lines
+898
to
+910
Collaborator
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. not needed |
||
| model_cls = MODEL_TYPE_TO_CLS_MAPPING[config.model_type] | ||
| model_file_names = model_cls._all_ov_model_paths.copy() | ||
| for k in tuple(model_file_names): | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -1114,6 +1114,32 @@ def test_exporters_cli_int8(self, task: str, model_type: str): | |
| del expected_int8["decoder_with_past"] | ||
| check_compression_state_per_model(self, model.ov_models, expected_int8) | ||
|
|
||
| @parameterized.expand(["fp16", "int8", "int4"]) | ||
|
Collaborator
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. fix tests |
||
| def test_exporters_cli_eagle3_vlm_quantization(self, weight_format: str): | ||
| # Regression test: exporting the VLM-flavored Eagle3 draft model (e.g. AngelSlim's | ||
| # Qwen3-VL eagle3 checkpoints) with any weight format used to fail with | ||
| # `KeyError: 'input_ids'` in `generate_dummy_inputs` because `eagle3_vlm` configs | ||
| # replace `input_ids` with `inputs_embeds` (see model_configs.py LlamaOpenVINOConfig). | ||
| model_type = "qwen3_vl_eagle3" | ||
| task = "text-generation-with-past" | ||
| with TemporaryDirectory() as tmpdir: | ||
| add_ops = "--group-size 16" if weight_format == "int4" else "" | ||
| subprocess.run( | ||
| f"optimum-cli export openvino --model {MODEL_NAMES[model_type]} --task {task} " | ||
| f"--trust-remote-code --weight-format {weight_format} {add_ops} {tmpdir}", | ||
| shell=True, | ||
| check=True, | ||
| ) | ||
| # Must be loaded with OVModelForCausalLM: it is a standalone draft causal LM, | ||
| # not a multi-component VLM, even though its config carries VLM-oriented fields. | ||
| model = OVModelForCausalLM.from_pretrained(tmpdir, use_cache=True) | ||
| self.assertTrue(model.stateful) | ||
|
|
||
| # Loading the same export with OVModelForVisualCausalLM must raise a clear, | ||
| # actionable error instead of a bare `KeyError: 'llama'`. | ||
| with self.assertRaisesRegex(ValueError, "OVModelForCausalLM"): | ||
| OVModelForVisualCausalLM.from_pretrained(tmpdir, use_cache=True) | ||
|
|
||
| @parameterized.expand(SUPPORTED_SD_HYBRID_ARCHITECTURES) | ||
| def test_exporters_cli_hybrid_quantization( | ||
| self, model_type: str, expected_fake_nodes: int, expected_int8_nodes: int | ||
|
|
||
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.
risky change because we have other vlm models. It can affect them