fix(trainer): skip no-op weight conversion for dense models (#3069)

Dense models (Qwen3, Qwen3.5, Llama) use identical key names in both
HF and PrimeRL weight formats, so is_hf_state_dict and is_prime_state_dict
both returned True for the same state dict. The auto-conversion logic in
load_dcp_from_hf would fire anyway, performing a no-op convert and
attempting to save the unchanged weights into the snapshot directory —
which crashes with OSError [Errno 30] Read-only file system when the
model cache is mounted read-only.

Fix: make is_hf_state_dict / is_prime_state_dict mutually exclusive for
dense models by having is_prime_state_dict return False (following the
pattern already used by GPT-OSS). This makes the conversion branches
naturally skip when there is no format difference, without needing
extra guards in load_dcp_from_hf.

MoE models are unaffected: their is_hf_state_dict / is_prime_state_dict
checks are already mutually exclusive (expert.0.w1 vs experts.w1 key
patterns).
This commit is contained in:
samsja
2026-07-23 19:08:58 +02:00
committed by GitHub
parent 3b5d031028
commit 45488ca048
3 changed files with 12 additions and 4 deletions
@@ -124,8 +124,10 @@ class LlamaPreTrainedModel(PreTrainedModelPrimeRL):
@classmethod
def is_prime_state_dict(cls, state_dict: dict[str, Tensor]) -> bool:
"""Check if the state dict is in PrimeRL training format."""
return True
# Dense models use identical key names in HF and PrimeRL format, so we
# never claim to be in a separate PrimeRL format. This disables the
# auto-conversion path in load_dcp_from_hf and lets DCP load directly.
return False
@classmethod
def convert_to_hf(cls, state_dict: dict[str, Tensor]) -> dict[str, Tensor]:
@@ -107,7 +107,10 @@ class Qwen3PreTrainedModel(PreTrainedModelPrimeRL):
@classmethod
def is_prime_state_dict(cls, state_dict: dict[str, Tensor]) -> bool:
return True
# Dense models use identical key names in HF and PrimeRL format, so we
# never claim to be in a separate PrimeRL format. This disables the
# auto-conversion path in load_dcp_from_hf and lets DCP load directly.
return False
@classmethod
def convert_to_hf(cls, state_dict: dict[str, Tensor]) -> dict[str, Tensor]:
@@ -160,7 +160,10 @@ class Qwen3_5PreTrainedModel(PreTrainedModelPrimeRL, HFQwen3_5PreTrainedModel):
@classmethod
def is_prime_state_dict(cls, state_dict: dict[str, Tensor]) -> bool:
return True
# Dense models use identical key names in HF and PrimeRL format, so we
# never claim to be in a separate PrimeRL format. This disables the
# auto-conversion path in load_dcp_from_hf and lets DCP load directly.
return False
@classmethod
def convert_to_hf(cls, state_dict: dict[str, Tensor]) -> dict[str, Tensor]: