Merged
Conversation
ArthurZucker
approved these changes
Jan 28, 2025
Collaborator
ArthurZucker
left a comment
There was a problem hiding this comment.
NIce I remember needing a special version of torch for this?
Also let's add a test (the current test does not cover this case)
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
bursteratom
pushed a commit
to bursteratom/transformers
that referenced
this pull request
Jan 31, 2025
* fix tp * Update modeling_utils.py * style * style * Update test_tp.py * Update test_tp.py * style * Update test_tp.py * Update test_tp.py * Update test_tp.py * Update test_tp.py
elvircrn
pushed a commit
to elvircrn/transformers
that referenced
this pull request
Feb 13, 2025
* fix tp * Update modeling_utils.py * style * style * Update test_tp.py * Update test_tp.py * style * Update test_tp.py * Update test_tp.py * Update test_tp.py * Update test_tp.py
sbucaille
pushed a commit
to sbucaille/transformers
that referenced
this pull request
Feb 16, 2025
* fix tp * Update modeling_utils.py * style * style * Update test_tp.py * Update test_tp.py * style * Update test_tp.py * Update test_tp.py * Update test_tp.py * Update test_tp.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
As per the title. When TP was introduced in #34184, it used a context manager
with torch.deviceto set the model device. However, the context manager actually does NOT put the tensor on the device explicitly (it simply changes the default device if using name without indices, such as "cuda" or .cuda()). This means that the model was still on CPU.Then
parallelize_modulewould automatically switch the model, however it uses the SAME gpu for all child processes. So it's fine for small models, but will OOM for larger ones (e.g. Llama 8B on 4x L4 GPU (24 GB) would OOM, even though it's supposed to take ~16 GB only).It does not look like we can instantiate only the model shards from the CPU to the different devices to avoid loading the full model on each device at the start.
To avoid that, I believe we could instantiate model on
metadevice, then recursively loading and dispatching each layer, which would avoif loading the full model in RAM then dispatching which goes against parallelization idea. Will try to explore it/see with accelerate team how we can do it.