{"record":{"id":"3c1ce1b1617ede7e","repo":"hiyouga/LlamaFactory","slug":"failed-to-export-model-weight-conversion-reversal","errorCode":null,"errorMessage":"Failed to export model: weight conversion reversal is not supported for this model architecture (NotImplementedError in transformers.core_model_loading.reverse_op). This is a known issue with transformers>=5.0 for certain model types (e.g. Mistral/Ministral). Workarounds: (1) use transformers<5.0, or (2) report the issue to the transformers repository.","messagePattern":"Failed to export model: weight conversion reversal is not supported for this model architecture \\(NotImplementedError in transformers\\.core_model_loading\\.reverse_op\\)\\. This is a known issue with transformers>=5\\.0 for certain model types \\(e\\.g\\. Mistral/Ministral\\)\\. Workarounds: \\(1\\) use transformers<5\\.0, or \\(2\\) report the issue to the transformers repository\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/train/tuner.py","lineNumber":222,"sourceCode":"        else:\n            output_dtype = getattr(torch, model_args.infer_dtype)\n\n        setattr(model.config, \"torch_dtype\", output_dtype)\n        model = model.to(output_dtype)\n        logger.info_rank0(f\"Convert model dtype to: {output_dtype}.\")\n\n    # Prepare save arguments (safe_serialization removed in transformers v5.0.0)\n    save_kwargs = {\n        \"save_directory\": model_args.export_dir,\n        \"max_shard_size\": f\"{model_args.export_size}GB\",\n    }\n    if not is_transformers_version_greater_than(\"5.0.0\"):\n        save_kwargs[\"safe_serialization\"] = not model_args.export_legacy_format\n\n    try:\n        model.save_pretrained(**save_kwargs)\n    except NotImplementedError as err:\n        raise RuntimeError(\n            \"Failed to export model: weight conversion reversal is not supported for this model architecture \"\n            \"(NotImplementedError in transformers.core_model_loading.reverse_op). \"\n            \"This is a known issue with transformers>=5.0 for certain model types (e.g. Mistral/Ministral). \"\n            \"Workarounds: (1) use transformers<5.0, or (2) report the issue to the transformers repository.\"\n        ) from err\n\n    if model_args.export_hub_model_id is not None:\n        # Prepare push arguments (safe_serialization removed in transformers v5.0.0)\n        push_kwargs = {\n            \"max_shard_size\": f\"{model_args.export_size}GB\",\n        }\n        if not is_transformers_version_greater_than(\"5.0.0\"):\n            push_kwargs[\"safe_serialization\"] = not model_args.export_legacy_format\n\n        model.push_to_hub(\n            model_args.export_hub_model_id,\n            token=model_args.hf_hub_token,\n            **push_kwargs,","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/train/tuner.py#L204-L240","documentation":"export_model wraps `model.save_pretrained` (src/llamafactory/train/tuner.py:222). On transformers>=5.0, saving certain architectures (e.g. Mistral/Ministral) can hit NotImplementedError in `transformers.core_model_loading.reverse_op`, which cannot invert a weight-conversion op back to the checkpoint format. LlamaFactory re-raises it as RuntimeError with the known-issue explanation and workarounds. The bug is upstream in transformers, not in your config.","triggerScenarios":"`llamafactory-cli export` with transformers>=5.0.0 installed and an affected architecture (Mistral, Ministral, and other models whose conversion path lacks a reverse op).","commonSituations":"Environments that auto-upgraded transformers to 5.x; exporting community Mistral fine-tunes that previously worked on 4.x.","solutions":["Downgrade: `pip install \"transformers<5.0.0\"` (and align any dependent pins), then re-export.","Report/track the issue in the transformers repository and upgrade once fixed.","As a stopgap on 5.x, save via a different route (e.g. state_dict + safetensors manually) if you accept non-standard layout."],"exampleFix":"# shell\npip install \"transformers<5.0.0\"\nllamafactory-cli export mistral_export.yaml","handlingStrategy":"try-catch","validationCode":"from packaging.version import Version\nimport transformers\ndef transformers5_export_safe() -> bool:\n    return Version(transformers.__version__) < Version(\"5.0.0\")","typeGuard":null,"tryCatchPattern":"try:\n    export_model(args)\nexcept RuntimeError as e:\n    if \"reverse_op\" in str(e):\n        # pin transformers<5.0.0 and retry once\n        raise SystemExit(\"Re-run with transformers<5.0.0\") from e\n    raise","preventionTips":["Pin transformers<5.0.0 in environments that export Mistral-family models.","Test export on a small checkpoint after any transformers major upgrade."],"tags":["export","transformers-5","version-incompatibility","mistral"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}