bridge.models.sarvam.sarvam_moe_bridge#

Module Contents#

Classes#

SarvamMoEBridge

Megatron Hub Bridge for Sarvam MoE Causal LM.

API#

class bridge.models.sarvam.sarvam_moe_bridge.SarvamMoEBridge#

Bases: megatron.bridge.models.conversion.model_bridge.MegatronModelBridge

Megatron Hub Bridge for Sarvam MoE Causal LM.

This bridge handles the conversion between HuggingFace SarvamMoEForCausalLM and Megatron-Core GPTModel formats. Sarvam MoE models use mixture of experts architecture with QKV layernorm.

.. rubric:: Example

from megatron.bridge import AutoBridge bridge = AutoBridge.from_hf_pretrained(“sarvamai/sarvam-30b”, trust_remote_code=True) model_config = bridge.get_model_config()

MODEL_CONFIG_CLASS#

None

USE_MODEL_CONFIG_FOR_CONVERSION#

True

hf_config_to_model_config_kwargs(
hf_config: transformers.PretrainedConfig,
) → dict[str, Any]#

Convert a Hugging Face Sarvam MoE config to builder config kwargs.

The architecture sizes come from the HF config; the remaining settings are fixed for the Sarvam MoE family. The builder’s default MoE layer spec is the GPT decoder block spec, which honors the dense-first moe_layer_freq.

hf_config_to_provider_kwargs(
hf_config: transformers.PretrainedConfig,
) → dict[str, Any]#

Adapt the canonical builder mapping to the deprecated provider path.

SarvamMoEModelProvider keeps its decoder block spec, which handles the mixed dense/MoE moe_layer_freq.

classmethod megatron_to_hf_config(provider) → dict[str, Any]#

Convert the Megatron config to a Hugging Face Sarvam MoE config dict.

mapping_registry() → megatron.bridge.models.conversion.mapping_registry.MegatronMappingRegistry#