Skip to content

fix(processing): Filter kwargs in ProcessorMixin call to prevent Type…#41606

Open
CodersAcademy006 wants to merge 2 commits intohuggingface:mainfrom
CodersAcademy006:fix-processor-kwargs-bug
Open

fix(processing): Filter kwargs in ProcessorMixin call to prevent Type…#41606
CodersAcademy006 wants to merge 2 commits intohuggingface:mainfrom
CodersAcademy006:fix-processor-kwargs-bug

Conversation

@CodersAcademy006
Copy link
Copy Markdown

This PR fixes an issue where multimodal processors could raise a TypeError when called with arguments specific to one modality. The ProcessorMixin.__call__ method was passing all keyword arguments to each sub-processor (tokenizer, feature extractor, etc.), causing a crash if a processor received an argument it didn't recognize (e.g., EncodecFeatureExtractor receiving pad_to_multiple_of from the tokenizer).

This fix resolves the problem by filtering the keyword arguments before they are passed to each sub-processor. It uses Python's inspect module to get the valid parameters for each processor's __call__ method and only passes the arguments that match. This prevents TypeErrors and makes the processor logic more robust.

Fixes #41598

@Rocketknight1
Copy link
Copy Markdown
Member

cc @zucchini-nlp! I'm not sure about this because some of the submodules may just have **kwargs

Comment on lines 628 to -629
input_data, input_kwargs = attribute_to_kwargs[attribute_name]
if input_data is not None and attribute is not None:
attribute_output = attribute(input_data, **kwargs[input_kwargs])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

in this line kwargs are filtered already and we are obtaining kwargs[input_kwargs]. That should work for all models if if there's a TypeError anywhere, I'd suggest to see what has gone wrong with specific model

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The model where this issue is occurring is CSM-1B, so it might be related to how that particular architecture handles its input kwargs.

@github-actions
Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=41606&sha=987d5c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EncodecFeatureExtractor.__call__() got an unexpected keyword argument 'pad_to_multiple_of'

4 participants