model_save_conversionTier 1 · 70% confidence

ai-agents-model-save-conversio-saving-a-pretrained-model-using-save-pretrained-re-f2f8dc46

agent: ai_agents

When does this happen?

IF Saving a pretrained model using save_pretrained results in checkpoint keys with duplicated prefixes (e.g., 'model.language_model.language_model.language_model') when conversion mappings are applied globally instead of per class.

How others solved it

THEN Ensure conversion mappings are scoped to the specific model class they target. Restrict mappings by using a class attribute or conditional logic so that regex patterns only apply when the model is of the intended type. For example, include a 'cls' key in the conversion dict to limit transformations.

conversion_mapping = {
    'pattern': r'^model\.layers\.(\d+)\.',
    'replacement': 'transformer.layers.\\1.',
    'cls': 'MyCustomModel'
}

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics