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

Fp8 integration #1086

Merged
merged 34 commits into from
Mar 7, 2023
Merged

Fp8 integration #1086

merged 34 commits into from
Mar 7, 2023

Conversation

sgugger
Copy link
Collaborator

@sgugger sgugger commented Feb 15, 2023

This PR brings FP8 mixed precision training to Accelerate. Using this requires a GPU Hopper or higher (hard to find at the moment!) and the transformers_engine library.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Feb 15, 2023

The documentation is not available anymore as the PR was closed or merged.

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.

Awesome job! I left a few notes and general questions, but great work :)

default to the value in the environment variable `ACCELERATE_MIXED_PRECISION`, which will use the default
value in the accelerate config of the current system or the flag passed with the `accelerate.launch`
command. 'fp16' requires pytorch 1.6 or higher. 'bf16' requires pytorch 1.10 or higher.
Whether or not to use mixed precision training (fp16 or bfloat16). Choose from 'no','fp16','bf16 or 'fp8'.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Whether or not to use mixed precision training (fp16 or bfloat16). Choose from 'no','fp16','bf16 or 'fp8'.
Whether or not to use mixed precision training (fp8, fp16, or bfloat16). Choose from 'no','fp16','bf16 or 'fp8'.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Based on the earlier comment, this could be "fp16, bfloat16, or fp8", or we remove the () and just have "Choose from"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removing the parenthesis entirely.

Comment on lines 1177 to 1179
f"The current device has compute capability of {torch.cuda.get_device_capability()} which is "
"insufficient for FP8 mixed precision training (requires a GPU Hopper or higher, compute "
"capability of 9 or higher). Will using FP16 instead."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this only warn? Or should it not explicitly raise an error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It still uses transformer engine instead of the regular model, so useful for testing on A100s

import transformer_engine.pytorch as te


def convert_model(model, to_transformer_engine=True, _convert_linear=True, _convert_ln=True):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this run an explicit try/catch for is_fp8_available and raise an error if not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It shouldn't be called if is_fp8_available is False.

examples/complete_cv_example.py Show resolved Hide resolved
Copy link
Contributor

@pacman100 pacman100 left a comment

Choose a reason for hiding this comment

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

Awesome! This is going to be a game-changer for LLM training. LGTM 🚀

src/accelerate/accelerator.py Outdated Show resolved Hide resolved
sgugger and others added 2 commits March 2, 2023 10:58
Co-authored-by: Sourab Mangrulkar <13534540+pacman100@users.noreply.github.com>
@sgugger sgugger merged commit 1bfde6b into main Mar 7, 2023
@sgugger sgugger deleted the fp8_integration branch March 7, 2023 14:10
@JulesGM
Copy link
Contributor

JulesGM commented Apr 2, 2023

I just made two new issues with fp8.
#1276
#1275

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.

None yet

5 participants