accelerator.gather() at training time
See original GitHub issueCan I use accelerator.gather() at training time? Would gradients be calculated properly? Basically my use case is something like below toy snippet. It seems that there is some issue with gradient flow in this scheme as my validation accuracy drops to 0.
model, optimizer, train_loader = accelerator.prepare(model, optimizer, train_loader)
for i, data in enumerate(train_loader):
model.zero_grad()
a, b = model(data)
b_all = accelerator.gather(b)
c = f(a, b_all)
loss = criterion(a, b, c)
accelerator.backward(loss)
optimizer.step()
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Quick tour - Hugging Face
We're on a journey to advance and democratize artificial intelligence through open source and open science.
Read more >About the use of gather to compute metrics · Issue #226 - GitHub
This code uses an Accuracy class to compute the epoch-wise accuracy from predictions and labels. It stores predictions/labels at each step to ...
Read more >GPU training (Intermediate) - PyTorch Lightning - Read the Docs
Use DDP which is more stable and at least 3x faster. Warning. DP only supports scattering and gathering primitive collections of tensors like...
Read more >Inside Hugging Face's Accelerate! – Weights & Biases - Wandb
Distributed data parallel training in PyTorch by Kevin Kaichuang ... Every time we initialize an Accelerator, accelerator = Accelerator(), ...
Read more >Introducing PyTorch-accelerated | by Chris Hughes
pytorch-accelerated is a lightweight library designed to accelerate the process of training PyTorch models by providing a minimal, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the tip! Using that it’s possible to add a
gather_with_grad
function that would work with training, leveraging the existinggather
.This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.