[BUG] `persist_pretrained_model` saves LoRA-keyed state_dict for PEFT models breaking inference on reload
[!WARNING] Before submitting a PR, please make sure that:
- A maintainer has triaged this issue and applied the
readylabel- This issue has no assignee
- No duplicate PR exists
PRs not meeting these requirements may be automatically closed.
Issues Policy acknowledgement
- I have read and agree to submit bug reports in accordance with the issues policy
Where did you encounter this bug?
Local machine
MLflow version
- Client: 3.13.0
- Tracking server: not applicable (local file store / SQLite reproduction)
System information
- OS Platform and Distribution: macOS 26.5 arm64 (Darwin Kernel 25.5.0)
- Python version: 3.12.10
- Also reproduced on: Databricks ML Runtime 16.x (Linux, transformers 4.51.x)
Describe the problem
When mlflow.transformers.persist_pretrained_model() runs on a PEFT/LoRA model, the persisted base weights are written with state_dict keys in LoRA-wrapped form (*.q_proj.base_layer.weight, *.q_proj.lora_A.default.weight, *.q_proj.lora_B.default.weight) instead of the expected flat keys (*.q_proj.weight).
At reload via mlflow.transformers.load_model(...), AutoModelForCausalLM.from_pretrained reports the flat keys as MISSING (newly initialized, random) and the LoRA-wrapped keys as UNEXPECTED.
Inference produces incoherent output.
Expected: persisted base weights should have flat keys matching the original AutoModelForCausalLM schema; reload restores intact weights.
Actual: persisted state_dict has LoRA-wrapped keys; reload produces a model with randomly re-initialized q_proj/v_proj weights.
This is silently triggered when registering a PEFT model to Databricks Unity Catalog: the UC REST store auto-invokes persist_pretrained_model at register_model time when the model has save_pretrained=False (which mlflow.transformers sets automatically for PeftModel). The user never calls persist_pretrained_model explicitly but ends up with a UC ModelVersion that can't be reloaded usefully.
Tracking information
System information: Darwin Darwin Kernel Version 25.5.0: Mon Apr 27 20:41:06 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T6030 Python version: 3.12.10 MLflow version: 3.13.0 Tracking URI: sqlite:///mlflow.db Registry URI: sqlite:///mlflow.db
Code to reproduce issue
"""
Reproduces the silent state_dict corruption when persist_pretrained_model
runs on a PEFT model.
Requires:
pip install "mlflow>=3.13" "peft>=0.19" "transformers>=4.51" "torch>=2.4"
"""
import mlflow
import mlflow.transformers
from peft import LoraConfig, TaskType, get_peft_model
from transformers import AutoModelForCausalLM, AutoTokenizer
BASE = "Qwen/Qwen3-0.6B"
REV = "c1899de289a04d12100db370d81485cdf75e47ca"
tokenizer = AutoTokenizer.from_pretrained(BASE, revision=REV)
base = AutoModelForCausalLM.from_pretrained(BASE, revision=REV, torch_dtype="auto")
peft_model = get_peft_model(
base,
LoraConfig(
task_type=TaskType.CAUSAL_LM, r=8, lora_alpha=16,
target_modules=["q_proj", "v_proj"],
),
)
with mlflow.start_run() as run:
info = mlflow.transformers.log_model(
transformers_model={"model": peft_model, "tokenizer": tokenizer},
name="model",
)
# This is what Unity Catalog triggers automatically at register_model.
# Invoked directly here to reproduce out of the UC context.
mlflow.transformers.persist_pretrained_model(info.model_uri)
# Reload — observe LOAD REPORT (q_proj.weight MISSING, base_layer/lora_A/lora_B UNEXPECTED)
# and the incoherent generation output.
loaded = mlflow.transformers.load_model(info.model_uri)
print(loaded("Hello, who are you?"))Stack trace
No exception raised — the bug is silent corruption + misleading inference output. The signal is the LOAD REPORT from transformers at load time:
Qwen3ForCausalLM LOAD REPORT from: /tmp/.../model
Key |
Status |
-------------------------------------------------------------+-----
-------+
model.layers.{0...27}.self_attn.q_proj.lora_A.default.weight |
UNEXPECTED |
model.layers.{0...27}.self_attn.q_proj.base_layer.weight |
UNEXPECTED |
model.layers.{0...27}.self_attn.q_proj.lora_B.default.weight |
UNEXPECTED |
model.layers.{0...27}.self_attn.v_proj.lora_A.default.weight |
UNEXPECTED |
model.layers.{0...27}.self_attn.v_proj.base_layer.weight |
UNEXPECTED |
model.layers.{0...27}.self_attn.v_proj.lora_B.default.weight |
UNEXPECTED |
model.layers.{0...27}.self_attn.q_proj.weight |
MISSING |
model.layers.{0...27}.self_attn.v_proj.weight |
MISSING |Generated text after persist + reload:
'Hello, who are you?elihoodếuếuwon//->__�력ếuancellableếuếuitzerland[]Other info / logs
This is silently triggered when registering a PEFT/LoRA model to Databricks Unity Catalog: the server-side
_download_model_weights_if_not_saved (in mlflow/store/_unity_catalog/registry/rest_store.py, lines 825-863 on commit c83d810b48f4fcc34d3ef8d060c3c22737c2f89f) auto-invokes persist_pretrained_model because the model has save_pretrained=False (which is automatically set by the flavor for PeftModel).
The user never calls persist_pretrained_model explicitly, but their UC ModelVersion ends up with a corrupted "base" that can't be reloaded usefully via models:/<3-part-name>@alias.
In mlflow/transformers/peft.py, replace:
def get_peft_base_model(model):
peft_config = model.peft_config.get(model.active_adapter) if
model.peft_config else None
if peft_config and not peft_config.is_prompt_learning:
return model.base_model.model
return model.base_modelwith:
import copy
def get_peft_base_model(model):
peft_config = model.peft_config.get(model.active_adapter) if
model.peft_config else None
if peft_config and not peft_config.is_prompt_learning:
# copy first to preserve the caller's PeftModel
return copy.deepcopy(model).unload()
return model.base_modelOr alternatively, have persist_pretrained_model explicitly reject PEFT models with an actionable error message pointing users to merge_and_unload() for the bundled-weights use case.
What component(s) does this bug affect?
-
area/tracking: Tracking Service, tracking client APIs, autologging -
area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry -
area/scoring: MLflow model serving, deployment tools, Spark UDFs -
area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows -
area/prompt: MLflow prompt engineering features, prompt templates, and prompt management -
area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality -
area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations -
area/projects: MLproject format, project running backends -
area/uiux: Front-end, user experience, plotting -
area/docs: MLflow documentation pages
Source: mlflow/mlflow