Fix model infrastructure edge cases#13709
Draft
taivu1998 wants to merge 1 commit intohuggingface:mainfrom
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #13655.
This PR addresses several small model-infrastructure edge cases that can surface as runtime failures or state leaks:
AutoModel.config_nameafter model-index probing, config fallback, and exceptionsPathLikemodel paths when building_diffusers_load_idCacheMixin.cache_context()hook state even when the wrapped block raisesImportErrorsenable_parallelism()to reject unavailable or uninitialized distributed setupsFlaxModelMixin.from_pretrained()receives an explicit configtorch.float32Root Cause
The failures come from a few independent guard/state issues:
AutoModel.from_pretrained()temporarily mutated the class-levelconfig_namewithout guaranteed restoration and joined load-id parts without stringifying path objects.cache_context()reset hook context only on normal exit, so exceptions could leave stateful hooks bound to a stale context.float32tensors after receiving low-precision inputs, which could mismatchbfloat16or other low-precision activations/weights.andwhereorwas required for guard logic.unused_kwargs.Validation
Ran focused and broader checks locally:
pytest tests/models/test_modeling_utils.py -qpytest tests/models/test_modeling_flax_utils.py -qpytest tests/hooks/test_hooks.py -q -k cache_context_clears_stateful_hook_context_after_exceptionpytest tests/models/test_attention_processor.py -q -k 'xla_flash_attention or is_torch_xla_version'pytest tests/models/test_layers_utils.py -q -k 'sincos_pos_embed or fir_bfloat16 or fir_upsample_with_conv_bfloat16 or fir_downsample_with_conv_bfloat16'pytest tests/models/test_models_auto.py -q -k 'local_model_index_pathlike or local_config_fallback or load_config_exception'pytest tests/hooks/test_hooks.py -qpytest tests/models/test_layers_utils.py -quvx ruff check ...uvx ruff format --check ...git diff --check