-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Disable checkpoint conversion inside AutoResume #10645
Open
hemildesai
wants to merge
7
commits into
main
Choose a base branch
from
hemil/revamp-finetuning-recipes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+239
−106
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8b29797
Disable checkpoint conversion inside AutoResume
hemildesai b8dfe04
Apply isort and black reformatting
hemildesai ee4af52
Update resume docstrings
hemildesai a896007
fix
hemildesai 57c1e60
add default finetuning recipe and refactor llama3 8b recipe
cuichenx 51c0b5f
Apply isort and black reformatting
cuichenx d9bd80d
address comment
cuichenx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,116 @@ | ||
from typing import Optional | ||
import nemo_run as run | ||
import nemo.lightning as nl | ||
import pytorch_lightning as pl | ||
from nemo.collections.llm.recipes.log.default import tensorboard_logger | ||
from nemo.collections.llm.recipes.optim.adam import distributed_fused_adam_with_cosine_annealing | ||
from nemo.collections.llm.recipes.precision.mixed_precision import bf16_mixed | ||
from nemo.collections import llm | ||
|
||
def default_finetune_recipe( | ||
model: run.Config[pl.LightningModule], | ||
resume_path: str, | ||
dir: Optional[str] = None, | ||
name: str = "default", | ||
num_nodes: int = 1, | ||
num_gpus_per_node: int = 8, | ||
) -> run.Partial: | ||
""" | ||
Create a default fine-tuning recipe for any model. | ||
|
||
This function sets up a template for a complete configuration for fine-tuning, including | ||
model, trainer, data, logging, optimization, and resumption settings. | ||
|
||
Args: | ||
model (run.Config[pl.LightningModule]): Configuration for a NeMo model. | ||
resume_path (str): Path to the Huggingface model. | ||
dir (Optional[str]): Directory for saving logs and checkpoints. | ||
name (str): Name of the fine-tuning run. | ||
num_nodes (int): Number of compute nodes to use. | ||
num_gpus_per_node (int): Number of GPUs per node. | ||
|
||
Returns: | ||
run.Partial: Partial configuration for fine-tuning. | ||
|
||
See usages of this recipe for further details. | ||
""" | ||
recipe = run.Partial( | ||
llm.finetune, | ||
model=model, | ||
trainer=default_finetune_trainer( | ||
num_nodes=num_nodes, | ||
num_gpus_per_node=num_gpus_per_node, | ||
), | ||
data=run.Config(llm.SquadDataModule, seq_length=2048, global_batch_size=128, micro_batch_size=1), | ||
log=llm.default_log(dir=dir, name=name, tensorboard_logger=tensorboard_logger(name=name)), | ||
optim=distributed_fused_adam_with_cosine_annealing(max_lr=1e-4, min_lr=0, warmup_steps=50), | ||
resume=nemo_resume(resume_path), | ||
) | ||
|
||
return recipe | ||
|
||
|
||
def default_finetune_trainer( | ||
tensor_parallelism=1, | ||
pipeline_parallelism=1, | ||
pipeline_parallelism_type=None, | ||
virtual_pipeline_parallelism=None, | ||
context_parallelism=1, | ||
sequence_parallelism=False, | ||
num_nodes=1, | ||
num_gpus_per_node=8, | ||
max_steps=1000, | ||
limit_test_batches=None, | ||
limit_val_batches=None, | ||
val_check_interval=5, | ||
): | ||
strategy = run.Config( | ||
nl.MegatronStrategy, | ||
tensor_model_parallel_size=tensor_parallelism, | ||
pipeline_model_parallel_size=pipeline_parallelism, | ||
pipeline_dtype=pipeline_parallelism_type, | ||
virtual_pipeline_model_parallel_size=virtual_pipeline_parallelism, | ||
context_parallel_size=context_parallelism, | ||
sequence_parallel=sequence_parallelism, | ||
gradient_as_bucket_view=True, | ||
) | ||
|
||
trainer = run.Config( | ||
nl.Trainer, | ||
accelerator="gpu", | ||
accumulate_grad_batches=1, | ||
devices=num_gpus_per_node, | ||
limit_test_batches=limit_test_batches, | ||
limit_val_batches=limit_val_batches, | ||
log_every_n_steps=10, | ||
max_steps=max_steps, | ||
num_nodes=num_nodes, | ||
plugins=bf16_mixed(), | ||
strategy=strategy, | ||
use_distributed_sampler=False, | ||
val_check_interval=val_check_interval, | ||
) | ||
|
||
return trainer | ||
|
||
|
||
def nemo_resume(model_id: str) -> run.Config[nl.AutoResume]: | ||
""" | ||
Configure automatic resumption from a NeMo checkpoint converted from Huggingface for https://huggingface.co/{model_id}. | ||
|
||
This NeMo checkpoint should be converted from Huggingface beforehand, using nemo.collections.llm.import_ckpt. | ||
When converting the checkpoint, the NeMo checkpoint will be saved in NEMO_HOME (set to ~/.cache/nemo by default). | ||
|
||
This function sets up the configuration to resume training from path nemo://{model_id}. | ||
This translates to the full path {NEMO_HOME}/models/{model_id}. | ||
|
||
Args: | ||
model_id (str): The Huggingface model to resume. | ||
|
||
Returns: | ||
run.Config[nl.AutoResume]: Configuration for resuming from NeMo checkpoint. | ||
""" | ||
return run.Config( | ||
nl.AutoResume, | ||
restore_config=run.Config(nl.RestoreConfig, path=f"nemo://{model_id}"), | ||
) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a check to only use this if it's PEFT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the comment, revised!