2020
2121MODEL_SOURCES = ["modelscope" , "civitai" ]
2222
23+ # Global registry for custom fetch function
24+ _CUSTOM_MODELSCOPE_FETCHER = None
25+
26+
27+ def register_fetch_modelscope_model (fetch_func ):
28+ """
29+ Register a global custom fetch function for ModelScope models.
30+
31+ Args:
32+ fetch_func (callable): Custom fetch function that should accept the same parameters
33+ as fetch_modelscope_model and return the model path(s)
34+ """
35+ global _CUSTOM_MODELSCOPE_FETCHER
36+ _CUSTOM_MODELSCOPE_FETCHER = fetch_func
37+ logger .info ("Registered global custom ModelScope fetcher" )
38+
39+
40+ def reset_fetch_modelscope_model ():
41+ """
42+ Reset the global custom fetch function for ModelScope models.
43+ """
44+ global _CUSTOM_MODELSCOPE_FETCHER
45+ _CUSTOM_MODELSCOPE_FETCHER = None
46+ logger .info ("Reset global custom ModelScope fetcher" )
47+
2348
2449def fetch_model (
2550 model_uri : str ,
@@ -43,6 +68,11 @@ def fetch_modelscope_model(
4368 access_token : Optional [str ] = None ,
4469 fetch_safetensors : bool = True ,
4570) -> str :
71+ # Check if there's a global custom fetcher registered
72+ if _CUSTOM_MODELSCOPE_FETCHER is not None :
73+ logger .info (f"Using global custom fetcher for model: { model_id } " )
74+ return _CUSTOM_MODELSCOPE_FETCHER (model_id , revision , path , access_token , fetch_safetensors )
75+
4676 lock_file_name = f"modelscope.{ model_id .replace ('/' , '--' )} .{ revision if revision else '__version' } .lock"
4777 lock_file_path = os .path .join (DIFFSYNTH_FILELOCK_DIR , lock_file_name )
4878 ensure_directory_exists (lock_file_path )
0 commit comments