AutoConfig has potential issue with composite config. #38258 solved #38672
+292
−76
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #38258
Description
This PR resolves an issue where keyword arguments passed to
from_pretrained
orfrom_config
for composite models were not being correctly routed to the respective sub-configs. This would lead to aTypeError
when an argument intended for a sub-model (e.g.,use_cache=True
for a text model) was passed down to a child constructor that did not accept it.Solution
The solution introduces a new private static method,
_route_kwargs
, to the_BaseAutoModelClass
inauto/factory.py
. This centralized helper method is responsible for:kwargs
.text_config
,vision_config
).config.text_config.use_cache = True
).kwargs
dictionary to prevent it from being passed down incorrectly.This helper method is now called from the entry points of both the
from_pretrained
andfrom_config
methods. This ensures that the argument routing is applied robustly and consistently, regardless of how a user chooses to load a composite model.This approach fixes the underlying issue in the factory layer, providing a general solution for all current and future composite models.
Testing
I have confirmed that these changes fix the issue by running the relevant tests in
tests/models/auto/test_modeling_auto_composite.py
. Additionally, all quality checks (make quality
) pass successfully.