4646}
4747
4848_PIPELINE_MODEL_TYPES : dict [str , str ] = {
49+ "MiniMaxMusic3ModularPipeline" : "minimax_music3" ,
4950 "QwenImageEditPlusPipeline" : "qwen_image_edit" ,
5051}
5152
@@ -58,6 +59,11 @@ def _init_diffusers_class_map() -> None:
5859 from mobius ._diffusers_configs import (
5960 CLIPTextConfig ,
6061 CogVideoXConfig ,
62+ MiniMaxMusic3ConditionConfig ,
63+ MiniMaxMusic3LanguageConfig ,
64+ MiniMaxMusic3RVQConfig ,
65+ MiniMaxMusic3TransformerConfig ,
66+ MiniMaxMusic3VocoderConfig ,
6167 QwenImageConfig ,
6268 QwenImageTextEncoderConfig ,
6369 QwenImageVAEConfig ,
@@ -76,6 +82,13 @@ def _init_diffusers_class_map() -> None:
7682 SD3Transformer2DModel ,
7783 )
7884 from mobius .models .hunyuan_dit import HunyuanDiT2DModel , HunyuanDiTConfig
85+ from mobius .models .minimax_music3 import (
86+ MiniMaxMusic3ConditionEncoder ,
87+ MiniMaxMusic3LanguageModel ,
88+ MiniMaxMusic3RVQDepthDecoder ,
89+ MiniMaxMusic3Transformer1DModel ,
90+ MiniMaxMusic3Vocoder ,
91+ )
7992 from mobius .models .qwen_image import QwenImageTransformer2DModel
8093 from mobius .models .qwen_image_vae import AutoencoderKLQwenImageModel
8194 from mobius .models .qwen_vl import Qwen25VLCausalLMModel
@@ -124,6 +137,31 @@ def _init_diffusers_class_map() -> None:
124137 CogVideoXConfig ,
125138 "video-denoising" ,
126139 ),
140+ "Qwen3ForCausalLM" : (
141+ MiniMaxMusic3LanguageModel ,
142+ MiniMaxMusic3LanguageConfig ,
143+ "minimax-music3-language" ,
144+ ),
145+ "MiniMaxMusic3RVQDepthDecoder" : (
146+ MiniMaxMusic3RVQDepthDecoder ,
147+ MiniMaxMusic3RVQConfig ,
148+ "minimax-music3-rvq" ,
149+ ),
150+ "MiniMaxMusic3ConditionEncoder" : (
151+ MiniMaxMusic3ConditionEncoder ,
152+ MiniMaxMusic3ConditionConfig ,
153+ "minimax-music3-condition" ,
154+ ),
155+ "MiniMaxMusic3Transformer1DModel" : (
156+ MiniMaxMusic3Transformer1DModel ,
157+ MiniMaxMusic3TransformerConfig ,
158+ "minimax-music3-denoising" ,
159+ ),
160+ "MiniMaxMusic3Vocoder" : (
161+ MiniMaxMusic3Vocoder ,
162+ MiniMaxMusic3VocoderConfig ,
163+ "minimax-music3-vocoder" ,
164+ ),
127165 }
128166 )
129167
@@ -136,15 +174,20 @@ def _load_diffusers_pipeline_index(
136174 Returns the parsed JSON dict, or ``None`` if not found.
137175 """
138176 from huggingface_hub import hf_hub_download
177+ from huggingface_hub .utils import EntryNotFoundError
139178
140- try :
141- path = hf_hub_download (
142- repo_id = model_id ,
143- filename = "model_index.json" ,
144- revision = revision ,
145- )
146- except (OSError , ValueError ) as e :
147- logger .debug ("Failed to download model_index.json for %s: %s" , model_id , e )
179+ path = None
180+ for filename in ("model_index.json" , "modular_model_index.json" ):
181+ try :
182+ path = hf_hub_download (
183+ repo_id = model_id ,
184+ filename = filename ,
185+ revision = revision ,
186+ )
187+ break
188+ except (EntryNotFoundError , OSError , ValueError ) as e :
189+ logger .debug ("Failed to download %s for %s: %s" , filename , model_id , e )
190+ if path is None :
148191 return None
149192
150193 with open (path ) as f :
@@ -156,6 +199,7 @@ def _download_diffusers_component_weights(
156199 component_name : str ,
157200 * ,
158201 revision : str | None = None ,
202+ subfolder : str | None = None ,
159203) -> dict [str , torch .Tensor ]:
160204 """Download weights for a specific component of a diffusers pipeline.
161205
@@ -168,7 +212,8 @@ def _download_diffusers_component_weights(
168212 from huggingface_hub import hf_hub_download
169213 from huggingface_hub .utils import EntryNotFoundError
170214
171- prefix = f"{ component_name } /"
215+ resolved_subfolder = component_name if subfolder is None else subfolder
216+ prefix = f"{ resolved_subfolder } /" if resolved_subfolder else ""
172217 # Diffusers uses two naming conventions for the weight basename, and either
173218 # safetensors (preferred) or PyTorch .bin serialization. Some real repos
174219 # (e.g. OFA-Sys/small-stable-diffusion-v0) ship only .bin.
@@ -234,26 +279,61 @@ def _load_diffusers_component_config(
234279 component_name : str ,
235280 * ,
236281 revision : str | None = None ,
282+ subfolder : str | None = None ,
237283) -> dict :
238284 """Load the config.json for a specific diffusers pipeline component."""
239285 from huggingface_hub import hf_hub_download
240286
287+ resolved_subfolder = component_name if subfolder is None else subfolder
288+ filename = f"{ resolved_subfolder } /config.json" if resolved_subfolder else "config.json"
241289 path = hf_hub_download (
242290 repo_id = model_id ,
243- filename = f" { component_name } /config.json" ,
291+ filename = filename ,
244292 revision = revision ,
245293 )
246294 with open (path ) as f :
247295 return json .load (f )
248296
249297
250- def _load_optional_diffusers_json (model_id : str , filename : str ) -> dict :
298+ def _resolve_diffusers_component_source (
299+ root_model_id : str ,
300+ root_revision : str | None ,
301+ component_name : str ,
302+ component_info : list ,
303+ ) -> tuple [str , str | None , str | None ]:
304+ """Resolve a modular component's repository, revision, and subfolder.
305+
306+ Legacy two-item entries always use ``root_model_id/component_name`` at the
307+ caller's revision. For modular three-item entries, an external repository
308+ uses its metadata revision independently of the root pin. A component that
309+ still references the root repository uses the explicit caller revision when
310+ supplied, otherwise its metadata revision.
311+ """
312+ if len (component_info ) == 2 or not isinstance (component_info [2 ], dict ):
313+ return root_model_id , root_revision , component_name
314+
315+ metadata = component_info [2 ]
316+ component_model_id = metadata .get ("pretrained_model_name_or_path" ) or root_model_id
317+ metadata_revision = metadata .get ("revision" )
318+ if component_model_id == root_model_id :
319+ component_revision = root_revision if root_revision is not None else metadata_revision
320+ else :
321+ component_revision = metadata_revision
322+ subfolder = metadata .get ("subfolder" ) if "subfolder" in metadata else component_name
323+ if subfolder is None :
324+ subfolder = ""
325+ return component_model_id , component_revision , subfolder
326+
327+
328+ def _load_optional_diffusers_json (
329+ model_id : str , filename : str , * , revision : str | None = None
330+ ) -> dict :
251331 """Load optional non-neural pipeline metadata without failing the build."""
252332 from huggingface_hub import hf_hub_download
253333 from huggingface_hub .utils import EntryNotFoundError
254334
255335 try :
256- path = hf_hub_download (repo_id = model_id , filename = filename )
336+ path = hf_hub_download (repo_id = model_id , filename = filename , revision = revision )
257337 except EntryNotFoundError :
258338 return {}
259339 with open (path ) as f :
@@ -347,10 +427,18 @@ def build_diffusers_pipeline(
347427 continue
348428 if components is not None and component_name not in components :
349429 continue
350- if not isinstance (component_info , list ) or len (component_info ) != 2 :
430+ if not isinstance (component_info , list ) or len (component_info ) not in ( 2 , 3 ) :
351431 continue
352432
353- library , class_name = component_info
433+ library , class_name = component_info [:2 ]
434+ component_model_id , component_revision , component_subfolder = (
435+ _resolve_diffusers_component_source (
436+ model_id ,
437+ revision ,
438+ component_name ,
439+ component_info ,
440+ )
441+ )
354442 if class_name not in _DIFFUSERS_CLASS_MAP :
355443 logger .info (
356444 "Skipping diffusers component '%s' (class '%s' from '%s' is not registered)." ,
@@ -367,10 +455,13 @@ def build_diffusers_pipeline(
367455 class_name ,
368456 )
369457
458+ component_source_kwargs = {"revision" : component_revision }
459+ if len (component_info ) == 3 and isinstance (component_info [2 ], dict ):
460+ component_source_kwargs ["subfolder" ] = component_subfolder
370461 component_config_dict = _load_diffusers_component_config (
371- model_id ,
462+ component_model_id ,
372463 component_name ,
373- revision = revision ,
464+ ** component_source_kwargs ,
374465 )
375466 component_configs [component_name ] = component_config_dict
376467 config = config_class .from_diffusers (component_config_dict )
@@ -415,9 +506,9 @@ def build_diffusers_pipeline(
415506
416507 if load_weights :
417508 state_dict = _download_diffusers_component_weights (
418- model_id ,
509+ component_model_id ,
419510 component_name ,
420- revision = revision ,
511+ ** component_source_kwargs ,
421512 )
422513 if hasattr (model_module , "preprocess_weights" ):
423514 state_dict = model_module .preprocess_weights (state_dict )
@@ -435,17 +526,36 @@ def build_diffusers_pipeline(
435526
436527 from mobius ._diffusers_configs import DiffusersPipelineConfig
437528
529+ def load_optional_component_json (component_name : str , filename : str ) -> dict :
530+ component_info = pipeline_index .get (component_name )
531+ if not isinstance (component_info , list ) or len (component_info ) not in (2 , 3 ):
532+ return {}
533+ source_model_id , source_revision , source_subfolder = (
534+ _resolve_diffusers_component_source (
535+ model_id ,
536+ revision ,
537+ component_name ,
538+ component_info ,
539+ )
540+ )
541+ component_filename = f"{ source_subfolder } /{ filename } " if source_subfolder else filename
542+ return _load_optional_diffusers_json (
543+ source_model_id ,
544+ component_filename ,
545+ revision = source_revision ,
546+ )
547+
438548 package .config = DiffusersPipelineConfig (
439549 source_model_id = model_id ,
440550 pipeline_class = pipeline_class ,
441551 component_configs = component_configs ,
442552 scheduler_config = (
443- _load_optional_diffusers_json ( model_id , "scheduler/ scheduler_config.json" )
553+ load_optional_component_json ( "scheduler" , "scheduler_config.json" )
444554 if "scheduler" in pipeline_index
445555 else {}
446556 ),
447557 processor_config = (
448- _load_optional_diffusers_json ( model_id , "processor/ preprocessor_config.json" )
558+ load_optional_component_json ( "processor" , "preprocessor_config.json" )
449559 if "processor" in pipeline_index
450560 else {}
451561 ),
0 commit comments