-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alexandros Koumparoulis <[email protected]>
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 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
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, | ||
) |