fix(trainer): preserve Nemotron Mamba parameter dtype (#3557)

## Summary

- Initialize Nemotron Mamba `A_log` and `D` parameters with the active
default dtype so FSDP units do not mix float32 and bfloat16 storage.
- Keep the existing float32 state-space computation by casting at use
time.
- Add a focused bfloat16 parameter-dtype regression test.

## Validation

- `ruff check src/prime_rl/trainer/models/nemotron_h/mamba.py
tests/unit/train/models/test_nemotron_h.py`
- Focused in-cluster GPU probe: `A_log=torch.bfloat16`,
`D=torch.bfloat16`
- One-step Nemotron 3.5 Super VLM + MATH + Dynamo run: optimizer
completed and policy v1 was applied over NCCL.
- Three-step Kubernetes run: all optimizer steps completed; policies v0
through v3 applied to Dynamo; Job succeeded.
- Trainer mismatch KL by step: `0.0274`, `0.0344`, `0.0309`.

W&B: https://wandb.ai/test232/nemotron35-vlm-rl/runs/jq06zl0l
This commit is contained in:
Biswa Panda
2026-09-23 13:35:34 -07:00
committed by GitHub
parent 94f359e8d6
commit 33e02a7a18
2 changed files with 14 additions and 3 deletions
@@ -105,8 +105,8 @@ class NemotronHMamba2(nn.Module):
bias=config.use_conv_bias,
)
self.dt_bias = nn.Parameter(torch.empty(self.num_heads))
self.A_log = nn.Parameter(torch.log(torch.arange(1, self.num_heads + 1, dtype=torch.float32)))
self.D = nn.Parameter(torch.ones(self.num_heads, dtype=torch.float32))
self.A_log = nn.Parameter(torch.arange(1, self.num_heads + 1, dtype=torch.get_default_dtype()).log())
self.D = nn.Parameter(torch.ones(self.num_heads))
self.norm = GatedRMSNorm(
self.intermediate_size,
group_size=self.intermediate_size // self.num_groups,
@@ -142,7 +142,7 @@ class NemotronHMamba2(nn.Module):
conv_weight = self.conv1d.weight
conv_bias = self.conv1d.bias
state_decay = -torch.exp(self.A_log.float())
skip = self.D
skip = self.D.float()
dt_bias = self.dt_bias
norm_weight = self.norm.weight
@@ -125,6 +125,17 @@ def test_nemotron_h_context_parallel_setup_finds_wrapped_mamba_layer():
assert mamba_layer.mamba.cp_context.cp_world_size == 2
def test_nemotron_h_mamba_parameters_follow_default_dtype():
config = NemotronHConfig(**_BASE, hybrid_override_pattern="ME*E")
with torch.device("meta"), default_dtype(torch.bfloat16):
model = NemotronHForCausalLM(config)
mamba = model.model.layers[0].mamba
assert isinstance(mamba, NemotronHMamba2)
assert mamba.A_log.dtype == torch.bfloat16
assert mamba.D.dtype == torch.bfloat16
def test_nemotron_h_no_latent_projection():
"""Verify model works without latent projections (moe_latent_size=None)."""
prime_config = NemotronHConfig(