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

Packed Sequence #7945

Merged
merged 23 commits into from
Dec 16, 2023
Merged

Packed Sequence #7945

merged 23 commits into from
Dec 16, 2023

Conversation

cuichenx
Copy link
Collaborator

@cuichenx cuichenx commented Nov 27, 2023

What does this PR do ?

Support training with packed sequences for SFT and PEFT.
In this scenario, sequences in a batch are "concatenated" in the sequence length dimension, instead of "stacked" in a batch dimension.
This is shown to significantly improve the training throughput.
Packed sequences will need to be prepared in a particular way (script in #8682 )

Collection: NLP

Changelog

  • new GPTSFTPackedDataset class to handle the new dataset format
  • pass cu_seqlens and qkv_format to the forward() function of mcore model

Usage

Note: only train_ds is packed. Validation and test datasets are unchanged.

python /opt/NeMo/examples/nlp/language_modeling/tuning/megatron_gpt_peft_tuning.py \
...
+model.data.train_ds.packed_sequence=True

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 Nov 27, 2023
@cuichenx cuichenx marked this pull request as ready for review December 5, 2023 01:10
Copy link
Collaborator

@ericharper ericharper left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

Copy link
Collaborator

@ericharper ericharper left a comment

Choose a reason for hiding this comment

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

Sorry ignore my previous approval.

Could you please add unit tests?

See tests/collections/nlp/test_chat_sft_dataset.py as an example

@ericharper
Copy link
Collaborator

jenkins

@ericharper
Copy link
Collaborator

jenkins

Copy link
Collaborator

@ericharper ericharper left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for adding the unit test.

@ericharper ericharper merged commit ed0f681 into main Dec 16, 2023
15 checks passed
@ericharper ericharper deleted the chcui/packed_sft branch December 16, 2023 01:26
pzelasko pushed a commit to pzelasko/NeMo that referenced this pull request Jan 3, 2024
* support packed dataset

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

* support packed dataset

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix collate_fn bug for TP > 1

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* make packed dataset work

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix nan bug

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

* support answer only loss

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* account for padding in cu_seqlens during dataloading for attn kernel

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

* fix path for answer_only_loss = false

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

* @vysarge
Modify GPTSFTPackedDataset to respond to pad_to_max_length setting

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

* add unit test

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

* fix loss mask bug for answer_only_loss=False

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: Chen Cui <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric Harper <[email protected]>
Signed-off-by: Piotr Żelasko <[email protected]>
ssh-meister pushed a commit to ssh-meister/NeMo that referenced this pull request Feb 15, 2024
* support packed dataset

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

* support packed dataset

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix collate_fn bug for TP > 1

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* make packed dataset work

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix nan bug

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

* support answer only loss

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* account for padding in cu_seqlens during dataloading for attn kernel

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

* fix path for answer_only_loss = false

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

* @vysarge
Modify GPTSFTPackedDataset to respond to pad_to_max_length setting

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

* add unit test

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

* fix loss mask bug for answer_only_loss=False

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: Chen Cui <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric Harper <[email protected]>
Signed-off-by: Sasha Meister <[email protected]>
rohitrango pushed a commit to rohitrango/NeMo that referenced this pull request Jun 25, 2024
* support packed dataset

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

* support packed dataset

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix collate_fn bug for TP > 1

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* make packed dataset work

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix nan bug

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

* support answer only loss

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* account for padding in cu_seqlens during dataloading for attn kernel

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

* fix path for answer_only_loss = false

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

* @vysarge
Modify GPTSFTPackedDataset to respond to pad_to_max_length setting

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

* add unit test

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

* fix loss mask bug for answer_only_loss=False

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: Chen Cui <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric Harper <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants