Skip to content

Commit a91eb79

Browse files
committed
fix compliation issue
- Update codes according to transformers version Signed-off-by: jiseong.oh <jiseong.oh@samsung.com>
1 parent 4f44126 commit a91eb79

11 files changed

Lines changed: 29 additions & 20 deletions

File tree

‎.github/workflows/lint.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
pip install -r requirements-lintrunner.txt
5959
USE_CPP=0 pip install --no-build-isolation third-party/ao
6060
# Match requirements-examples.txt for the model APIs checked by mypy.
61-
pip install pytest numpy parameterized huggingface_hub "transformers==5.0.0rc1" timm expecttest types-requests tosa-tools
61+
pip install pytest numpy parameterized huggingface_hub "transformers==5.11.0" timm expecttest types-requests tosa-tools
6262
6363
- name: Generate mypy stubs for C++ bindings
6464
run: |

‎backends/arm/test/models/Gemma3n/test_gemma3nModel.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def forward(
218218
attn_output, _ = self.attn(
219219
hidden_states=hidden_states,
220220
position_embeddings=(cos, sin),
221+
attention_mask=None,
221222
)
222223
return attn_output
223224

‎backends/arm/test/models/Qwen3_VL/test_qwen3_vl_layers.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ def __init__(self, config) -> None:
156156
head_dim = config.vision_config.hidden_size // config.vision_config.num_heads
157157
self.rotary = Qwen3VLVisionRotaryEmbedding(head_dim // 2)
158158

159-
def forward(self, max_hw: int) -> torch.Tensor:
160-
return self.rotary(max_hw)
159+
def forward(self, position_ids: torch.Tensor) -> torch.Tensor:
160+
return self.rotary(position_ids)
161161

162162
@classmethod
163163
def prepare_model_and_inputs(cls):
164164
config = _make_qwen3_vl_2b_instruct_layer_config()
165165
grid_thw = _make_image_grid_thw(torch.device("cpu"))
166166
max_hw = int(grid_thw[:, 1:].max().item())
167167
model = cls(config).eval()
168-
return model, (max_hw,)
168+
return model, (torch.arange(max_hw),)
169169

170170

171171
class VisionRotaryApplyModel(Qwen3VLTestModule):

‎backends/native/examples/audio/export_hf_whisper.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ def forward(
195195
cache_position: torch.Tensor,
196196
*cross_kv: torch.Tensor,
197197
) -> torch.Tensor:
198+
for layer in self.self_cache.layers:
199+
layer.cumulative_length = cache_position[:1].clone()
198200
num_layers = len(self.cross_cache.layers)
199201
for layer_idx, layer in enumerate(self.cross_cache.layers):
200202
layer.keys = cross_kv[layer_idx]

‎backends/native/examples/hf_llm/export_hf_llm.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
PreTrainedModel,
4545
)
4646
from transformers.cache_utils import StaticLayer
47-
from transformers.integrations.accelerate import init_empty_weights
4847
from transformers.integrations.executorch import TorchExportableModuleForDecoderOnlyLM
4948
from transformers.integrations.sdpa_attention import sdpa_attention_forward
5049
from transformers.masking_utils import (
@@ -64,6 +63,9 @@ def _load(
6463
text_config.layer_types = text_config.layer_types[:layers]
6564
kwargs = {"torch_dtype": torch.float32, "attn_implementation": "sdpa"}
6665
if empty_weights:
66+
# transformers 5.11 no longer ships init_empty_weights; only --gguf needs it.
67+
from accelerate import init_empty_weights
68+
6769
with init_empty_weights():
6870
model = AutoModelForCausalLM.from_config(config, **kwargs)
6971
elif random_weights:
@@ -161,7 +163,9 @@ def _store_kv_as(self, model: PreTrainedModel, dtype: torch.dtype) -> None:
161163
if type(old) is not StaticLayer:
162164
raise ValueError(f"cannot change the KV dtype of {type(old).__name__}")
163165
layer = _CastingStaticLayer(old.max_cache_len)
164-
layer.lazy_initialization(old.keys[:, :, :1].to(dtype))
166+
layer.lazy_initialization(
167+
old.keys[:, :, :1].to(dtype), old.values[:, :, :1].to(dtype)
168+
)
165169
self.cache.layers[i] = layer
166170
self.cached.register_buffer(f"key_cache_{i}", layer.keys, persistent=False)
167171
self.cached.register_buffer(
@@ -176,6 +180,9 @@ def _store_kv_as(self, model: PreTrainedModel, dtype: torch.dtype) -> None:
176180
def forward(
177181
self, input_ids: torch.Tensor, cache_position: torch.Tensor
178182
) -> torch.Tensor:
183+
# StaticLayer writes at cumulative_length and ignores cache_position.
184+
for layer in self.cache.layers:
185+
layer.cumulative_length = cache_position[:1].clone()
179186
return self.cached.model(
180187
input_ids=input_ids,
181188
cache_position=cache_position,

‎examples/qualcomm/oss_scripts/albert.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def main(args):
4949
random_ids = torch.randint(low=0, high=100, size=(1, 100), dtype=torch.int32)
5050
attention_mask = create_bidirectional_mask(
5151
config=module.config,
52-
input_embeds=module.albert.embeddings(random_ids),
52+
inputs_embeds=module.albert.embeddings(random_ids),
5353
attention_mask=torch.zeros((1, 100), dtype=torch.float32),
5454
)
5555
inputs = [
@@ -70,7 +70,7 @@ def main(args):
7070
input_ids,
7171
create_bidirectional_mask(
7272
config=module.config,
73-
input_embeds=module.albert.embeddings(input_ids),
73+
inputs_embeds=module.albert.embeddings(input_ids),
7474
attention_mask=attention_mask,
7575
),
7676
)

‎examples/qualcomm/oss_scripts/bert.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def main(args):
4747
random_ids = torch.randint(low=0, high=100, size=(1, 100), dtype=torch.int32)
4848
attention_mask = create_bidirectional_mask(
4949
config=module.config,
50-
input_embeds=module.bert.embeddings(random_ids),
50+
inputs_embeds=module.bert.embeddings(random_ids),
5151
attention_mask=torch.zeros((1, 100), dtype=torch.float32),
5252
)
5353
inputs = [
@@ -68,7 +68,7 @@ def main(args):
6868
input_ids,
6969
create_bidirectional_mask(
7070
config=module.config,
71-
input_embeds=module.bert.embeddings(input_ids),
71+
inputs_embeds=module.bert.embeddings(input_ids),
7272
attention_mask=attention_mask,
7373
),
7474
)

‎examples/qualcomm/oss_scripts/distilbert.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def main(args):
4848
random_ids = torch.randint(low=0, high=100, size=(1, 100), dtype=torch.int32)
4949
attention_mask = create_bidirectional_mask(
5050
config=module.config,
51-
input_embeds=module.distilbert.embeddings(random_ids),
51+
inputs_embeds=module.distilbert.embeddings(random_ids),
5252
attention_mask=torch.zeros((1, 100), dtype=torch.float32),
5353
)
5454
inputs = [
@@ -69,7 +69,7 @@ def main(args):
6969
input_ids,
7070
create_bidirectional_mask(
7171
config=module.config,
72-
input_embeds=module.distilbert.embeddings(input_ids),
72+
inputs_embeds=module.distilbert.embeddings(input_ids),
7373
attention_mask=attention_mask,
7474
),
7575
)

‎examples/qualcomm/oss_scripts/roberta.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def main(args):
4848
random_ids = torch.randint(low=0, high=100, size=(1, 100), dtype=torch.int32)
4949
attention_mask = create_bidirectional_mask(
5050
config=module.config,
51-
input_embeds=module.roberta.embeddings(random_ids),
51+
inputs_embeds=module.roberta.embeddings(random_ids),
5252
attention_mask=torch.zeros((1, 100), dtype=torch.float32),
5353
)
5454
inputs = [
@@ -69,7 +69,7 @@ def main(args):
6969
input_ids,
7070
create_bidirectional_mask(
7171
config=module.config,
72-
input_embeds=module.roberta.embeddings(input_ids),
72+
inputs_embeds=module.roberta.embeddings(input_ids),
7373
attention_mask=attention_mask,
7474
),
7575
)
@@ -117,7 +117,7 @@ def main(args):
117117
sample_input["input_ids"] = sample_input["input_ids"].to(torch.int32)
118118
sample_input["attention_mask"] = create_bidirectional_mask(
119119
config=module.config,
120-
input_embeds=module.roberta.embeddings(sample_input["input_ids"]),
120+
inputs_embeds=module.roberta.embeddings(sample_input["input_ids"]),
121121
attention_mask=sample_input["attention_mask"],
122122
)
123123
sample_input = tuple(sample_input.values())

‎examples/qualcomm/oss_scripts/t5/t5_model.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ def forward( # noqa: C901
168168
if self.config.is_decoder:
169169
attention_mask = create_causal_mask(
170170
config=self.config,
171-
input_embeds=inputs_embeds,
171+
inputs_embeds=inputs_embeds,
172172
attention_mask=attention_mask,
173-
cache_position=cache_position,
174173
past_key_values=(
175174
past_key_values.self_attention_cache
176175
if isinstance(past_key_values, EncoderDecoderCache)
@@ -180,15 +179,15 @@ def forward( # noqa: C901
180179
else:
181180
attention_mask = create_bidirectional_mask(
182181
config=self.config,
183-
input_embeds=inputs_embeds,
182+
inputs_embeds=inputs_embeds,
184183
attention_mask=attention_mask,
185184
)
186185

187186
encoder_extended_attention_mask = None
188187
if self.is_decoder and encoder_hidden_states is not None:
189188
encoder_extended_attention_mask = create_bidirectional_mask(
190189
config=self.config,
191-
input_embeds=inputs_embeds,
190+
inputs_embeds=inputs_embeds,
192191
attention_mask=encoder_attention_mask,
193192
encoder_hidden_states=encoder_hidden_states,
194193
)

0 commit comments

Comments
 (0)