Comments (8)
You can explicitly stop averaging across GPUs by calling:
with model.no_sync():
loss.backward()
I hope that helps in your case :)
from sam.
You can explicitly stop averaging across GPUs by calling:
with model.no_sync(): loss.backward()I hope that helps in your case :)
Thanks a lot. But I mean the DDP can average the gradients automatically, so we don't need to do the reduce_gradients_from_all_accelerators()
. Is that right?
from sam.
I just did some testing and this seems to work and be the same way they do it in the paper.
from sam.
Hi, thank you very much for this great suggestion!
I have not tried distributed training with SAM but your code seems to be in line with the paper. Does it produce better results than reducing the gradients before both steps? I will add a comment about the independent computation into readme — or, if you want, you can make a pull request (as you know more about this important detail than me) :)
from sam.
So I haven't done an exact side-by-side study yet, but it seems to improve things. I looked closely at the authors' jax code and yours and I'm sure it's the exact same as the way they do it, so that's good. I'm pretty busy so probably won't get around to a pull request, but yeah you could add this to the readme, might be useful. Cheers! I'll get around to doing an exact side-by-side test and report back
from sam.
I use DDP to parallelize the model training on multiple machines. It seems that DDP will automatically average the gradients on different GPUs during backpropagation.
from sam.
I was using TPUs when I wrote that example
from sam.
You can explicitly stop averaging across GPUs by calling:
with model.no_sync(): loss.backward()I hope that helps in your case :)
Should wrap the whole loss calculation to the context. Otherwise it won't work, afaik.
with model.no_sync():
loss = criterion(model(inputs), targets)
loss.backward()
from sam.
Related Issues (20)
- "TypeError: __init__() missing 1 required positional argument: 'base_optimizer'" with 'ddp_sharded'' HOT 1
- Any chance for the implementation of the recent Fisher SAM? HOT 3
- Is saving the state by calling .state_dict() sufficient? HOT 4
- sam install HOT 1
- RuntimeError: stack expects a non-empty TensorList?? HOT 1
- RuntimeError: stack expects a non-empty TensorList HOT 2
- i found it hard to implement this optimizer on yolov5.looking forward to s.b. could do me a FAVOR. THX HOT 5
- Training Tips for multiple GPUs may be invalid! HOT 3
- Using SAM with torch.cuda.amp.GradScaler HOT 1
- Setting Rho == 0 is NOT equivalent to running the base optimizer HOT 1
- Wrong Adaptive mode? HOT 1
- SAM yolov5 HOT 1
- Has anyone reproduce the ViT on ImageNet results using this torch implementation? HOT 2
- bayesian-sam HOT 1
- Readme.MD Usage typo issue HOT 1
- SAM doesn't seem to be doing well HOT 2
- `model.no_sync()` should include the forward pass HOT 1
- bypass_bn is missing HOT 1
- Using the step function with closure HOT 1
- Will Layernorm or Groupnorm cause problems?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sam.