Weight decay is applied to all model's parameters
Feature request
From what I understand (at least with FSDP training) verl applies weight decay to all model's parameters. This is incorrect approach as parameters such as biases or layer normalization should be excluded (example from hf transformers: https://github.com/huggingface/transformers/blob/4854dbf9da4086731256496cf4a8e4ea45d4d54e/src/transformers/trainer.py#L1191C1-L1268C30). This is even bigger problem considering that weight decay is enabled by default (weight_decay=0.01) in verl.
Motivation
improve trainings with verl
Your contribution
just reporting, not sure whether I'm missing something in my observation
You're correct. Weight decay should not be applied to all parameters. The standard practice is to exclude:
- Bias parameters - Should not have weight decay
- LayerNorm/BatchNorm parameters - Should not have weight decay
- Embedding parameters - Often excluded from weight decay
Current behavior in verl: If verl applies weight decay to all parameters uniformly, this is a bug that can affect training quality.
Expected behavior:
# Standard approach from HF Trainer
decay_parameters = get_parameter_names(model, [torch.nn.LayerNorm])
decay_parameters = [name for name in decay_parameters if "bias" not in name]
optimizer_grouped_parameters = [
{
"params": [p for n, p in model.named_parameters() if n in decay_parameters],
"weight_decay": weight_decay,
},
{
"params": [p for n, p in model.named_parameters() if n not in decay_parameters],
"weight_decay": 0.0,
},
]
Workaround for users:
Set weight_decay=0.0 in config and manually create optimizer groups if needed.
This should be addressed in a future release for better training quality.
中文:
我重新检查了当前公开源码,这个 issue 仍然是可复现且可行动的。FSDP 路径现在仍然把 module.parameters() 整体传给 build_optimizer,而 build_optimizer 只把单个 weight_decay 值传入优化器构造函数,没有按参数名或模块类型拆成 decay/no_decay 参数组:
- FSDP 默认配置仍是
weight_decay: 0.01: https://github.com/verl-project/verl/blob/054668350b76bb1a748a05536c5841ba225e71f5/verl/trainer/config/optim/fsdp.yaml#L20-L21 - 基础 OptimizerConfig 默认值也是
weight_decay = 0.01: https://github.com/verl-project/verl/blob/054668350b76bb1a748a05536c5841ba225e71f5/verl/workers/config/optimizer.py#L47-L50 - FSDP engine 使用
build_optimizer(module.parameters(), self.optimizer_config): https://github.com/verl-project/verl/blob/054668350b76bb1a748a05536c5841ba225e71f5/verl/workers/engine/fsdp/transformer_impl.py#L473-L477 build_optimizer直接把weight_decay传给 optimizer,没有 no-decay 参数组逻辑: https://github.com/verl-project/verl/blob/054668350b76bb1a748a05536c5841ba225e71f5/verl/workers/config/optimizer.py#L326-L351
建议保持此 issue 打开,作为 bug/feature-fix 跟踪项。一个合理修复是为 FSDP optimizer 构造 decay/no_decay 参数组,默认排除 bias、LayerNorm/RMSNorm 等 normalization 参数;是否排除 embedding 可以作为配置项或遵循 HuggingFace Trainer 的现有实践。
English:
I re-checked the current public source, and this issue still appears valid and actionable. The FSDP path still passes module.parameters() as one parameter collection into build_optimizer, and build_optimizer passes a single weight_decay value to the optimizer constructor without creating separate decay/no_decay parameter groups:
- FSDP default config still sets
weight_decay: 0.01: https://github.com/verl-project/verl/blob/054668350b76bb1a748a05536c5841ba225e71f5/verl/trainer/config/optim/fsdp.yaml#L20-L21 - The base OptimizerConfig default is also
weight_decay = 0.01: https://github.com/verl-project/verl/blob/054668350b76bb1a748a05536c5841ba225e71f5/verl/workers/config/optimizer.py#L47-L50 - The FSDP engine calls
build_optimizer(module.parameters(), self.optimizer_config): https://github.com/verl-project/verl/blob/054668350b76bb1a748a05536c5841ba225e71f5/verl/workers/engine/fsdp/transformer_impl.py#L473-L477 build_optimizerforwardsweight_decaydirectly to the optimizer and has no no-decay grouping logic: https://github.com/verl-project/verl/blob/054668350b76bb1a748a05536c5841ba225e71f5/verl/workers/config/optimizer.py#L326-L351
I recommend keeping this issue open as a bug/feature-fix tracking item. A reasonable fix would be to construct decay/no_decay parameter groups for FSDP optimizers, excluding bias and normalization parameters such as LayerNorm/RMSNorm by default; embedding exclusion could either be configurable or follow the existing HuggingFace Trainer practice.
This response was generated by a scheduled Codex GPT5.5 issue processing task.
@Kirrito-k423
中文
感谢你重新核查,这个结论很有帮助。我顺着你建议的参数分组方案继续看了一下,有个 FSDP1 的细节想先确认。
目前 FSDP1 默认是 use_orig_params=False。在这种情况下,优化器拿到的是 FSDP 合并后的 FlatParameter,一个参数里可能同时包含普通权重、bias 和 norm 参数。因此,直接照 Hugging Face 的方式拆成 decay/no-decay 两组,对 FSDP2 或 use_orig_params=True 没问题,但并不能真正修复默认的 FSDP1 路径。
你觉得这里更合适的做法是:
- 把 FSDP1 的默认值改为
use_orig_params=True,让 selective weight decay 成为默认行为;还是 - 暂时只在 FSDP2 或显式开启
use_orig_params=True时支持,并对其他情况给出明确提示?
我个人更倾向第一种,因为这样才算真正修复了 issue 里提到的默认行为。参数规则可以先保持简单:bias 和 normalization 参数不做 weight decay,embedding 继续遵循 Hugging Face Trainer 的默认行为;如果后续确实有需求,再增加可配置的排除规则。
另一个需要留意的点是,单参数组改成两个参数组后,旧 optimizer checkpoint 可能无法直接恢复。我们可以保留一个 legacy 选项,并把迁移方式写清楚。
如果你认可这个方向,我就按这个范围整理实现和测试。感谢建议!
English
Thanks for taking another look—this is very helpful. I followed the parameter-grouping approach you suggested and noticed one FSDP1-specific detail that I’d like to clarify first.
FSDP1 currently defaults to use_orig_params=False. In that mode, the optimizer sees FSDP FlatParameters, and one flat parameter may contain regular weights, biases, and normalization parameters together. So the usual Hugging Face-style decay/no-decay grouping works for FSDP2 or use_orig_params=True, but it would not actually fix the default FSDP1 path.
Which direction do you think would be preferable?
- Change the FSDP1 default to
use_orig_params=Trueand make selective weight decay the default behavior; or - Support it only for FSDP2 or explicitly enabled
use_orig_params=True, with a clear message for unsupported configurations.
I’m leaning toward the first option, since it would fully address the default behavior reported in this issue. We could keep the initial policy simple: no weight decay for biases and normalization parameters, while embeddings continue to follow the Hugging Face Trainer default. Additional exclusions could be made configurable later if needed.
One other consideration is checkpoint compatibility: changing from one optimizer parameter group to two may prevent older optimizer checkpoints from loading directly. We could preserve a legacy option and document the migration path clearly.
If this direction makes sense to you, I’ll use it to shape the implementation and tests. Thanks again for the guidance!