Implementation:Alibaba ROLL AutoConfig
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Model_Architecture |
| Last Updated | 2026-02-07 20:00 GMT |
Overview
Auto-configuration registry and factory for loading and instantiating model configurations by model type in the mcore_adapter framework.
Description
This module implements a registry pattern for model configurations, allowing dynamic registration and lookup of McaModelConfig subclasses by model type string. The global CONFIG_MAPPING (an OrderedDict) serves as the central registry. The register_config function acts as both a decorator and a direct registration call, associating a model type string (e.g., "qwen3_omni_moe") with its configuration class. If a model type is re-registered, a warning is logged but the new class overrides the previous one.
The AutoConfig class provides two factory class methods:
- for_model: Instantiates a config class directly from a model type string and optional constructor arguments
- from_pretrained: Loads a config from a checkpoint directory by first checking for an mca_config.json file (MCA format), then falling back to the standard HuggingFace config.json. It reads the hf_model_type field to determine which registered config class to use, then delegates to that class's from_pretrained method.
Usage
Use register_config as a decorator on new McaModelConfig subclasses to register them with the auto-config system. Use AutoConfig.from_pretrained to load model configurations from checkpoint directories in a model-type-agnostic manner. Use AutoConfig.for_model when you know the model type and want to create a fresh config instance.
Code Reference
Source Location
- Repository: Alibaba_ROLL
- File: mcore_adapter/src/mcore_adapter/models/auto/config_auto.py
- Lines: 1-63
Signature
CONFIG_MAPPING: OrderedDict # Global registry
def register_config(model_type: str, cls=None): ...
def get_config_cls(model_type: str) -> Type[McaModelConfig]: ...
class AutoConfig:
@classmethod
def for_model(cls, model_type: str, *args, **kwargs) -> McaModelConfig: ...
@classmethod
def from_pretrained(cls, model_name_or_path: str, *args, **kwargs) -> McaModelConfig: ...
Import
from mcore_adapter.models.auto.config_auto import AutoConfig, register_config, get_config_cls, CONFIG_MAPPING
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model_type | str | Yes | String identifier for the model type (e.g., "qwen3_omni_moe", "qwen2") |
| cls | type or None | No | Config class to register; if None, returns a decorator |
| model_name_or_path | str | Yes (for from_pretrained) | Path to a checkpoint directory containing mca_config.json or config.json |
Outputs
| Name | Type | Description |
|---|---|---|
| (register_config) | type or Callable | The registered class, or a decorator if cls is None |
| (get_config_cls) | Type[McaModelConfig] | The registered config class for the given model type, or McaModelConfig as fallback |
| (AutoConfig.for_model) | McaModelConfig | A fresh config instance for the specified model type |
| (AutoConfig.from_pretrained) | McaModelConfig | A config instance loaded from a checkpoint directory |
Usage Examples
from dataclasses import dataclass
from mcore_adapter.models.auto.config_auto import AutoConfig, register_config
from mcore_adapter.models.model_config import McaModelConfig
# Register a new model config class
@register_config("my_model")
@dataclass
class MyModelConfig(McaModelConfig):
custom_param: int = 42
# Create config by model type
config = AutoConfig.for_model("my_model", custom_param=100)
# Load config from a pretrained checkpoint directory
config = AutoConfig.from_pretrained("/path/to/checkpoint")
print(config.hidden_size)