Skip to content

Can not load pretrained model properly #3090

@wwdok

Description

@wwdok

Is your feature request related to a problem? Please describe.
I use pipeline.save_pretrained(config.output_dir, variant=str(epoch)) to save model every n epochs, this leads to there are multiple model in the unet folder:
image
Then when I want to load pretrained model using pipeline = DDPMPipeline.from_pretrained('./eye-144192_100_4atten', local_files_only=True), it throw error:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>                                                                                      │
│                                                                                                  │
│ /opt/conda/lib/python3.8/site-packages/diffusers/pipelines/pipeline_utils.py:944 in              │
│ from_pretrained                                                                                  │
│                                                                                                  │
│    941 │   │   │   │                                                                             │
│    942 │   │   │   │   # check if the module is in a subdirectory                                │
│    943 │   │   │   │   if os.path.isdir(os.path.join(cached_folder, name)):                      │
│ ❱  944 │   │   │   │   │   loaded_sub_model = load_method(os.path.join(cached_folder, name), **  │
│    945 │   │   │   │   else:                                                                     │
│    946 │   │   │   │   │   # else load from the root directory                                   │
│    947 │   │   │   │   │   loaded_sub_model = load_method(cached_folder, **loading_kwargs)       │
│                                                                                                  │
│ /opt/conda/lib/python3.8/site-packages/diffusers/models/modeling_utils.py:527 in from_pretrained │
│                                                                                                  │
│   524 │   │   │   │   except:  # noqa: E722                                                      │
│   525 │   │   │   │   │   pass                                                                   │
│   526 │   │   │   if model_file is None:                                                         │
│ ❱ 527 │   │   │   │   model_file = _get_model_file(                                              │
│   528 │   │   │   │   │   pretrained_model_name_or_path,                                         │
│   529 │   │   │   │   │   weights_name=_add_variant(WEIGHTS_NAME, variant),                      │
│   530 │   │   │   │   │   cache_dir=cache_dir,                                                   │
│                                                                                                  │
│ /opt/conda/lib/python3.8/site-packages/diffusers/models/modeling_utils.py:821 in _get_model_file │
│                                                                                                  │
│   818 │   │   │   model_file = os.path.join(pretrained_model_name_or_path, subfolder, weights_   │
│   819 │   │   │   return model_file                                                              │
│   820 │   │   else:                                                                              │
│ ❱ 821 │   │   │   raise EnvironmentError(                                                        │
│   822 │   │   │   │   f"Error no file named {weights_name} found in directory {pretrained_mode   │
│   823 │   │   │   )                                                                              │
│   824 │   else:                                                                                  │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
OSError: Error no file named diffusion_pytorch_model.bin found in directory ./eye-144192_100_4atten/unet.

Describe the solution you'd like
diffusers can automatically choose the last model, e.g. here is eye-144192_100/unet/diffusion_pytorch_model.99.bin

Describe alternatives you've considered
User specify the model , e.g. pipeline = DDPMPipeline.from_pretrained('./eye-144192_100_4atten/unet/diffusion_pytorch_model.99.bin', local_files_only=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions