Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def checku2e(x):
candidates.append((self.vocab[wd], wd, e))
if len(candidates) > 0:
# the smallest token_id is adopted
_, wd, e = sorted(candidates, key=lambda x: x[0])[0]
_, wd, e = min(candidates, key=lambda x: x[0])
result.append(wd)
pos = e
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def checku2e(x):
candidates.append((self.vocab[wd], wd, e))
if len(candidates) > 0:
# the smallest token_id is adopted
_, wd, e = sorted(candidates, key=lambda x: x[0])[0]
_, wd, e = min(candidates, key=lambda x: x[0])
result.append(wd)
pos = e
else:
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/models/ovis2/image_processing_ovis2.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ def get_min_tile_covering_grid(

if sufficient_covering_grids:
# Prefer fewer tiles and higher covering ratio
return sorted(sufficient_covering_grids, key=lambda x: (x[0][0] * x[0][1], -x[1]))[0][0]
return min(sufficient_covering_grids, key=lambda x: (x[0][0] * x[0][1], -x[1]))[0]
else:
# Fallback: prefer higher covering even if below threshold
return sorted(evaluated_grids, key=lambda x: (-x[1], x[0][0] * x[0][1]))[0][0]
return min(evaluated_grids, key=lambda x: (-x[1], x[0][0] * x[0][1]))[0]


class Ovis2ImageProcessor(BaseImageProcessor):
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/tokenization_mistral_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ def from_pretrained(
if "tekken.json" in valid_tokenizer_files:
tokenizer_file = "tekken.json"
else:
tokenizer_file = sorted(valid_tokenizer_files)[-1]
tokenizer_file = max(valid_tokenizer_files)
logger.warning(
f"Multiple tokenizer files found in directory: {pretrained_model_name_or_path}. Using {tokenizer_file}."
)
Expand Down
2 changes: 1 addition & 1 deletion tests/trainer/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3478,7 +3478,7 @@ def test_resume_training_with_randomness(self):
checkpoints = [d for d in os.listdir(tmp_dir) if d.startswith("checkpoint-")]
# There should be one checkpoint per epoch.
self.assertEqual(len(checkpoints), 3)
checkpoint_dir = sorted(checkpoints, key=lambda x: int(x.replace("checkpoint-", "")))[0]
checkpoint_dir = min(checkpoints, key=lambda x: int(x.replace("checkpoint-", "")))

trainer.train(resume_from_checkpoint=os.path.join(tmp_dir, checkpoint_dir))
(a1, b1) = trainer.model.a.item(), trainer.model.b.item()
Expand Down
2 changes: 1 addition & 1 deletion utils/add_pipeline_model_mapping_to_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def find_test_class(test_file):
break
# Take the test class with the shortest name (just a heuristic)
if target_test_class is None and len(test_classes) > 0:
target_test_class = sorted(test_classes, key=lambda x: (len(x.__name__), x.__name__))[0]
target_test_class = min(test_classes, key=lambda x: (len(x.__name__), x.__name__))

return target_test_class

Expand Down
2 changes: 1 addition & 1 deletion utils/create_dummy_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def get_tiny_config(config_class, model_class=None, **model_tester_kwargs):
# This is to avoid `T5EncoderOnlyModelTest` is used instead of `T5ModelTest`, which has
# `is_encoder_decoder=False` and causes some pipeline tests failing (also failures in `Optimum` CI).
# TODO: More fine grained control of the desired tester class.
model_tester_class = sorted(tester_classes, key=lambda x: (len(x.__name__), x.__name__))[0]
model_tester_class = min(tester_classes, key=lambda x: (len(x.__name__), x.__name__))
except ModuleNotFoundError:
error = f"Tiny config not created for {model_type} - cannot find the testing module from the model name."
raise ValueError(error)
Expand Down
2 changes: 1 addition & 1 deletion utils/deprecate_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_last_stable_minor_release():
last_stable_minor_releases = [
release for release in release_data["releases"] if release.startswith(last_major_minor)
]
last_stable_release = sorted(last_stable_minor_releases, key=version.parse)[-1]
last_stable_release = max(last_stable_minor_releases, key=version.parse)

return last_stable_release

Expand Down