Skip to content
33 changes: 33 additions & 0 deletions optimum/exporters/openvino/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4645,6 +4645,39 @@ def generate_dummy_inputs(self, framework: str = "pt", **kwargs):

return dummy_inputs

class HunyuanDummyPastKeyValuesGenerator(GemmaDummyPastKeyValuesGenerator):
def __init__(
self,
task: str,
normalized_config: NormalizedTextConfig,
batch_size: int = DEFAULT_DUMMY_SHAPES["batch_size"],
sequence_length: int = DEFAULT_DUMMY_SHAPES["sequence_length"],
random_batch_size_range: Optional[Tuple[int, int]] = None,
random_sequence_length_range: Optional[Tuple[int, int]] = None,
**kwargs,
):
super().__init__(
task=task,
normalized_config=normalized_config,
batch_size=batch_size,
sequence_length=sequence_length,
random_batch_size_range=random_batch_size_range,
random_sequence_length_range=random_sequence_length_range,
)
self.head_dim = normalized_config.attention_head_dim

@register_in_tasks_manager("hunyuan_v1_dense", *["text-generation", "text-generation-with-past"], library_name="transformers")
class HunyuanOpenVINOConfig(TextDecoderWithPositionIdsOnnxConfig):
MIN_TRANSFORMERS_VERSION = "4.55.0.dev0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure that we need dev0 suffix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since optimum-intel does not support Transformers 4.56, this PR can only work with the commit for Transformers 4.55.

git+https://github.com/huggingface/transformers@4970b23cedaf745f963779b4eae68da281e8c6ca


DUMMY_INPUT_GENERATOR_CLASSES = (DummyTextInputGenerator, HunyuanDummyPastKeyValuesGenerator)
DUMMY_PKV_GENERATOR_CLASS = HunyuanDummyPastKeyValuesGenerator
NORMALIZED_CONFIG_CLASS = NormalizedTextConfig

def patch_model_for_export(
self, model: Union["PreTrainedModel", "TFPreTrainedModel"], model_kwargs: Optional[Dict[str, Any]] = None
) -> "ModelPatcher":
return OVDecoderModelPatcher(self, model, model_kwargs=model_kwargs)

@register_in_tasks_manager(
"gpt2",
Expand Down
4 changes: 4 additions & 0 deletions tests/openvino/test_decoder.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests for modelling to test generate() method is needed as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests for modelling to test generate() method is needed as well

its already covered in test_compare_to_transformers i think

Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase):

if is_transformers_version(">=", "4.55.0"):
SUPPORTED_ARCHITECTURES += ("gpt_oss", "gpt_oss_mxfp4")

if is_transformers_version(">=", "4.56.0"):
SUPPORTED_ARCHITECTURES += ("hunyuan_v1_dense",)

GENERATION_LENGTH = 100
REMOTE_CODE_MODELS = (
Expand Down Expand Up @@ -224,6 +227,7 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase):
"mamba": 0,
"falcon-mamba": 0,
"arcee": 2,
"hunyuan_v1_dense": 2,
}

# TODO: remove gptq/awq from here
Expand Down
3 changes: 3 additions & 0 deletions tests/openvino/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class ExportModelTest(unittest.TestCase):
SUPPORTED_ARCHITECTURES.update({"qwen3": OVModelForFeatureExtraction})

GENERATIVE_MODELS = ("pix2struct", "t5", "bart", "gpt2", "whisper", "llava", "speecht5")

if is_transformers_version(">=", "4.56"):
SUPPORTED_ARCHITECTURES.update({"hunyuan_v1_dense": OVModelForCausalLM})

def _openvino_export(
self,
Expand Down
1 change: 1 addition & 0 deletions tests/openvino/test_exporters_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class OVCLIExportTestCase(unittest.TestCase):
"mamba": 2,
"falcon-mamba": 2,
"qwen3": 2,
"hunyuan_v1_dense": 2,
}

TOKENIZER_CHAT_TEMPLATE_TESTS_MODELS = {
Expand Down
1 change: 1 addition & 0 deletions tests/openvino/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
"sana": "katuni4ka/tiny-random-sana",
"sana-sprint": "katuni4ka/tiny-random-sana-sprint",
"ltx-video": "katuni4ka/tiny-random-ltx-video",
"hunyuan_v1_dense": "snake7gun/tiny-random-hunyuan",
}


Expand Down