-
Notifications
You must be signed in to change notification settings - Fork 333
Support Hunyuan Dense V1 export #2189
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,59 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import importlib.util | ||
| import math | ||
| import sys | ||
| import types | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| BUILDERS_DIR = Path(__file__).parents[3] / "src" / "python" / "py" / "models" / "builders" | ||
| sys.path.insert(0, str(BUILDERS_DIR.parents[1])) | ||
|
|
||
|
|
||
| def _load_builder_module(module_name): | ||
| spec = importlib.util.spec_from_file_location(f"models.builders.{module_name}", BUILDERS_DIR / f"{module_name}.py") | ||
| module = importlib.util.module_from_spec(spec) | ||
| sys.modules[f"models.builders.{module_name}"] = module | ||
| spec.loader.exec_module(module) | ||
| return module | ||
|
|
||
|
|
||
| sys.modules.setdefault("models", types.ModuleType("models")) | ||
| builders_package = sys.modules.setdefault("models.builders", types.ModuleType("models.builders")) | ||
| builders_package.__path__ = [str(BUILDERS_DIR)] | ||
|
|
||
| base_module = _load_builder_module("base") | ||
| hunyuan_module = _load_builder_module("hunyuan") | ||
| HunyuanDenseV1Model = hunyuan_module.HunyuanDenseV1Model | ||
| Model = base_module.Model | ||
|
|
||
|
|
||
| def _build_hunyuan_config(config, monkeypatch): | ||
| def base_init(self, config, io_dtype, onnx_dtype, ep, cache_dir, extra_options): | ||
| self.config = config | ||
|
|
||
| monkeypatch.setattr(Model, "__init__", base_init) | ||
| return HunyuanDenseV1Model(config, None, None, "cpu", None, {}) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("rope_field", ["rope_scaling", "rope_parameters"]) | ||
| def test_hunyuan_dynamic_alpha_rope_is_baked_into_theta(rope_field, monkeypatch): | ||
| rope_config = {"type": "dynamic", "alpha": 1000.0, "rope_theta": 10000.0} | ||
| config_kwargs = { | ||
| "hidden_size": 2048, | ||
| "num_attention_heads": 16, | ||
| "head_dim": 128, | ||
| "rope_theta": None if rope_field == "rope_parameters" else 10000.0, | ||
| "rope_scaling": rope_config if rope_field == "rope_scaling" else None, | ||
| "rope_parameters": rope_config if rope_field == "rope_parameters" else None, | ||
| } | ||
| config = types.SimpleNamespace(**config_kwargs) | ||
|
|
||
| _build_hunyuan_config(config, monkeypatch) | ||
|
|
||
| expected_theta = 10000.0 * (1000.0 ** (128 / 126)) | ||
| assert math.isclose(config.rope_theta, expected_theta) | ||
| assert config.rope_scaling is None | ||
| assert config.rope_parameters is None |
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.
Uh oh!
There was an error while loading. Please reload this page.