Fix None dereference crashes and mutable default feat_idx in Wan/Cosmos autoencoders#13190
Open
jashshah999 wants to merge 1 commit intohuggingface:mainfrom
Open
Conversation
In model_loading_utils.py, chained .get().get() would crash with AttributeError if the first key was missing from the remapping dict. In autoencoder_kl_cosmos.py, _WAVELETS.get(patch_method).clone() crashes with AttributeError if patch_method is not a recognized wavelet type (both CosmosPatchEmbed3d and CosmosUnpatcher3d). In autoencoder_kl_wan.py, 8 forward() methods used feat_idx=[0] as a mutable default argument. Since the list is mutated via feat_idx[0] += 1 during forward passes, the shared default list accumulates state across calls, corrupting the cache index.
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.
What does this PR do?
Fixes None dereference crashes and a mutable default argument bug:
1.
models/model_loading_utils.py-_fetch_remapped_cls_from_configused chained.get().get()without a fallback on the first call. Ifprevious_class_nameis not in_CLASS_REMAPPING_DICT, the first.get()returnsNoneand the second.get()crashes withAttributeError.2.
models/autoencoders/autoencoder_kl_cosmos.py- BothCosmosPatchEmbed3dandCosmosUnpatcher3dcall_WAVELETS.get(patch_method).clone(). Ifpatch_methodis not a recognized wavelet type,.get()returnsNoneand.clone()crashes withAttributeError.3.
models/autoencoders/autoencoder_kl_wan.py- 8forward()methods usedfeat_idx=[0]as a mutable default argument. Since the list is actively mutated viafeat_idx[0] += 1during forward passes, the shared default list accumulates state across calls, corrupting the cache index on subsequent invocations.