forked from NVIDIA/NeMo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nemo ux mixtral 8x22b config (NVIDIA#9977)
* nemo ux mixtral 8x22b config Signed-off-by: Alexandros Koumparoulis <[email protected]> * add mixtral 8x22b recipe Signed-off-by: Alexandros Koumparoulis <[email protected]> * add note Signed-off-by: Alexandros Koumparoulis <[email protected]> * fix type hint Signed-off-by: Alexandros Koumparoulis <[email protected]> * Apply isort and black reformatting Signed-off-by: akoumpa <[email protected]> * fix type hint Signed-off-by: Alexandros Koumparoulis <[email protected]> --------- Signed-off-by: Alexandros Koumparoulis <[email protected]> Signed-off-by: akoumpa <[email protected]> Co-authored-by: akoumpa <[email protected]> Signed-off-by: Hainan Xu <[email protected]>
- Loading branch information
1 parent
bc31182
commit b7bba47
Showing
4 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import pytorch_lightning as pl | ||
|
||
from nemo import lightning as nl | ||
from nemo.collections.llm.api import finetune, pretrain | ||
from nemo.collections.llm.gpt.data.api import squad | ||
from nemo.collections.llm.gpt.model.llama import MixtralConfig8x22B, MixtralModel | ||
from nemo.collections.llm.peft.api import gpt_lora | ||
from nemo.collections.llm.recipes.log.default import default_log | ||
from nemo.collections.llm.recipes.optim.adam import adam_with_cosine_annealing | ||
from nemo.collections.llm.utils import Partial, factory | ||
|
||
NAME = "mixtral_8x22b_4k" | ||
|
||
|
||
@factory(name=NAME) | ||
def model() -> pl.LightningModule: | ||
return MixtralModel(MixtralConfig8x22B(seq_length=4096)) | ||
|
||
|
||
@factory(name=NAME) | ||
def trainer(devices=8) -> nl.Trainer: | ||
strategy = nl.MegatronStrategy( | ||
tensor_model_parallel_size=8, | ||
sequence_parallel=True, | ||
) | ||
|
||
return nl.Trainer( | ||
devices=devices, | ||
max_steps=100, | ||
accelerator="gpu", | ||
strategy=strategy, | ||
plugins=nl.MegatronMixedPrecision(precision="bf16-mixed"), | ||
) | ||
|
||
|
||
@factory(name=NAME + "_hf") | ||
def hf_resume() -> nl.AutoResume: | ||
return nl.AutoResume(import_path="hf://mistralai/Mixtral-8x22B-v0.1") | ||
|
||
|
||
@factory(name=NAME, for_task="llm.pretrain") | ||
def pretrain_recipe() -> Partial: | ||
return Partial( | ||
pretrain, | ||
model=model, | ||
trainer=trainer, | ||
data=squad, | ||
log=default_log, | ||
optim=adam_with_cosine_annealing, | ||
) | ||
|
||
|
||
@factory(name=NAME, for_task="llm.finetune") | ||
def finetune_recipe() -> Partial: | ||
return Partial( | ||
finetune, | ||
model=model, | ||
trainer=trainer, | ||
data=squad, | ||
log=default_log, | ||
optim=adam_with_cosine_annealing, | ||
peft=gpt_lora, | ||
resume=hf_resume, | ||
) |