Skip to content

Error On '_load_state_dict_into_model #36

@Jillinger

Description

@Jillinger

I'm getting this error, on running python webui.py

Traceback (most recent call last):
File "...\CharacterGen\webui.py", line 28, in
from tuneavideo.models.unet_mv2d_condition import UNetMV2DConditionModel
File "...\2D_Stage\tuneavideo\models\unet_mv2d_condition.py", line 40, in
from diffusers.models.modeling_utils import ModelMixin, load_state_dict, _load_state_dict_into_model
ImportError: cannot import name '_load_state_dict_into_model' from 'diffusers.models.modeling_utils' (...site-packages\diffusers\models\modeling_utils.py)

On searching, I read this:

The error "cannot import name '_load_state_dict_into_model'" typically arises when attempting to use a private or internal function that is not part of the public API in PyTorch. This function, _load_state_dict_into_model, is not intended for direct user import and is used internally by PyTorch's model loading mechanism.
The correct way to load a state dictionary into a model is to use the load_state_dict method on the model instance itself, after loading the state dictionary from a file using torch.load.
For example, the proper usage is:

state_dict = torch.load('model.pth')
model.load_state_dict(state_dict)

Attempting to import or use _load_state_dict_into_model directly will result in an ImportError because it is not exposed in the public namespace.
This is consistent with PyTorch's design, where internal functions are prefixed with an underscore to indicate they are not part of the stable public API and may change without notice.
Therefore, users should avoid referencing such functions and instead follow the documented workflow for saving and loading models.

Can this be fixed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions