GithubHelp home page GithubHelp logo

Comments (3)

stas00 avatar stas00 commented on May 21, 2024 1

There are 2 ways that I know of to measure peak GPU memory:

from ml-engineering.

stas00 avatar stas00 commented on May 21, 2024

There are a few places where the Deepspeed implementation of ZeRO upcasts grads to fp32:

  1. it does it before stepping as it tries not to meddle with the optim API, so any optimizer can be used. It'd have to meddle with the optim API to perform the upcasting on the fly.
  2. If you use communication_data_type=fp32, to avoid the lossy reduction of grads, it'll also upcast to fp32, though only doing it to the amount of params fitting into the current reduction bucket (so typically far less than all params).

So there are at least those 2 cases where 4 bytes are used. This might change in the future.

Now those upcasts can really be considered temp memory usage as they use peak memory, but practically this is 4 bytes per param.

I don't know how Apex does it.

How do you measure memory usage, are you taking into the account the peak memory? Which would have led to OOM if there weren't enough spare.

You can try this package in a jupyter notebook https://github.com/stas00/ipyexperiments if you want automated reports of peak and normal memory usages. The package is very trivial to setup and you will just need to load your code into a jupyter notebook, which sometimes can be more difficult to setup. But you could use even something as simple as https://github.com/Syllo/nvtop to get the peak memory usage.

from ml-engineering.

SumanthRH avatar SumanthRH commented on May 21, 2024

Got it! I understand now. Part of the issue was that I did not understand torch.autocast properly. After inspecting training step with mixed precision, it's clear that the full FP32 gradients are stored in HBM and this matches the memory consumption seen as well.

If you use communication_data_type=fp32, to avoid the lossy reduction of grads, it'll also upcast to fp32, though only doing it to the amount of params fitting into the current reduction bucket (so typically far less than all params).

Ah interesting. I believe I'll probably need to dig into the code to actually understand this fully :)

How do you measure memory usage, are you taking into the account the peak memory? Which would have led to OOM if there weren't enough spare.

Hmm I was using pynvml to measure current memory usage. You're right that peak memory is not accounted for here. ipyexperiments looks great! I'll check it out!

Thank you so much for the detailed reply!

from ml-engineering.

Related Issues (18)

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.