From 74e640c885922c436e4e400ea01e9474d310b825 Mon Sep 17 00:00:00 2001 From: Mingji Han Date: Mon, 28 Jul 2025 15:23:55 +0800 Subject: [PATCH 1/4] update --- .../models/hunyuan_v1_dense/modeling_hunyuan_v1_dense.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transformers/models/hunyuan_v1_dense/modeling_hunyuan_v1_dense.py b/src/transformers/models/hunyuan_v1_dense/modeling_hunyuan_v1_dense.py index 5394520220eb..4cb2d6371eac 100644 --- a/src/transformers/models/hunyuan_v1_dense/modeling_hunyuan_v1_dense.py +++ b/src/transformers/models/hunyuan_v1_dense/modeling_hunyuan_v1_dense.py @@ -5,7 +5,7 @@ import math import warnings -from typing import Optional, Union, Unpack +from typing import Optional, Union import torch import torch.nn.functional as F @@ -37,7 +37,7 @@ replace_return_docstrings, ) from transformers.utils.import_utils import is_torch_fx_available - +from ...processing_utils import Unpack from ...generation import GenerationMixin from .configuration_hunyuan_v1_dense import HunYuanDenseV1Config From 9e202b24a775babff6a363d706b411b045154149 Mon Sep 17 00:00:00 2001 From: Mingji Han Date: Mon, 28 Jul 2025 15:31:32 +0800 Subject: [PATCH 2/4] fix format --- .../models/hunyuan_v1_dense/modeling_hunyuan_v1_dense.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/transformers/models/hunyuan_v1_dense/modeling_hunyuan_v1_dense.py b/src/transformers/models/hunyuan_v1_dense/modeling_hunyuan_v1_dense.py index 4cb2d6371eac..cec99465a0ad 100644 --- a/src/transformers/models/hunyuan_v1_dense/modeling_hunyuan_v1_dense.py +++ b/src/transformers/models/hunyuan_v1_dense/modeling_hunyuan_v1_dense.py @@ -12,7 +12,7 @@ import torch.utils.checkpoint from torch import nn from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss -from ...utils import TransformersKwargs + from transformers.activations import ACT2FN from transformers.cache_utils import Cache, DynamicCache from transformers.modeling_attn_mask_utils import ( @@ -37,8 +37,10 @@ replace_return_docstrings, ) from transformers.utils.import_utils import is_torch_fx_available -from ...processing_utils import Unpack + from ...generation import GenerationMixin +from ...processing_utils import Unpack +from ...utils import TransformersKwargs from .configuration_hunyuan_v1_dense import HunYuanDenseV1Config @@ -1329,7 +1331,7 @@ def forward( output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, - **super_kwargs: Unpack[TransformersKwargs] + **super_kwargs: Unpack[TransformersKwargs], ) -> Union[tuple, CausalLMOutputWithPast]: r""" Args: From 38a21eeec470b26bede717e7da95c4faae344000 Mon Sep 17 00:00:00 2001 From: Mingji Han Date: Mon, 28 Jul 2025 15:35:29 +0800 Subject: [PATCH 3/4] update --- Makefile | 4 ++-- .../models/hunyuan_v1_moe/modeling_hunyuan_v1_moe.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 17315c8a9e2d..c18b5c1be225 100644 --- a/Makefile +++ b/Makefile @@ -73,8 +73,8 @@ extra_style_checks: # this target runs checks on all files and potentially modifies some of them style: - ruff check $(check_dirs) setup.py conftest.py --fix --exclude $(exclude_folders) - ruff format $(check_dirs) setup.py conftest.py --exclude $(exclude_folders) + python3 -m ruff check $(check_dirs) setup.py conftest.py --fix --exclude $(exclude_folders) + python3 -m ruff format $(check_dirs) setup.py conftest.py --exclude $(exclude_folders) ${MAKE} autogenerate_code ${MAKE} extra_style_checks diff --git a/src/transformers/models/hunyuan_v1_moe/modeling_hunyuan_v1_moe.py b/src/transformers/models/hunyuan_v1_moe/modeling_hunyuan_v1_moe.py index 655a4199a0d0..f851ca9457c7 100644 --- a/src/transformers/models/hunyuan_v1_moe/modeling_hunyuan_v1_moe.py +++ b/src/transformers/models/hunyuan_v1_moe/modeling_hunyuan_v1_moe.py @@ -50,6 +50,8 @@ from transformers.utils.import_utils import is_torch_fx_available from ...generation import GenerationMixin +from ...processing_utils import Unpack +from ...utils import TransformersKwargs from .configuration_hunyuan_v1_moe import HunYuanMoeV1Config @@ -739,7 +741,7 @@ def forward( "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class " "with a layer index." ) - kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx) + kv_seq_len += past_key_value.get_seq_length(self.layer_idx) if self.use_rotary_pos_emb: cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len) @@ -853,7 +855,7 @@ def forward( kv_seq_len = key_states.shape[-2] if past_key_value is not None: - kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx) + kv_seq_len += past_key_value.get_seq_length(self.layer_idx) if self.use_rotary_pos_emb: cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len) query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids) @@ -1393,7 +1395,7 @@ def forward( use_legacy_cache = not isinstance(past_key_values, Cache) if use_legacy_cache: past_key_values = DynamicCache.from_legacy_cache(past_key_values) - past_key_values_length = past_key_values.get_usable_length(seq_length) + past_key_values_length = past_key_values.get_seq_length() if position_ids is None: device = input_ids.device if input_ids is not None else inputs_embeds.device @@ -1544,6 +1546,7 @@ def forward( output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, + **super_kwargs: Unpack[TransformersKwargs], ) -> Union[tuple, CausalLMOutputWithPast]: r""" Args: From 3e033e6e33cebcd377f69a5ab36e950b8e33dd76 Mon Sep 17 00:00:00 2001 From: Mingji Han Date: Mon, 28 Jul 2025 15:37:17 +0800 Subject: [PATCH 4/4] revert makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c18b5c1be225..17315c8a9e2d 100644 --- a/Makefile +++ b/Makefile @@ -73,8 +73,8 @@ extra_style_checks: # this target runs checks on all files and potentially modifies some of them style: - python3 -m ruff check $(check_dirs) setup.py conftest.py --fix --exclude $(exclude_folders) - python3 -m ruff format $(check_dirs) setup.py conftest.py --exclude $(exclude_folders) + ruff check $(check_dirs) setup.py conftest.py --fix --exclude $(exclude_folders) + ruff format $(check_dirs) setup.py conftest.py --exclude $(exclude_folders) ${MAKE} autogenerate_code ${MAKE} extra_style_checks