model_support.profile

model_support.profile

Composable model-family templates and per-model profiles.

Classes

Name Description
ModelFamilyTemplate Shared defaults for a family that follows the vanilla training path.
ModelHookContext Phase-specific inputs passed to a model hook.
ModelHookPhase Stable lifecycle boundaries available to model-specific hooks.
ModelHooks Model-specific hooks grouped by explicit lifecycle phase.
ModelMatchers Discovery predicates used when exact model_type lookup is unavailable.
ModelProfile Per-model declarations layered over a reusable family template.
ModelRegistrationOverrides Per-model registration overrides layered over family registrations.
ModelRegistrations Lazy payloads for transformers’ own extension registries.
ModelStrategies Lazy component providers supplied by a model family.
ModelStrategyOverrides Per-model component overrides layered over family strategies.
ResolvedModelProfile Immutable effective behavior for one registered model descriptor.

ModelFamilyTemplate

model_support.profile.ModelFamilyTemplate(
    name,
    is_multimodal=False,
    capabilities=dict(),
    strategies=ModelStrategies(),
    registrations=ModelRegistrations(),
    matchers=ModelMatchers(),
    hooks=ModelHooks(),
)

Shared defaults for a family that follows the vanilla training path.

ModelHookContext

model_support.profile.ModelHookContext(
    cfg,
    model_config=None,
    tokenizer=None,
    processor=None,
    model=None,
    inference=None,
    reference_model=None,
)

Phase-specific inputs passed to a model hook.

The dataclass prevents field reassignment, but the contained config and model objects remain mutable. Config loading phases populate only the fields available at that boundary; model loading phases also provide the tokenizer, optional processor, mode flags, and eventually the model instance. Optional fields and mode flags are None when the current boundary does not know them.

ModelHookPhase

model_support.profile.ModelHookPhase()

Stable lifecycle boundaries available to model-specific hooks.

ModelHooks

model_support.profile.ModelHooks(by_phase=dict(), replace_phases=frozenset())

Model-specific hooks grouped by explicit lifecycle phase.

Hooks append to inherited family hooks unless their phase is included in replace_phases. Replacing a phase with an empty tuple suppresses the family hooks for that phase.

ModelMatchers

model_support.profile.ModelMatchers(cfg=None, processor=None)

Discovery predicates used when exact model_type lookup is unavailable.

The config matcher runs at pre-config and tokenizer boundaries; the processor matcher runs while selecting multimodal processing. Matchers should be side-effect-free and return a boolean. Multiple matches are rejected as ambiguous.

Unlike ModelStrategyOverrides, None here always means inherit — matchers have no removal form, only overriding with a narrower predicate.

ModelProfile

model_support.profile.ModelProfile(
    family,
    is_multimodal=None,
    capabilities=dict(),
    strategies=ModelStrategyOverrides(),
    registrations=ModelRegistrationOverrides(),
    matchers=ModelMatchers(),
    hooks=ModelHooks(),
)

Per-model declarations layered over a reusable family template.

ModelRegistrationOverrides

model_support.profile.ModelRegistrationOverrides(
    weight_conversions=_INHERIT_STRATEGY,
    patch_mappings=_INHERIT_STRATEGY,
)

Per-model registration overrides layered over family registrations.

An omitted field inherits its family provider. Explicit None removes the inherited provider.

ModelRegistrations

model_support.profile.ModelRegistrations(
    weight_conversions=None,
    patch_mappings=None,
)

Lazy payloads for transformers’ own extension registries.

weight_conversions maps a model_type or model class name to WeightTransform entries registered via transformers.conversion_mapping.register_checkpoint_conversion_mapping; patch_mappings maps class names (or regex patterns) to replacement modules registered via transformers.monkey_patching.register_patch_mapping. Both are applied idempotently before model build. A patch mapping that changes a module’s checkpoint layout must ship matching weight conversions, or loading and saving break.

ModelStrategies

model_support.profile.ModelStrategies(
    auto_model_cls=None,
    processing_strategy_cls=None,
)

Lazy component providers supplied by a model family.

Each field is a zero-argument callable that returns a component class or None. Providers should import optional or heavyweight implementations only when called.

ModelStrategyOverrides

model_support.profile.ModelStrategyOverrides(
    auto_model_cls=_INHERIT_STRATEGY,
    processing_strategy_cls=_INHERIT_STRATEGY,
)

Per-model component overrides layered over family strategies.

An omitted field inherits its family provider. Explicit None removes the inherited provider and restores the downstream generic fallback.

ResolvedModelProfile

model_support.profile.ResolvedModelProfile(
    model_types,
    family,
    is_multimodal,
    capabilities,
    strategies,
    registrations,
    matchers,
    hooks,
)

Immutable effective behavior for one registered model descriptor.

Functions

Name Description
resolve_model_support Resolve family defaults, profile overrides, and legacy declarations.
run_model_support_hooks Run the effective hooks for one explicit lifecycle phase.

resolve_model_support

model_support.profile.resolve_model_support(support)

Resolve family defaults, profile overrides, and legacy declarations.

run_model_support_hooks

model_support.profile.run_model_support_hooks(support, phase, context)

Run the effective hooks for one explicit lifecycle phase.