Skip to content

Commit c76387e

Browse files
authored
Fix arguments (#40605)
* Fix invalid arguments Signed-off-by: cyy <[email protected]> * Fix typing Signed-off-by: cyy <[email protected]> * Add missing self Signed-off-by: cyy <[email protected]> * Add missing self and other fixes Signed-off-by: cyy <[email protected]> *  More fixes Signed-off-by: cyy <[email protected]> *  More fixes Signed-off-by: cyy <[email protected]> --------- Signed-off-by: cyy <[email protected]>
1 parent 21f0903 commit c76387e

File tree

10 files changed

+26
-23
lines changed

10 files changed

+26
-23
lines changed

src/transformers/models/evolla/modeling_evolla.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,11 @@ def forward(
637637
)
638638

639639
def get_extended_attention_mask(
640-
self, attention_mask: Tensor, input_shape: tuple[int], device: torch.device = None, dtype: torch.float = None
640+
self,
641+
attention_mask: Tensor,
642+
input_shape: tuple[int],
643+
device: torch.device = None,
644+
dtype: Optional[torch.dtype] = None,
641645
) -> Tensor:
642646
"""
643647
Makes broadcastable attention and causal masks so that future and masked tokens are ignored.

src/transformers/models/evolla/modular_evolla.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ def forward(
269269
)
270270

271271
def get_extended_attention_mask(
272-
self, attention_mask: Tensor, input_shape: tuple[int], device: torch.device = None, dtype: torch.float = None
272+
self,
273+
attention_mask: Tensor,
274+
input_shape: tuple[int],
275+
device: torch.device = None,
276+
dtype: Optional[torch.dtype] = None,
273277
) -> Tensor:
274278
"""
275279
Makes broadcastable attention and causal masks so that future and masked tokens are ignored.

src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,13 +1565,12 @@ def prepare_inputs_for_generation(
15651565
# Calculate RoPE index once per generation in the pre-fill stage only.
15661566
# When compiling, we can't check tensor values thus we check only input length
15671567
# It is safe to assume that `length!=1` means we're in pre-fill because compiled
1568-
# models currently cannot do asssisted decoding
1568+
# models currently cannot do assisted decoding
15691569
if cache_position[0] == 0 or self.model.rope_deltas is None:
15701570
vision_positions, rope_deltas = self.model.get_rope_index(
15711571
model_inputs.get("input_ids", None),
15721572
image_grid_thw=image_grid_thw,
15731573
video_grid_thw=video_grid_thw,
1574-
second_per_grid_ts=second_per_grid_ts,
15751574
attention_mask=attention_mask,
15761575
)
15771576
self.model.rope_deltas = rope_deltas

src/transformers/models/qwen2_5_vl/modular_qwen2_5_vl.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,13 +809,12 @@ def prepare_inputs_for_generation(
809809
# Calculate RoPE index once per generation in the pre-fill stage only.
810810
# When compiling, we can't check tensor values thus we check only input length
811811
# It is safe to assume that `length!=1` means we're in pre-fill because compiled
812-
# models currently cannot do asssisted decoding
812+
# models currently cannot do assisted decoding
813813
if cache_position[0] == 0 or self.model.rope_deltas is None:
814814
vision_positions, rope_deltas = self.model.get_rope_index(
815815
model_inputs.get("input_ids", None),
816816
image_grid_thw=image_grid_thw,
817817
video_grid_thw=video_grid_thw,
818-
second_per_grid_ts=second_per_grid_ts,
819818
attention_mask=attention_mask,
820819
)
821820
self.model.rope_deltas = rope_deltas

src/transformers/models/sam2/modular_sam2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ class Sam2ImageProcessorFast(SamImageProcessorFast):
108108
def __init__(self, **kwargs: Unpack[Sam2FastImageProcessorKwargs]):
109109
BaseImageProcessorFast.__init__(self, **kwargs)
110110

111-
def pad_image():
111+
def pad_image(self):
112112
raise NotImplementedError("No pad_image for SAM 2.")
113113

114-
def _get_preprocess_shape():
114+
def _get_preprocess_shape(self):
115115
raise NotImplementedError("No _get_preprocess_shape for SAM 2.")
116116

117-
def resize():
117+
def resize(self):
118118
raise NotImplementedError("No need to override resize for SAM 2.")
119119

120120
def _preprocess(

src/transformers/models/wavlm/modeling_wavlm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def torch_multi_head_self_attention(
191191
attention_mask: Union[torch.LongTensor, torch.BoolTensor],
192192
gated_position_bias: torch.FloatTensor,
193193
output_attentions: bool,
194-
) -> (torch.FloatTensor, torch.FloatTensor):
194+
) -> tuple[torch.FloatTensor, torch.FloatTensor]:
195195
"""simple wrapper around torch's multi_head_attention_forward function"""
196196
# self-attention assumes q = k = v
197197
query = key = value = hidden_states.transpose(0, 1)

src/transformers/models/wavlm/modular_wavlm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def torch_multi_head_self_attention(
122122
attention_mask: Union[torch.LongTensor, torch.BoolTensor],
123123
gated_position_bias: torch.FloatTensor,
124124
output_attentions: bool,
125-
) -> (torch.FloatTensor, torch.FloatTensor):
125+
) -> tuple[torch.FloatTensor, torch.FloatTensor]:
126126
"""simple wrapper around torch's multi_head_attention_forward function"""
127127
# self-attention assumes q = k = v
128128
query = key = value = hidden_states.transpose(0, 1)

src/transformers/models/yolos/modular_yolos.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,22 @@ def post_process_object_detection(
171171

172172
return results
173173

174-
def post_process_segmentation():
174+
def post_process_segmentation(self):
175175
raise NotImplementedError("Segmentation post-processing is not implemented for Deformable DETR yet.")
176176

177-
def post_process_instance():
177+
def post_process_instance(self):
178178
raise NotImplementedError("Instance post-processing is not implemented for Deformable DETR yet.")
179179

180-
def post_process_panoptic():
180+
def post_process_panoptic(self):
181181
raise NotImplementedError("Panoptic post-processing is not implemented for Deformable DETR yet.")
182182

183-
def post_process_instance_segmentation():
183+
def post_process_instance_segmentation(self):
184184
raise NotImplementedError("Segmentation post-processing is not implemented for Deformable DETR yet.")
185185

186-
def post_process_semantic_segmentation():
186+
def post_process_semantic_segmentation(self):
187187
raise NotImplementedError("Semantic segmentation post-processing is not implemented for Deformable DETR yet.")
188188

189-
def post_process_panoptic_segmentation():
189+
def post_process_panoptic_segmentation(self):
190190
raise NotImplementedError("Panoptic segmentation post-processing is not implemented for Deformable DETR yet.")
191191

192192

src/transformers/trainer.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,6 @@ def safe_globals():
294294
if TYPE_CHECKING:
295295
import optuna
296296

297-
if is_datasets_available():
298-
import datasets
299-
300297
logger = logging.get_logger(__name__)
301298

302299

@@ -418,14 +415,14 @@ class Trainer:
418415
def __init__(
419416
self,
420417
model: Union[PreTrainedModel, nn.Module, None] = None,
421-
args: TrainingArguments = None,
418+
args: Optional[TrainingArguments] = None,
422419
data_collator: Optional[DataCollator] = None,
423420
train_dataset: Optional[Union[Dataset, IterableDataset, "datasets.Dataset"]] = None,
424421
eval_dataset: Optional[Union[Dataset, dict[str, Dataset], "datasets.Dataset"]] = None,
425422
processing_class: Optional[
426423
Union[PreTrainedTokenizerBase, BaseImageProcessor, FeatureExtractionMixin, ProcessorMixin]
427424
] = None,
428-
model_init: Optional[Callable[[], PreTrainedModel]] = None,
425+
model_init: Optional[Callable[..., PreTrainedModel]] = None,
429426
compute_loss_func: Optional[Callable] = None,
430427
compute_metrics: Optional[Callable[[EvalPrediction], dict]] = None,
431428
callbacks: Optional[list[TrainerCallback]] = None,

src/transformers/video_processing_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ def get_video_processor_dict(
681681
else:
682682
video_processor_file = VIDEO_PROCESSOR_NAME
683683
try:
684-
# Try to load with a new config name first and if not successfull try with the old file name
684+
# Try to load with a new config name first and if not successful try with the old file name
685685
# NOTE: we will gradually change to saving all processor configs as nested dict in PROCESSOR_NAME
686686
resolved_video_processor_files = cached_files(
687687
pretrained_model_name_or_path,

0 commit comments

Comments
 (0)