Skip to content
Merged
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions unsloth/models/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,19 +780,22 @@ def from_pretrained(
token = token,
language = whisper_language,
task = whisper_task,
trust_remote_code = trust_remote_code,
)
else:
try:
tokenizer = auto_processor.from_pretrained(
tokenizer_name,
padding_side = "left",
token = token,
trust_remote_code = trust_remote_code,
)
except:
tokenizer = get_auto_processor(
tokenizer_name,
padding_side = "left",
token = token,
trust_remote_code = trust_remote_code,
)
Comment on lines 786 to 799
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve code clarity and reduce duplication, you can extract the common arguments for auto_processor.from_pretrained and get_auto_processor into a dictionary. This makes the code more maintainable.

Additionally, the bare except: is too broad and can catch unexpected exceptions like KeyboardInterrupt. It's better to specify the exceptions you expect to catch, or at least use except Exception:.

Suggested change
try:
tokenizer = auto_processor.from_pretrained(
tokenizer_name,
padding_side = "left",
token = token,
trust_remote_code = trust_remote_code,
)
except:
tokenizer = get_auto_processor(
tokenizer_name,
padding_side = "left",
token = token,
trust_remote_code = trust_remote_code,
)
common_kwargs = {
"padding_side": "left",
"token": token,
"trust_remote_code": trust_remote_code,
}
try:
tokenizer = auto_processor.from_pretrained(
tokenizer_name,
**common_kwargs,
)
except Exception:
tokenizer = get_auto_processor(
tokenizer_name,
**common_kwargs,
)
if hasattr(tokenizer, "tokenizer"):
__tokenizer = tokenizer.tokenizer
Expand Down