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

QLoRA #9340

Merged
merged 18 commits into from
Jun 7, 2024
Merged

QLoRA #9340

merged 18 commits into from
Jun 7, 2024

Conversation

cuichenx
Copy link
Collaborator

@cuichenx cuichenx commented May 29, 2024

What does this PR do ?

Add QLoRA

Current Results

Convergence

Llama 7b, Squad, packed seq 2k, LoRA on all layers
gbs4, 2e-4, 2k iterations
exact_match 89.199 f1 94.791 rougeL 94.400 total 6064.000

Normal LoRA (qkv only)
exact_match 88.819 f1 94.415 rougeL 94.084 total 6064.000

Memory Usage

Llama 13b, Alpaca, seq len 512, LoRA on all layers, gbs256
Peak memory reserved (GB):

Batch Size LoRA QLoRA % Reduction
2 37.5 18.3 51%
4 46.7 27.4 41%
8 65.4 46.4 29%

Performance

Llama 13b, Alpaca, seq len 512, LoRA on all layers, gbs256
Global batch step timing (s):

Batch Size LoRA QLoRA % Increase
2 2.7 6.7 148%
4 2.3 4.4 91%
8 2.2 3.2 46%

Collection: NLP

Changelog

  • Add specific line by line info of high level changes in this PR.

Usage

Set this flag in megatron_gpt_finetuning_config.yaml to enable QLoRA

model.peft.peft_scheme=qlora

To get the maximum memory savings, also set these flags

++model.dist_ckpt_load_on_device=False         # load checkpoint on CPU
++model.use_cpu_initialization=True            # initialize model on CPU
++model.peft.lora_tuning.target_modules=[all]  # quantize all linear layers in the model

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

  • Related to # (issue)

@github-actions github-actions bot added the NLP label May 29, 2024
@cuichenx cuichenx marked this pull request as ready for review June 3, 2024 22:21
@cuichenx cuichenx requested review from ertkonuk and arendu June 3, 2024 22:29
Signed-off-by: Chen Cui <[email protected]>
arendu
arendu previously approved these changes Jun 6, 2024
Copy link
Collaborator

@arendu arendu left a comment

Choose a reason for hiding this comment

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

LGTM! awesome PR!

@cuichenx cuichenx added Run CICD and removed Run CICD labels Jun 7, 2024
Signed-off-by: Chen Cui <[email protected]>
@arendu arendu merged commit ceffb49 into main Jun 7, 2024
135 checks passed
@arendu arendu deleted the chcui/qlora branch June 7, 2024 16:50
janekl pushed a commit that referenced this pull request Jun 12, 2024
* temp qlora implementation

Signed-off-by: Chen Cui <[email protected]>

* swap nf4 after model instantiation

Signed-off-by: Chen Cui <[email protected]>

* load model on cpu and then quantize on gpu

Signed-off-by: Chen Cui <[email protected]>

* model init on cpu to prevent memory spike

Signed-off-by: Chen Cui <[email protected]>

* account for TE versions

Signed-off-by: Chen Cui <[email protected]>

* guard use_cpu_initialization

Signed-off-by: Chen Cui <[email protected]>

* fix layernorm autograd Function

Signed-off-by: Chen Cui <[email protected]>

* add unit tests

Signed-off-by: Chen Cui <[email protected]>

* Apply isort and black reformatting

Signed-off-by: cuichenx <[email protected]>

* move cpu init to library code

Signed-off-by: Chen Cui <[email protected]>

* copyright header and nf4 quantize on GPU

Signed-off-by: Chen Cui <[email protected]>

* Apply isort and black reformatting

Signed-off-by: cuichenx <[email protected]>

* fix cpu init

Signed-off-by: Chen Cui <[email protected]>

* comments

Signed-off-by: Chen Cui <[email protected]>

* fix test

Signed-off-by: Chen Cui <[email protected]>

---------

Signed-off-by: Chen Cui <[email protected]>
Signed-off-by: cuichenx <[email protected]>
Co-authored-by: cuichenx <[email protected]>
Signed-off-by: Jan Lasek <[email protected]>
JesusPaz pushed a commit to JesusPaz/NeMo that referenced this pull request Jun 18, 2024
* temp qlora implementation

Signed-off-by: Chen Cui <[email protected]>

* swap nf4 after model instantiation

Signed-off-by: Chen Cui <[email protected]>

* load model on cpu and then quantize on gpu

Signed-off-by: Chen Cui <[email protected]>

* model init on cpu to prevent memory spike

Signed-off-by: Chen Cui <[email protected]>

* account for TE versions

Signed-off-by: Chen Cui <[email protected]>

* guard use_cpu_initialization

Signed-off-by: Chen Cui <[email protected]>

* fix layernorm autograd Function

Signed-off-by: Chen Cui <[email protected]>

* add unit tests

Signed-off-by: Chen Cui <[email protected]>

* Apply isort and black reformatting

Signed-off-by: cuichenx <[email protected]>

* move cpu init to library code

Signed-off-by: Chen Cui <[email protected]>

* copyright header and nf4 quantize on GPU

Signed-off-by: Chen Cui <[email protected]>

* Apply isort and black reformatting

Signed-off-by: cuichenx <[email protected]>

* fix cpu init

Signed-off-by: Chen Cui <[email protected]>

* comments

Signed-off-by: Chen Cui <[email protected]>

* fix test

Signed-off-by: Chen Cui <[email protected]>

---------

Signed-off-by: Chen Cui <[email protected]>
Signed-off-by: cuichenx <[email protected]>
Co-authored-by: cuichenx <[email protected]>
rohitrango pushed a commit to rohitrango/NeMo that referenced this pull request Jun 25, 2024
* temp qlora implementation

Signed-off-by: Chen Cui <[email protected]>

* swap nf4 after model instantiation

Signed-off-by: Chen Cui <[email protected]>

* load model on cpu and then quantize on gpu

Signed-off-by: Chen Cui <[email protected]>

* model init on cpu to prevent memory spike

Signed-off-by: Chen Cui <[email protected]>

* account for TE versions

Signed-off-by: Chen Cui <[email protected]>

* guard use_cpu_initialization

Signed-off-by: Chen Cui <[email protected]>

* fix layernorm autograd Function

Signed-off-by: Chen Cui <[email protected]>

* add unit tests

Signed-off-by: Chen Cui <[email protected]>

* Apply isort and black reformatting

Signed-off-by: cuichenx <[email protected]>

* move cpu init to library code

Signed-off-by: Chen Cui <[email protected]>

* copyright header and nf4 quantize on GPU

Signed-off-by: Chen Cui <[email protected]>

* Apply isort and black reformatting

Signed-off-by: cuichenx <[email protected]>

* fix cpu init

Signed-off-by: Chen Cui <[email protected]>

* comments

Signed-off-by: Chen Cui <[email protected]>

* fix test

Signed-off-by: Chen Cui <[email protected]>

---------

Signed-off-by: Chen Cui <[email protected]>
Signed-off-by: cuichenx <[email protected]>
Co-authored-by: cuichenx <[email protected]>
@ko3n1g ko3n1g mentioned this pull request Jul 18, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants