8989 unwrap_model ,
9090)
9191from megatron .bridge .models .decorators .dispatch import dispatch
92- from megatron .bridge .models .gpt .model_config import BridgeGPTModelConfig
9392from megatron .bridge .models .hf_pretrained .causal_lm import PreTrainedCausalLM
9493from megatron .bridge .models .model_provider import ModelProviderMixin
9594from megatron .bridge .models .transformer_config import TransformerConfig as BridgeTransformerConfig
@@ -529,16 +528,18 @@ def mapping_registry(self) -> MegatronMappingRegistry:
529528 # provider, such as one implementing MLA.
530529 PROVIDER_CLASS = None
531530
532- # Builder-backed construction is rolling out incrementally by model family. Override this
533- # when the standard GPT model config cannot represent the model, and set it to None for
534- # families that have not yet migrated. The selected model config owns its nested
535- # transformer config class.
536- MODEL_CONFIG_CLASS : ClassVar [type [ModelConfig ] | None ] = BridgeGPTModelConfig
531+ # Builder-backed construction is rolling out incrementally by model family, so it is opt-in.
532+ # None means the family has not migrated: get_model_config() raises and the provider path
533+ # stays the supported one. A family that has mapped its Hugging Face config for the builder
534+ # path sets this to BridgeGPTModelConfig, or to a specialized config when the standard GPT
535+ # model config cannot represent the model. Subclasses of a migrated bridge inherit the
536+ # opt-in. The selected model config owns its nested transformer config class.
537+ MODEL_CONFIG_CLASS : ClassVar [type [ModelConfig ] | None ] = None
537538
538539 # Conversion still uses the provider-backed construction path unless a model family has
539540 # explicitly migrated its conversion lifecycle to ModelBuilder. Keeping this separate
540- # from MODEL_CONFIG_CLASS preserves get_model_config() for legacy families without
541- # silently changing how their checkpoints are constructed.
541+ # from MODEL_CONFIG_CLASS lets a family expose get_model_config() without silently
542+ # changing how its checkpoints are constructed. Requires MODEL_CONFIG_CLASS to be set .
542543 USE_MODEL_CONFIG_FOR_CONVERSION : ClassVar [bool ] = False
543544
544545 # Leave unset unless HF export must copy nonstandard files in addition to the usual artifacts,
@@ -814,26 +815,12 @@ def _partition_model_config_kwargs(
814815 }
815816 return model_kwargs , transformer_kwargs
816817
817- def _has_model_config_mapping (self ) -> bool :
818- """Return whether this bridge maps its Hugging Face config to a builder-backed config.
819-
820- The base ``hf_config_to_model_config_kwargs()`` maps only the generic
821- ``CONFIG_MAPPING`` fields. Family-specific settings such as position
822- embeddings, normalization, or bias flags stay in ``provider_bridge()``
823- until a family overrides one of the builder-backed hooks.
824- """
825- bridge_class = type (self )
826- return (
827- bridge_class .hf_config_to_model_config_kwargs is not MegatronModelBridge .hf_config_to_model_config_kwargs
828- or bridge_class .hf_config_to_model_config is not MegatronModelBridge .hf_config_to_model_config
829- )
830-
831818 def hf_config_to_model_config (self , hf_config : PretrainedConfig ) -> ModelConfig :
832819 """Convert a Hugging Face config directly to a builder-backed config.
833820
834- GPT-style model families use ``BridgeGPTModelConfig `` by default.
835- A bridge may select a specialized config class or explicitly disable
836- this path by setting ``MODEL_CONFIG_CLASS`` to ``None`` .
821+ This path is opt-in per model family. ``MODEL_CONFIG_CLASS `` defaults to
822+ ``None``; a migrated family sets it to ``BridgeGPTModelConfig`` or to a
823+ specialized config class .
837824
838825 Args:
839826 hf_config: Hugging Face architecture configuration.
@@ -842,21 +829,16 @@ def hf_config_to_model_config(self, hf_config: PretrainedConfig) -> ModelConfig:
842829 Serializable model configuration linked to its builder.
843830
844831 Raises:
845- ModelConfigNotSupportedError: If the model family explicitly disables this path
846- or has not migrated its config mapping .
832+ ModelConfigNotSupportedError: If the model family has not migrated to
833+ builder-backed configs (``MODEL_CONFIG_CLASS`` is ``None``) .
847834 ValueError: If mapped fields do not belong to either config dataclass.
848835 """
849836 model_config_class = self .MODEL_CONFIG_CLASS
850837 if model_config_class is None :
851838 raise ModelConfigNotSupportedError (
852839 f"ModelConfig conversion is not implemented for { type (self ).__name__ } . "
853- "This model family sets MODEL_CONFIG_CLASS to None."
854- )
855- if not self ._has_model_config_mapping ():
856- raise ModelConfigNotSupportedError (
857- f"ModelConfig conversion is not implemented for { type (self ).__name__ } . "
858- "This model family has not migrated its Hugging Face config mapping; "
859- "use AutoBridge.to_megatron_provider() instead."
840+ "This model family has not migrated to builder-backed configs "
841+ "(MODEL_CONFIG_CLASS is None); use AutoBridge.to_megatron_provider() instead."
860842 )
861843
862844 config_kwargs = self .hf_config_to_model_config_kwargs (hf_config )
@@ -912,7 +894,7 @@ def provider_bridge(self, hf_pretrained: HFPreTrained) -> ModelProviderTarget:
912894 from megatron .bridge .models .gpt_provider import GPTModelProvider
913895 from megatron .bridge .models .mla_provider import MLAModelProvider
914896
915- if self .MODEL_CONFIG_CLASS is not None and self . _has_model_config_mapping () :
897+ if self .MODEL_CONFIG_CLASS is not None :
916898 warnings .warn (
917899 f"{ type (self ).__name__ } .provider_bridge() and AutoBridge.to_megatron_provider() "
918900 "are deprecated for builder-backed models. Use AutoBridge.get_model_config() "
0 commit comments