deepspeedai / deepspeedai/DeepSpeed
How can I extract and log grad norm for individual layers
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 43.1k
- Forks
- 5k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 112
Description
I want to use gradients to monitor if the model is training properly, like this
I change the transformers.Trainer https://github.com/huggingface/transformers/blob/main/src/transformers/trainer.py#L1857 ,by add a function to get the parm.grad to log grad norm front the zero_grad.
But it not work for the model when use the DeepSpeed, parm.grad is None for all layers, I read the code and found comments said there is no way to return gradients when use DeepSpeed.
elif self.distributed_type == DistributedType.DEEPSPEED:
# `accelerator.backward(loss)` is doing that automatically. Therefore, its implementation is not needed
# We cannot return the gradient norm because DeepSpeed does it.
return None
So how can I get the grad norm for track training state when I am using the DeepSpeed?
I found a similar problem in megatron-deepspeed, but there seems to be no follow-up
https://github.com/bigscience-workshop/Megatron-DeepSpeed/issues/149
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked transformers Trainer location and accelerate.py around line 1499 to trace how DeepSpeed handles gradients, then compare the related Megatron-DeepSpeed issue. A complete resolution would need an agreed, tested way to obtain per-layer gradient norms during DeepSpeed training, but the issue does not specify the intended API or implementation location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- distributed-systems, machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100