-
Notifications
You must be signed in to change notification settings - Fork 146
[OpenVINO][Draft]support Hunyuan LLM #1429
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
Open
openvino-dev-samples
wants to merge
12
commits into
huggingface:main
Choose a base branch
from
openvino-dev-samples:hunyuan
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.
Open
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
800aae9
update hunyuan patcher
openvino-dev-samples 73193b2
update hunyuan patcher
openvino-dev-samples 150db50
update hunyuan patcher
openvino-dev-samples f051f08
align with tranformers
openvino-dev-samples 2c01397
update
openvino-dev-samples a7afdae
update with MistralDummyPastKeyValuesGenerator
openvino-dev-samples 116b098
update test case
openvino-dev-samples c4f7cc3
update test case
openvino-dev-samples 4127d04
Update optimum/exporters/openvino/model_configs.py
openvino-dev-samples 159574d
rebase
openvino-dev-samples c50b7a9
Update model_configs.py
openvino-dev-samples 4a34ab5
remove artifacts of merge
openvino-dev-samples 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
Some comments aren't visible on the classic Files Changed page.
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 |
---|---|---|
|
@@ -4490,3 +4490,54 @@ def generate_dummy_inputs(self, framework: str = "pt", **kwargs): | |
) | ||
|
||
return dummy_inputs | ||
|
||
|
||
class HunyuanDummyPastKeyValuesGenerator(DummyPastKeyValuesGenerator): | ||
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.num_key_value_heads = normalized_config.num_key_value_heads | ||
self.head_dim = normalized_config.attention_head_dim | ||
|
||
def generate(self, input_name: str, framework: str = "pt", int_dtype: str = "int64", float_dtype: str = "fp32"): | ||
shape = ( | ||
self.batch_size, | ||
self.num_key_value_heads, | ||
self.sequence_length, | ||
self.head_dim, | ||
) | ||
return [ | ||
( | ||
self.random_float_tensor(shape, framework=framework, dtype=float_dtype), | ||
self.random_float_tensor(shape, framework=framework, dtype=float_dtype), | ||
) | ||
for _ in range(self.num_layers) | ||
] | ||
|
||
|
||
@register_in_tasks_manager("hunyuan_v1_dense", *["text-generation", "text-generation-with-past"], library_name="transformers") | ||
class HunyuanOpenVINOConfig(TextDecoderWithPositionIdsOnnxConfig): | ||
MIN_TRANSFORMERS_VERSION = "4.54.0" | ||
|
||
DUMMY_INPUT_GENERATOR_CLASSES = (DummyTextInputGenerator, HunyuanDummyPastKeyValuesGenerator) | ||
DUMMY_PKV_GENERATOR_CLASS = HunyuanDummyPastKeyValuesGenerator | ||
openvino-dev-samples marked this conversation as resolved.
Show resolved
Hide resolved
|
||
NORMALIZED_CONFIG_CLASS = NormalizedTextConfig | ||
|
||
def patch_model_for_export( | ||
self, model: Union["PreTrainedModel", "TFPreTrainedModel"], model_kwargs: Optional[Dict[str, Any]] = None | ||
) -> "ModelPatcher": | ||
return UpdateCausalMaskModelPatcher(self, model, model_kwargs=model_kwargs) |
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
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.
why not use instead
MistralDummyPastKeyValuesGenerator
and set insteadnormalized_config.head_dim