@@ -154,12 +154,30 @@ def check_imports(filename):
154154    return  get_relative_imports (filename )
155155
156156
157- def  get_class_in_module (class_name , module_path ):
157+ def  get_class_in_module (class_name , module_path ,  pretrained_model_name_or_path = None ):
158158    """ 
159159    Import a module on the cache directory for modules and extract a class from it. 
160160    """ 
161161    module_path  =  module_path .replace (os .path .sep , "." )
162-     module  =  importlib .import_module (module_path )
162+     try :
163+         module  =  importlib .import_module (module_path )
164+     except  ModuleNotFoundError  as  e :
165+         # This can happen when the repo id contains ".", which Python's import machinery interprets as a directory 
166+         # separator. We do a bit of monkey patching to detect and fix this case. 
167+         if  not  (
168+             pretrained_model_name_or_path  is  not None 
169+             and  "."  in  pretrained_model_name_or_path 
170+             and  module_path .startswith ("diffusers_modules" )
171+             and  pretrained_model_name_or_path .replace ("/" , "--" ) in  module_path 
172+         ):
173+             raise  e   # We can't figure this one out, just reraise the original error 
174+ 
175+         corrected_path  =  os .path .join (HF_MODULES_CACHE , module_path .replace ("." , "/" )) +  ".py" 
176+         corrected_path  =  corrected_path .replace (
177+             pretrained_model_name_or_path .replace ("/" , "--" ).replace ("." , "/" ),
178+             pretrained_model_name_or_path .replace ("/" , "--" ),
179+         )
180+         module  =  importlib .machinery .SourceFileLoader (module_path , corrected_path ).load_module ()
163181
164182    if  class_name  is  None :
165183        return  find_pipeline_class (module )
@@ -454,4 +472,4 @@ def get_class_from_dynamic_module(
454472        revision = revision ,
455473        local_files_only = local_files_only ,
456474    )
457-     return  get_class_in_module (class_name , final_module .replace (".py" , "" ))
475+     return  get_class_in_module (class_name , final_module .replace (".py" , "" ),  pretrained_model_name_or_path )
0 commit comments