hiyouga/LlamaFactory · error · RuntimeError
Failed to export model: weight conversion reversal is not su
Error message
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.
What it means
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.
Source
Thrown at src/llamafactory/train/tuner.py:222
else:
output_dtype = getattr(torch, model_args.infer_dtype)
setattr(model.config, "torch_dtype", output_dtype)
model = model.to(output_dtype)
logger.info_rank0(f"Convert model dtype to: {output_dtype}.")
# Prepare save arguments (safe_serialization removed in transformers v5.0.0)
save_kwargs = {
"save_directory": model_args.export_dir,
"max_shard_size": f"{model_args.export_size}GB",
}
if not is_transformers_version_greater_than("5.0.0"):
save_kwargs["safe_serialization"] = not model_args.export_legacy_format
try:
model.save_pretrained(**save_kwargs)
except NotImplementedError as err:
raise RuntimeError(
"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."
) from err
if model_args.export_hub_model_id is not None:
# Prepare push arguments (safe_serialization removed in transformers v5.0.0)
push_kwargs = {
"max_shard_size": f"{model_args.export_size}GB",
}
if not is_transformers_version_greater_than("5.0.0"):
push_kwargs["safe_serialization"] = not model_args.export_legacy_format
model.push_to_hub(
model_args.export_hub_model_id,
token=model_args.hf_hub_token,
**push_kwargs,View on GitHub (pinned to f28afaf635)
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.
Example fix
# shell pip install "transformers<5.0.0" llamafactory-cli export mistral_export.yaml
Defensive patterns
Strategy: try-catch
Validate before calling
from packaging.version import Version
import transformers
def transformers5_export_safe() -> bool:
return Version(transformers.__version__) < Version("5.0.0") Try / catch
try:
export_model(args)
except RuntimeError as e:
if "reverse_op" in str(e):
# pin transformers<5.0.0 and retry once
raise SystemExit("Re-run with transformers<5.0.0") from e
raise Prevention
- Pin transformers<5.0.0 in environments that export Mistral-family models.
- Test export on a small checkpoint after any transformers major upgrade.
When it happens
Trigger: `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).
Common situations: Environments that auto-upgraded transformers to 5.x; exporting community Mistral fine-tunes that previously worked on 4.x.
Related errors
- Dict is not supported.
- Quantization dataset is necessary for exporting.
- vLLM only accepts a single adapter. Merge them first.
- Cannot find satisfying example, considering decrease `export
- AutoGPTQ only accepts 2/3/4/8-bit quantization.
AI-assisted analysis of hiyouga/LlamaFactory@f28afaf635 (2026-08-14).
Data as JSON: /api/errors/3c1ce1b1617ede7e.
Report an issue: GitHub.