Skip to content

v0.11.1.dev33

@nxphi47 nxphi47 tagged this 26 Nov 01:28
Logs the gradient norm of each module group next to the total, to locate
where a gradient-norm spike comes from.

`clip_grad_norm_` already groups gradients by device mesh before
combining norms (dense and expert-parallel gradients reduce on different
meshes). It now groups by module as well and returns each group's norm
next to the total. The total is the root-sum-square of the groups, so it
is unchanged. The RL and SFT trainers log them as
`optim/grad_norm/{group}`.

Groups come from the parameter name (`grad_norm_group`):
- the block in a decoder layer: `self_attn`, `linear_attn`, `mlp`, or a
MoE's `mlp.experts`, `mlp.router`, `mlp.shared_expert`;
- `norm` for every norm;
- outside the layers, the top-level module: `embed_tokens`, `lm_head`.

Compile, activation-checkpoint and FSDP wrapper prefixes are ignored.
Nothing is logged with gradient offloading, which keeps its own norm.

## Cost
It is the same single pass over the gradients and the same bytes read,
split into more `foreach` launches. A MoE model under EP needs about 9
scalar all-reduces per step instead of 2, plus one host sync for the
group values at logging. That is well under a millisecond per step.

## Checks
On CPU:
- The total equals the previous single norm.
- The groups' root-sum-square equals the total.
- Clipping still scales the gradients to `max_norm`.
- A Qwen3.6-35B-A3B checkpoint's parameter names group into
`mlp.experts`, `linear_attn`, `self_attn`, `mlp.shared_expert`,
`mlp.router` and `norm`.
Assets 2
Loading