Got an error trying to load from pretrained local files

#104
by rtcml - opened

I loaded files by huggingface-cli, and tried to use code from the example:

from diffusers import DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained("$PATH_TO_LOCAL_DIR$/stabilityai/stable-diffusion-3.5-large", 
                                         torch_dtype=torch.bfloat16, 
                                         local_files_only=True,
                                         use_safetensors=True)
pipe.to("cuda")
                                         
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
image = pipe(prompt).images[0]

But got the following error:

Loading pipeline components...:  44%|β–ˆβ–ˆβ–ˆβ–ˆβ–     | 4/9 [00:00<00:00,  5.29it/s]
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[23], line 3
      1 from diffusers import DiffusionPipeline
----> 3 pipe = DiffusionPipeline.from_pretrained("$PATH_TO_LOCAL_DIR$/stabilityai/stable-diffusion-3.5-large/", 
      4                                          torch_dtype=torch.bfloat16, 
      5                                          local_files_only=True,
      6                                          use_safetensors=True)
      8 pipe.to("cuda:2")
     10 prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"

File /usr/local/lib/python3.12/dist-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    111 if check_use_auth_token:
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)

File /usr/local/lib/python3.12/dist-packages/diffusers/pipelines/pipeline_utils.py:1022, in DiffusionPipeline.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
   1015 else:
   1016     # load sub model
   1017     sub_model_dtype = (
   1018         torch_dtype.get(name, torch_dtype.get("default", torch.float32))
   1019         if isinstance(torch_dtype, dict)
   1020         else torch_dtype
   1021     )
-> 1022     loaded_sub_model = load_sub_model(
   1023         library_name=library_name,
   1024         class_name=class_name,
   1025         importable_classes=importable_classes,
   1026         pipelines=pipelines,
   1027         is_pipeline_module=is_pipeline_module,
   1028         pipeline_class=pipeline_class,
   1029         torch_dtype=sub_model_dtype,
   1030         provider=provider,
   1031         sess_options=sess_options,
   1032         device_map=current_device_map,
   1033         max_memory=max_memory,
   1034         offload_folder=offload_folder,
   1035         offload_state_dict=offload_state_dict,
   1036         model_variants=model_variants,
   1037         name=name,
   1038         from_flax=from_flax,
   1039         variant=variant,
   1040         low_cpu_mem_usage=low_cpu_mem_usage,
   1041         cached_folder=cached_folder,
   1042         use_safetensors=use_safetensors,
   1043         dduf_entries=dduf_entries,
   1044         provider_options=provider_options,
   1045         quantization_config=quantization_config,
   1046     )
   1047     logger.info(
   1048         f"Loaded {name} as {class_name} from `{name}` subfolder of {pretrained_model_name_or_path}."
   1049     )
   1051 init_kwargs[name] = loaded_sub_model  # UNet(...), # DiffusionSchedule(...)

File /usr/local/lib/python3.12/dist-packages/diffusers/pipelines/pipeline_loading_utils.py:833, in load_sub_model(library_name, class_name, importable_classes, pipelines, is_pipeline_module, pipeline_class, torch_dtype, provider, sess_options, device_map, max_memory, offload_folder, offload_state_dict, model_variants, name, from_flax, variant, low_cpu_mem_usage, cached_folder, use_safetensors, dduf_entries, provider_options, quantization_config)
    830     loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
    831 else:
    832     # else load from the root directory
--> 833     loaded_sub_model = load_method(cached_folder, **loading_kwargs)
    835 if isinstance(loaded_sub_model, torch.nn.Module) and isinstance(device_map, dict):
    836     # remove hooks
    837     remove_hook_from_module(loaded_sub_model, recurse=True)

File /usr/local/lib/python3.12/dist-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    111 if check_use_auth_token:
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)

File /usr/local/lib/python3.12/dist-packages/diffusers/models/modeling_utils.py:1014, in ModelMixin.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
   1011 config_path = pretrained_model_name_or_path
   1013 # load config
-> 1014 config, unused_kwargs, commit_hash = cls.load_config(
   1015     config_path,
   1016     cache_dir=cache_dir,
   1017     return_unused_kwargs=True,
   1018     return_commit_hash=True,
   1019     force_download=force_download,
   1020     proxies=proxies,
   1021     local_files_only=local_files_only,
   1022     token=token,
   1023     revision=revision,
   1024     subfolder=subfolder,
   1025     user_agent=user_agent,
   1026     dduf_entries=dduf_entries,
   1027     **kwargs,
   1028 )
   1029 # no in-place modification of the original config.
   1030 config = copy.deepcopy(config)

File /usr/local/lib/python3.12/dist-packages/huggingface_hub/utils/_validators.py:114, in validate_hf_hub_args.<locals>._inner_fn(*args, **kwargs)
    111 if check_use_auth_token:
    112     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
--> 114 return fn(*args, **kwargs)

File /usr/local/lib/python3.12/dist-packages/diffusers/configuration_utils.py:384, in ConfigMixin.load_config(cls, pretrained_model_name_or_path, return_unused_kwargs, return_commit_hash, **kwargs)
    382         config_file = os.path.join(pretrained_model_name_or_path, cls.config_name)
    383     else:
--> 384         raise EnvironmentError(
    385             f"Error no file named {cls.config_name} found in directory {pretrained_model_name_or_path}."
    386         )
    387 else:
    388     try:
    389         # Load from URL or cache if already cached

OSError: Error no file named config.json found in directory $PATH_TO_LOCAL_DIR$/stabilityai/stable-diffusion-3.5-large/.

I don't see a config.json file in this repo. What am I doing wrong?

rtcml changed discussion status to closed

Sign up or log in to comment