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

Pipeline-parallel support for Knowledge Distillation (NeMo 2) #11766

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

AAnoosheh
Copy link
Collaborator

@AAnoosheh AAnoosheh commented Jan 6, 2025

What does this PR do ?

Enable Pipeline-Parallelism in conjunction with student-teacher distillation in NeMo 2

Collection: [LLM]

Changelog

  • Create new script to enable KD in NeMo 2
  • Add folder nemo/collections/llm/distillation
  • Modify the MegatronParallel forward pass to run teacher in addition to student

Usage

        python scripts/llm/gpt_distillation.py \
          --name experiment_name \
          --teacher_path /path/to/nemo2/teacher \
          --student_path /path/to/nemo2/student \
          --tp_size 4 \
          --cp_size 1 \
          --pp_size 2 \
          --devices 8 \
          --log_dir /tmp/nemo2_llama_distill \
          --max_steps 100 \
          --gbs 64 \
          --mbs 4 \
          --data_paths weight1 /path/to/data/1 weight2 /path/to/data/2 \
          --index_mapping_dir /path/to/data/cache/ \
          --seq_length 8192 \
          --warmup_steps 5 \
          --val_check_interval 50 \
          --log_interval 5

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)

nemo/lightning/megatron_parallel.py Fixed Show fixed Hide fixed
scripts/llm/gpt_distillation.py Fixed Show fixed Hide fixed
scripts/llm/gpt_distillation.py Fixed Show fixed Hide fixed
@AAnoosheh AAnoosheh force-pushed the aanoosheh/pp-distillation-nemo2 branch from 0ce6e7d to b748ae8 Compare January 14, 2025 18:55
nemo/lightning/megatron_parallel.py Dismissed Show dismissed Hide dismissed
scripts/llm/gpt_distillation.py Fixed Show fixed Hide fixed
nemo/collections/llm/distillation/model.py Dismissed Show dismissed Hide dismissed
nemo/collections/llm/distillation/model.py Dismissed Show dismissed Hide dismissed
@AAnoosheh AAnoosheh force-pushed the aanoosheh/pp-distillation-nemo2 branch from 1538557 to 19e4a3a Compare January 22, 2025 16:04
@github-actions github-actions bot added the CI label Jan 22, 2025
@AAnoosheh AAnoosheh marked this pull request as ready for review January 22, 2025 17:45
@AAnoosheh AAnoosheh force-pushed the aanoosheh/pp-distillation-nemo2 branch 2 times, most recently from 896e802 to ae95fa8 Compare January 23, 2025 15:00
@AAnoosheh AAnoosheh force-pushed the aanoosheh/pp-distillation-nemo2 branch from 7d980cb to 2bd6e40 Compare January 27, 2025 15:24
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
@AAnoosheh AAnoosheh force-pushed the aanoosheh/pp-distillation-nemo2 branch from 3539768 to 7f1e572 Compare January 29, 2025 16:19
Signed-off-by: Asha Anoosheh <[email protected]>
Signed-off-by: Asha Anoosheh <[email protected]>
Copy link
Contributor

beep boop 🤖: 🙏 The following files have warnings. In case you are familiar with these, please try helping us to improve the code base.


Your code was analyzed with PyLint. The following annotations have been identified:

************* Module nemo.collections.llm.gpt.model.base
nemo/collections/llm/gpt/model/base.py:240:0: C0301: Line too long (122/119) (line-too-long)
nemo/collections/llm/gpt/model/base.py:417:0: C0301: Line too long (126/119) (line-too-long)
nemo/collections/llm/gpt/model/base.py:51:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:94:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:115:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:126:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:134:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:142:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:152:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:162:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/base.py:187:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:266:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/base.py:278:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/base.py:290:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/base.py:302:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/base.py:314:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/base.py:326:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/base.py:340:0: C0115: Missing class docstring (missing-class-docstring)
nemo/collections/llm/gpt/model/base.py:358:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:362:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:385:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:388:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:391:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:395:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:400:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:431:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:438:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:445:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:473:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/gpt/model/base.py:43:4: W0611: Unused import fused_weight_gradient_mlp_cuda (unused-import)
************* Module nemo.lightning.megatron_parallel
nemo/lightning/megatron_parallel.py:260:0: C0301: Line too long (127/119) (line-too-long)
nemo/lightning/megatron_parallel.py:261:0: C0301: Line too long (140/119) (line-too-long)
nemo/lightning/megatron_parallel.py:262:0: C0301: Line too long (130/119) (line-too-long)
nemo/lightning/megatron_parallel.py:607:0: C0301: Line too long (129/119) (line-too-long)
nemo/lightning/megatron_parallel.py:614:0: C0301: Line too long (135/119) (line-too-long)
nemo/lightning/megatron_parallel.py:906:0: C0301: Line too long (137/119) (line-too-long)
nemo/lightning/megatron_parallel.py:1136:0: C0301: Line too long (136/119) (line-too-long)
nemo/lightning/megatron_parallel.py:1709:0: C0301: Line too long (128/119) (line-too-long)
nemo/lightning/megatron_parallel.py:1748:0: C0301: Line too long (146/119) (line-too-long)
nemo/lightning/megatron_parallel.py:71:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/megatron_parallel.py:72:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:74:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:109:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:113:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:366:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:390:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:416:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:442:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:578:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:622:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:626:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:692:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:727:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:733:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:739:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:746:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:753:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:757:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:791:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:799:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:815:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:842:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:854:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/megatron_parallel.py:876:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:1402:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:1577:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/megatron_parallel.py:1583:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:1589:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:1593:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:1598:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/megatron_parallel.py:1603:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/megatron_parallel.py:1631:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:1677:8: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:1699:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/megatron_parallel.py:1772:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/megatron_parallel.py:1818:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/megatron_parallel.py:1832:0: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.utils.model_utils
nemo/utils/model_utils.py:349:0: C0301: Line too long (145/119) (line-too-long)
nemo/utils/model_utils.py:443:0: C0301: Line too long (145/119) (line-too-long)
nemo/utils/model_utils.py:655:0: C0301: Line too long (127/119) (line-too-long)
nemo/utils/model_utils.py:699:0: C0301: Line too long (150/119) (line-too-long)
nemo/utils/model_utils.py:64:0: C0115: Missing class docstring (missing-class-docstring)
nemo/utils/model_utils.py:117:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/utils/model_utils.py:466:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/utils/model_utils.py:672:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/utils/model_utils.py:32:0: W0611: Unused resolve_cache_dir imported from nemo.utils.data_utils (unused-import)

-----------------------------------
Your code has been rated at 9.31/10

Mitigation guide:

  • Add sensible and useful docstrings to functions and methods
  • For trivial methods like getter/setters, consider adding # pylint: disable=C0116 inside the function itself
  • To disable multiple functions/methods at once, put a # pylint: disable=C0116 before the first and a # pylint: enable=C0116 after the last.

By applying these rules, we reduce the occurance of this message in future.

Thank you for improving NeMo's documentation!

Copy link
Collaborator

@ko3n1g ko3n1g left a comment

Choose a reason for hiding this comment

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

Makes sense, thanks!

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.

3 participants