Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the correct available memory API for XPU #3076

Merged
merged 8 commits into from
Sep 9, 2024

Conversation

faaany
Copy link
Contributor

@faaany faaany commented Sep 4, 2024

What does this PR do?

This PR introduces the new API for get xpu available memory. Below is an example of before and after:

from transformers import AutoModelForSeq2SeqLM

model = AutoModelForSeq2SeqLM.from_pretrained("bigscience/T0pp", device_map="auto")
print(model.hf_device_map)

Before

{'': 'cpu'}

After

{'shared': 0, 'decoder.embed_tokens': 0, 'encoder.embed_tokens': 0, 'encoder.block.0': 0, 'encoder.block.1': 0, 'encoder.block.2': 0, 'encoder.block.3': 0, 'encoder.block.4': 0, 'encoder.block.5': 0, 'encoder.block.6': 1, 'encoder.block.7': 1, 'encoder.block.8': 1, 'encoder.block.9': 1, 'encoder.block.10': 1, 'encoder.block.11': 1, 'encoder.block.12': 1, 'encoder.block.13': 1, 'encoder.block.14': 2, 'encoder.block.15': 2, 'encoder.block.16': 2, 'encoder.block.17': 2, 'encoder.block.18': 2, 'encoder.block.19': 2, 'encoder.block.20': 2, 'encoder.block.21': 2, 'encoder.block.22': 3, 'encoder.block.23': 3, 'encoder.final_layer_norm': 3, 'encoder.dropout': 3, 'decoder.block.0': 3, 'decoder.block.1': 3, 'decoder.block.2': 3, 'decoder.block.3': 3, 'decoder.block.4': 4, 'decoder.block.5': 4, 'decoder.block.6': 4, 'decoder.block.7': 4, 'decoder.block.8': 4, 'decoder.block.9': 4, 'decoder.block.10': 5, 'decoder.block.11': 5, 'decoder.block.12': 5, 'decoder.block.13': 5, 'decoder.block.14': 5, 'decoder.block.15': 5, 'decoder.block.16': 6, 'decoder.block.17': 6, 'decoder.block.18': 6, 'decoder.block.19': 6, 'decoder.block.20': 6, 'decoder.block.21': 6, 'decoder.block.22': 7, 'decoder.block.23': 7, 'decoder.final_layer_norm': 7, 'decoder.dropout': 7, 'lm_head': 7}

@faaany faaany changed the title fix the not working torch.xpu.max_memory_allocated use the correct available memory API for XPU Sep 4, 2024
@muellerzr muellerzr marked this pull request as ready for review September 4, 2024 19:48
Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Overall this looks good to me, let's use device_index however rather than i (or something similar to avoid single-letter input names)

@faaany
Copy link
Contributor Author

faaany commented Sep 5, 2024

Thanks! Overall this looks good to me, let's use device_index however rather than i (or something similar to avoid single-letter input names)

thanks for pointing this out! Code Updated.

I also added a version check.

@HuggingFaceDocBuilderDev

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.

@faaany
Copy link
Contributor Author

faaany commented Sep 5, 2024

Hi @muellerzr , how do you think about the new update?

Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about it a bit more, let's:

  1. Move this to utils.memory
  2. Use the new implementation I've shown, which takes care of things a bit cleaner.

src/accelerate/utils/imports.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! This looks much cleaner :)

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM. I have a clarifying question, but it's not a blocker.

src/accelerate/utils/memory.py Outdated Show resolved Hide resolved
@faaany
Copy link
Contributor Author

faaany commented Sep 9, 2024

ok, I think we can merge now. 😊

@muellerzr muellerzr merged commit 4b4c036 into huggingface:main Sep 9, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants