Comments (3)
There are 2 ways that I know of to measure peak GPU memory:
- using
pynvml
to take frequent snapshots (imprecise, but good enough) - that's whatipyexperiments
does - https://pytorch.org/docs/stable/generated/torch.cuda.max_memory_allocated.html - (but there is only one counter, so if more than application uses it and resets the counter - the results are unpredictable.)
from ml-engineering.
There are a few places where the Deepspeed implementation of ZeRO upcasts grads to fp32:
- 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.
- 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.
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)
- Parallel training hangs HOT 10
- Convert to bfloat16 failing HOT 2
- Missing `hparams` section HOT 2
- convert markdown to pdf HOT 10
- Minor Typo in emulate multi node HOT 4
- GPU requirements and cost estimation. HOT 4
- Daisy chain batch jobs HOT 1
- Improve folder structure HOT 3
- pip install -r build/requirements.txt fails due to github_md_utils HOT 3
- Quarto Site HOT 3
- Conflicting opinions about streaming data from cloud storage? HOT 2
- discuss the solutions to Not fully recovering spikes HOT 7
- ML
- TPU v4 has 1,200GB/s of mem bandwidth and not 2,400, right? HOT 1
- Question about changing precision post training HOT 2
- Question about the right hidden dim when using SwiGLU HOT 3
- Adding another logbook (kinda) HOT 1
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 ml-engineering.