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

[NeMo-UX] Adding recipes #9720

Merged
merged 27 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9aeb7ce
Adding recipy proposal
marcromeyn Jul 12, 2024
648a12b
Adding more recipies
marcromeyn Jul 12, 2024
6c8d933
Apply isort and black reformatting
artbataev Jul 12, 2024
bd6ccaa
Remove api.py inside llm.gpt.model
marcromeyn Jul 12, 2024
90b02ac
Adding resume to FineTuneRecipy
marcromeyn Jul 12, 2024
3b18c83
Fix spelling error
marcromeyn Jul 12, 2024
27ab061
Fix spelling error
marcromeyn Jul 12, 2024
175d00e
Fix spelling error
marcromeyn Jul 12, 2024
888f87f
Apply isort and black reformatting
marcromeyn Jul 12, 2024
c7a200b
Adding resume to PreTrainRecipe
marcromeyn Jul 12, 2024
8f25855
update recipe proposal to use sdk.Partial
ashors1 Jul 17, 2024
ff9e011
Apply isort and black reformatting
ashors1 Jul 17, 2024
e6716cf
update __init__
ashors1 Jul 17, 2024
04ff16c
update __init__
ashors1 Jul 17, 2024
0147133
fix return type
ashors1 Jul 17, 2024
71e36fb
Fix bug in factory
hemildesai Jul 17, 2024
0be29ac
rename recipe folder to 'models'
ashors1 Jul 18, 2024
d1571cf
Fixes
hemildesai Jul 18, 2024
ad97b1b
Apply isort and black reformatting
hemildesai Jul 18, 2024
3d63241
Bug fixes
hemildesai Jul 18, 2024
79087a1
rename models --> configs
ashors1 Jul 19, 2024
d5898de
Apply isort and black reformatting
ashors1 Jul 19, 2024
e87aa69
rename configs --> recipes
ashors1 Jul 20, 2024
fddc03f
Apply isort and black reformatting
ashors1 Jul 20, 2024
c37143f
address comments
ashors1 Jul 20, 2024
dacafc2
Merge branch 'nemo-ux/llm-factories' of github.com:NVIDIA/NeMo into n…
ashors1 Jul 20, 2024
83df7d4
Merge branch 'r2.0.0rc1' of github.com:NVIDIA/NeMo into nemo-ux/llm-f…
ashors1 Jul 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 1 addition & 34 deletions nemo/collections/llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,7 @@
gpt_data_step,
gpt_forward_step,
)
from nemo.collections.llm.gpt.model.api import (
code_gemma_2b,
code_gemma_7b,
code_llama_7b,
code_llama_13b,
code_llama_34b,
code_llama_70b,
gemma,
gemma_2b,
gemma_7b,
llama2_7b,
llama2_13b,
llama2_70b,
llama3_8b,
llama3_70b,
mistral,
mixtral,
)
from nemo.collections.llm.recipes import * # noqa

__all__ = [
"MockDataModule",
Expand Down Expand Up @@ -103,21 +86,5 @@
"mock",
"squad",
"dolly",
"mistral",
"mixtral",
"llama2_7b",
"llama3_8b",
"llama2_13b",
"llama2_70b",
"llama3_70b",
"code_llama_7b",
"code_llama_13b",
"code_llama_34b",
"code_llama_70b",
"gemma",
"gemma_2b",
"gemma_7b",
"code_gemma_2b",
"code_gemma_7b",
"peft",
]
125 changes: 0 additions & 125 deletions nemo/collections/llm/gpt/model/api.py

This file was deleted.

13 changes: 13 additions & 0 deletions nemo/collections/llm/recipes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from nemo.collections.llm.recipes import llama2_7b, llama3_8b, llama3_8b_16k, llama3_8b_64k, mistral
from nemo.collections.llm.recipes.log.default import default_log
from nemo.collections.llm.recipes.optim import adam

__all__ = [
"llama3_8b",
"llama3_8b_16k",
"llama3_8b_64k",
"llama2_7b",
"mistral",
"adam",
"default_log",
]
61 changes: 61 additions & 0 deletions nemo/collections/llm/recipes/llama2_7b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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 Llama2Config7B, LlamaModel
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 = "llama2_7b"


@factory(name=NAME)
def model() -> pl.LightningModule:
return LlamaModel(Llama2Config7B())


@factory(name=NAME)
def trainer(devices=8) -> nl.Trainer:
strategy = nl.MegatronStrategy(tensor_model_parallel_size=2)

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://meta-llama/Llama-2-7b-hf")


@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,
)
61 changes: 61 additions & 0 deletions nemo/collections/llm/recipes/llama3_8b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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 Llama3Config8B, LlamaModel
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 = "llama3_8b"


@factory(name=NAME)
def model() -> pl.LightningModule:
return LlamaModel(Llama3Config8B(seq_length=16384))


@factory(name=NAME)
def trainer(devices=8) -> nl.Trainer:
strategy = nl.MegatronStrategy(tensor_model_parallel_size=2)

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://meta-llama/Meta-Llama-3-8B")


@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,
)
45 changes: 45 additions & 0 deletions nemo/collections/llm/recipes/llama3_8b_16k.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytorch_lightning as pl

from nemo import lightning as nl
from nemo.collections.llm.api import pretrain
from nemo.collections.llm.gpt.data.api import squad
from nemo.collections.llm.gpt.model.llama import Llama3Config8B, LlamaModel
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 = "llama3_8b_16k"


@factory(name=NAME)
def model() -> pl.LightningModule:
return LlamaModel(Llama3Config8B(seq_length=16384))


@factory(name=NAME)
def trainer(devices=8) -> nl.Trainer:
strategy = nl.MegatronStrategy(
tensor_model_parallel_size=4,
context_parallel_size=2,
sequence_parallel=True,
)

return nl.Trainer(
devices=devices,
max_steps=100,
accelerator="gpu",
strategy=strategy,
plugins=nl.MegatronMixedPrecision(precision="bf16-mixed"),
)


@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,
)
Loading
Loading