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

Fix GPU OOM for mistral.py::Mask4DTestHard #31212

Merged
merged 4 commits into from
Jun 3, 2024

Conversation

ydshieh
Copy link
Collaborator

@ydshieh ydshieh commented Jun 3, 2024

What does this PR do?

Fix GPU OOM for mistral.py::Mask4DTestHard

tests/models/mistral/test_modeling_mistral.py::Mask4DTestHard::test_partial_stacked_causal_mask
(line 1159)  torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 224.00 MiB. GPU
tests/models/mistral/test_modeling_mistral.py::Mask4DTestHard::test_stacked_causal_mask
(line 1159)  torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 224.00 MiB. GPU

job run page

https://github.com/huggingface/transformers/actions/runs/9343352211/job/25712939733

Comment on lines +742 to +746
if self.__class__._model is None:
self.__class__._model = MistralForCausalLM.from_pretrained(
self.model_name, torch_dtype=self.model_dtype
).to(torch_device)
return self.__class__._model
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we need to modify the class attribute instead of self._model.

Without this but just @cached_property, it still GPU OOM.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not ideal, but since it's slow tests which is meant to be run in a single process, we can accept this somehow hacky solution to avoid GPU OOM.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we even need @cached_property here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No :-), you have a very good 👁️ ! I will remove it.
(Actually, after this PR, I started to doubt if cached_property is working well with tests!)

@ydshieh ydshieh requested a review from amyeroberts June 3, 2024 16:03
self.model_dtype = torch.float32
self.tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
self.model = MistralForCausalLM.from_pretrained(model_name, torch_dtype=self.model_dtype).to(torch_device)
self.model_dtype = torch.float16
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This change is also necessary, otherwise still GPU OOM

@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.

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for fixing!

Comment on lines +742 to +746
if self.__class__._model is None:
self.__class__._model = MistralForCausalLM.from_pretrained(
self.model_name, torch_dtype=self.model_dtype
).to(torch_device)
return self.__class__._model
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we even need @cached_property here?

@ydshieh ydshieh merged commit 8a1a23a into main Jun 3, 2024
21 checks passed
@ydshieh ydshieh deleted the fix_Mask4DTestHard_for_mistral branch June 3, 2024 17:25
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Jun 11, 2024
* build

* build

* build

* build

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
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.

3 participants