You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just saw that there is a "gradient_clipping" option in the config. However, setting it to 1.0, does not eliminate the gradient overflow messages. Is this expected?
Gradient overflow messages, typically at the beginning of training, are not surprising. But this should eventually stop once the dynamic loss scale has decreased to a point that allows training stability.
Regarding to the original question, what's the purpose to disable 'max_grad_norm' for fp16?
if self.fp16_enabled() and 'max_grad_norm' in optimizer_parameters.keys():
optimizer_parameters['max_grad_norm'] = 0.0
The rationale for this was to support both the old and new ways of specifying gradient clipping. The difference is that in the old way, gradient clipping is specified as max_grad_norm parameter of the fp32 optimizer, while in the new (and more intuitive way IMHO) gradient clipping is handled in the fp16 wrapper optimizer, such as here. In summary, this logic allows the fp16 optimizers in DeepSpeed to handle both old and new gradient clipping styles.
All that said, we are thinking of ways to improve the interface and avoid this confusion, and we certainly appreciate your input on that.
The line this report points at is gone, and has been since 2020. Recording it here because the last word in the thread still defends the old behaviour, so the issue reads as unresolved.
optimizer_parameters['max_grad_norm'] = 0.0 was removed in abe2204d ("Support fp32 grad clipping and fix max_grad_norm confusion", #232, 2020-05-26), three months after this was filed. That commit deleted the assignment and turned the neighbouring warnings.warn into an unconditional raise ValueError, so the fp16-only silent override became a hard error at every precision. The intermediate step was 3ce531c9 (#205, 2020-04-30), which added the warning text while the assignment was still in place. First tag containing abe2204d is v0.2.0 (2020-06-11).
git blame on the current lines attributes them to those two commits and nothing has put the assignment back at that site, so @LiweiPeng's question about the purpose of disabling max_grad_norm under fp16 was effectively answered by the project deciding not to do it.
At HEAD 6098f799, clean python:3.11-slim container, torch 2.13.0+cpu, deepspeed installed with pip install -e . from the checkout (deepspeed.__file__ = /src/deepspeed/__init__.py):
[A: max_grad_norm in optimizer params] ValueError: 'max_grad_norm' is not supported as an
optimizer parameter, please switch to using the deepspeed parameter 'gradient_clipping'
see: https://www.deepspeed.ai/docs/config-json/#gradient-clipping for more details
[B: gradient_clipping] OK -> engine built, gradient_clipping=1.0
Arm A passes {"optimizer": {"type": "Adam", "params": {"lr": 1e-3, "max_grad_norm": 1.0}}}, arm B drops it and sets a top-level "gradient_clipping": 1.0 instead. So the config option @LvanderGoten found on the day he filed this is the supported route, and max_grad_norm now fails loudly rather than being silently zeroed.
Two things I did not check. I could not run the fp16 arm: fp16 is unsupported on the CPU accelerator and this machine has no GPU, so deepspeed.initialize rejects it before reaching the guard. The check at deepspeed/runtime/engine.py:2060 carries no precision condition, so by inspection it covers fp16 too, but that is read from the source rather than run. And the separate question in the thread, whether gradient_clipping: 1.0 ought to stop the overflow messages, was answered by @tjruwase at the time and I am not reopening it.
Activity
[-]max_grad_norm is ignore in FP16 training[/-][+]max_grad_norm is ignored in FP16 training[/+]LvanderGoten commentedon Feb 24, 2020
I just saw that there is a "gradient_clipping" option in the config. However, setting it to 1.0, does not eliminate the gradient overflow messages. Is this expected?
tjruwase commentedon Feb 24, 2020
Gradient overflow messages, typically at the beginning of training, are not surprising. But this should eventually stop once the dynamic loss scale has decreased to a point that allows training stability.
Are you not seeing the overflow messages stop?
LiweiPeng commentedon Mar 6, 2020
Regarding to the original question, what's the purpose to disable 'max_grad_norm' for fp16?
if self.fp16_enabled() and 'max_grad_norm' in optimizer_parameters.keys():
optimizer_parameters['max_grad_norm'] = 0.0
tjruwase commentedon Mar 19, 2020
The rationale for this was to support both the old and new ways of specifying gradient clipping. The difference is that in the old way, gradient clipping is specified as max_grad_norm parameter of the fp32 optimizer, while in the new (and more intuitive way IMHO) gradient clipping is handled in the fp16 wrapper optimizer, such as here. In summary, this logic allows the fp16 optimizers in DeepSpeed to handle both old and new gradient clipping styles.
All that said, we are thinking of ways to improve the interface and avoid this confusion, and we certainly appreciate your input on that.
update submodule deepspeedexamples to use torch.gelu (deepspeedai#102)
ebarkhordar commentedon Aug 20, 2026
The line this report points at is gone, and has been since 2020. Recording it here because the last word in the thread still defends the old behaviour, so the issue reads as unresolved.
optimizer_parameters['max_grad_norm'] = 0.0was removed inabe2204d("Support fp32 grad clipping and fix max_grad_norm confusion", #232, 2020-05-26), three months after this was filed. That commit deleted the assignment and turned the neighbouringwarnings.warninto an unconditionalraise ValueError, so the fp16-only silent override became a hard error at every precision. The intermediate step was3ce531c9(#205, 2020-04-30), which added the warning text while the assignment was still in place. First tag containingabe2204dis v0.2.0 (2020-06-11).git blameon the current lines attributes them to those two commits and nothing has put the assignment back at that site, so @LiweiPeng's question about the purpose of disablingmax_grad_normunder fp16 was effectively answered by the project deciding not to do it.At HEAD
6098f799, cleanpython:3.11-slimcontainer, torch 2.13.0+cpu, deepspeed installed withpip install -e .from the checkout (deepspeed.__file__ = /src/deepspeed/__init__.py):Arm A passes
{"optimizer": {"type": "Adam", "params": {"lr": 1e-3, "max_grad_norm": 1.0}}}, arm B drops it and sets a top-level"gradient_clipping": 1.0instead. So the config option @LvanderGoten found on the day he filed this is the supported route, andmax_grad_normnow fails loudly rather than being silently zeroed.Two things I did not check. I could not run the fp16 arm: fp16 is unsupported on the CPU accelerator and this machine has no GPU, so
deepspeed.initializerejects it before reaching the guard. The check atdeepspeed/runtime/engine.py:2060carries no precision condition, so by inspection it covers fp16 too, but that is read from the source rather than run. And the separate question in the thread, whethergradient_clipping: 1.0ought to stop the overflow messages, was answered by @tjruwase at the time and I am not reopening it.Looks closeable.