Code Monkey home page Code Monkey logo

Comments (8)

davda54 avatar davda54 commented on August 16, 2024 2

You can explicitly stop averaging across GPUs by calling:

with model.no_sync():
    loss.backward()

I hope that helps in your case :)

from sam.

guozhiyao avatar guozhiyao commented on August 16, 2024 2

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.

evanatyourservice avatar evanatyourservice commented on August 16, 2024 1

I just did some testing and this seems to work and be the same way they do it in the paper.

from sam.

davda54 avatar davda54 commented on August 16, 2024

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.

evanatyourservice avatar evanatyourservice commented on August 16, 2024

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.

guozhiyao avatar guozhiyao commented on August 16, 2024

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.

evanatyourservice avatar evanatyourservice commented on August 16, 2024

I was using TPUs when I wrote that example

from sam.

yzlnew avatar yzlnew commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.