Skip to content

Commit

Permalink
Processors: don't default padding side (huggingface#33942)
Browse files Browse the repository at this point in the history
* don't default padding side

* fix
  • Loading branch information
zucchini-nlp authored Oct 8, 2024
1 parent a3add29 commit 0dbc709
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/transformers/models/idefics3/processing_idefics3.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ def __call__(
**kwargs,
)

# Temporary fix for "padding_side" in init_kwargs
output_kwargs["text_kwargs"].pop("padding_side", None)

image_seq_len = image_seq_len if image_seq_len is not None else self.image_seq_len

n_images_in_text = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ def __call__(
num_video_tokens = (num_frames * pooled_height_width * pooled_height_width) + 1 # +1 for newline token
text = [sample.replace(self.video_token, self.video_token * num_video_tokens) for sample in text]

# Padding side can be in TextKwargs but is not accepted by the tokenizer
_ = output_kwargs["text_kwargs"].pop("padding_side", None)
text_inputs = self.tokenizer(text, **output_kwargs["text_kwargs"])
return BatchFeature(data={**text_inputs, **image_inputs, **video_inputs})

Expand Down
1 change: 0 additions & 1 deletion src/transformers/models/qwen2_vl/processing_qwen2_vl.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def __call__(
index += 1
text[i] = text[i].replace("<|placeholder|>", "<|video_pad|>")

_ = output_kwargs["text_kwargs"].pop("padding_side", None)
text_inputs = self.tokenizer(text, **output_kwargs["text_kwargs"])

return BatchFeature(data={**text_inputs, **image_inputs, **videos_inputs})
Expand Down
7 changes: 6 additions & 1 deletion src/transformers/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,12 @@ class MyProcessingKwargs(ProcessingKwargs, CommonKwargs, TextKwargs, ImagesKwarg
for modality_key in ModelProcessorKwargs.__annotations__[modality].__annotations__.keys():
# init with tokenizer init kwargs if necessary
if modality_key in tokenizer_init_kwargs:
default_kwargs[modality][modality_key] = tokenizer_init_kwargs[modality_key]
value = (
getattr(self.tokenizer, modality_key)
if hasattr(self.tokenizer, modality_key)
else tokenizer_init_kwargs[modality_key]
)
default_kwargs[modality][modality_key] = value
# now defaults kwargs are updated with the tokenizers defaults.
# pass defaults to output dictionary
output_kwargs.update(default_kwargs)
Expand Down

0 comments on commit 0dbc709

Please sign in to comment.