-
Notifications
You must be signed in to change notification settings - Fork 6.9k
null on exported json config results in custom model not being loaded #3231
Copy link
Copy link
Closed
Labels
staleIssues that haven't received updatesIssues that haven't received updates
Description
Hi,
I have created my own CustomImage pipeline using the save_pretrained method using a CustomEncoder imported from a local file. The saved general config file looks like this:
{
"_class_name": "CustomImagePipeline",
"_diffusers_version": "0.14.0",
"customencoder": [
null,
"CustomEncoder"
],
"scheduler": [
"diffusers",
"DDPMScheduler"
],
"unet": [
"diffusers",
"UNet2DConditionModel"
],
"vqvae": [
"diffusers",
"AutoencoderKL"
]
}
When saved the library corresponding to the encoder becomes None and it is then removed through load_module and thus I get the error:
File ~/miniconda3/envs/diffusers/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py:1038, in DiffusionPipeline.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
1036 elif len(missing_modules) > 0:
1037 passed_modules = set(list(init_kwargs.keys()) + list(passed_class_obj.keys())) - optional_kwargs
-> 1038 raise ValueError(
1039 f"Pipeline {pipeline_class} expected {expected_modules}, but only {passed_modules} were passed."
1040 )
1042 # 8. Instantiate the pipeline
1043 model = pipeline_class(**init_kwargs)
ValueError: Pipeline <class 'model.CustomImagePipeline'> expected {'scheduler', 'vqvae', 'unet', 'customencoder'}, but only {'scheduler', 'vqvae', 'unet'} were passed.
If I replace null with the name of the file from which the encoder comes from, let's say encoderfname then the following line breaks:
File ~/miniconda3/envs/diffusers/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py:995, in DiffusionPipeline.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
993 # 6.2 Define all importable classes
994 is_pipeline_module = hasattr(pipelines, library_name)
--> 995 importable_classes = ALL_IMPORTABLE_CLASSES if is_pipeline_module else LOADABLE_CLASSES[library_name]
996 loaded_sub_model = None
998 # 6.3 Use passed sub model or load class_name from library_name
KeyError: 'encoderfname'
Could you propose a workaround for this problem (that ofc wouldn't involve making a library out of my code)?
(Future proofing libraries is always a good idea especially when the use case is that simple.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
staleIssues that haven't received updatesIssues that haven't received updates