Skip to content

Commit

Permalink
guard
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchit-gandhi committed May 16, 2024
1 parent e5ee509 commit f8dc983
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,18 @@ def __init__(
):
self.place_model_on_device = False

self.tokenizer = processor if processor is not None else tokenizer
if processor is not None and hasattr(processor, "feature_extractor"):
tokenizer = processor.feature_extractor
if processor is not None and tokenizer is not None:
raise ValueError(
"You cannot pass both `processor` and `tokenizer` to the Trainer. Only pass the `processor` if defined."
)
elif processor is not None:
self.tokenizer = processor
if hasattr(processor, "feature_extractor"):
tokenizer = processor.feature_extractor
elif hasattr(processor, "tokenizer"):
tokenizer = processor.tokenizer
else:
self.tokenizer = tokenizer

default_collator = (
DataCollatorWithPadding(tokenizer)
Expand Down

0 comments on commit f8dc983

Please sign in to comment.