Skip to content

Fix None dereference crashes and mutable default feat_idx in Wan/Cosmos autoencoders#13190

Open
jashshah999 wants to merge 1 commit intohuggingface:mainfrom
jashshah999:fix/none-dereference-and-mutable-defaults
Open

Fix None dereference crashes and mutable default feat_idx in Wan/Cosmos autoencoders#13190
jashshah999 wants to merge 1 commit intohuggingface:mainfrom
jashshah999:fix/none-dereference-and-mutable-defaults

Conversation

@jashshah999
Copy link

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_config used chained .get().get() without a fallback on the first call. If previous_class_name is not in _CLASS_REMAPPING_DICT, the first .get() returns None and the second .get() crashes with AttributeError.

2. models/autoencoders/autoencoder_kl_cosmos.py - Both CosmosPatchEmbed3d and CosmosUnpatcher3d call _WAVELETS.get(patch_method).clone(). If patch_method is not a recognized wavelet type, .get() returns None and .clone() crashes with AttributeError.

3. models/autoencoders/autoencoder_kl_wan.py - 8 forward() methods used feat_idx=[0] as a mutable default argument. Since the list is actively mutated via feat_idx[0] += 1 during forward passes, the shared default list accumulates state across calls, corrupting the cache index on subsequent invocations.

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.
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.

1 participant