-
Notifications
You must be signed in to change notification settings - Fork 368
feat: LoRA SFT support for DTensorV2 path #1556
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ddb5ae8
initial commit
samodi-nv 0d3ad49
fix: update model name and configuration in sft_lora.yaml; enhance de…
RayenTian 8ac528d
Deepcoyp of peft config.
joyang-nv a8a7829
remove debug code
RayenTian ac24ee9
add unit test and clean code
RayenTian e664749
refactor: update .pre-commit-config.yaml to enable minimize-check hoo…
RayenTian 3a5975e
remove unit test param
RayenTian 08e24f8
fix: update LoRA weight initialization method in DTensorPolicyWorkerV…
RayenTian 1cabb62
remove grpo related code
RayenTian 0e7e19c
feat: add LoRA configuration support for parameter-efficient fine-tun…
RayenTian 1321ac4
add thinking machine LoRA configuration for Llama 3.1 8B model; inclu…
RayenTian 097678a
Moved LoRA configuration
RayenTian 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
41 changes: 41 additions & 0 deletions
41
examples/configs/recipes/llm/sft-llama3.1-8b-1n8g-fsdp2tp1-lora.yaml.disabled
This file contains hidden or 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,41 @@ | ||
| defaults: ../../sft.yaml | ||
| sft: | ||
| max_num_steps: 350 | ||
| val_period: 20 | ||
| val_global_batch_size: 128 | ||
| val_micro_batch_size: 2 | ||
| checkpointing: | ||
| checkpoint_dir: results/sft-tmblog-llama3.1-8b | ||
| save_period: 20 | ||
| policy: | ||
| model_name: meta-llama/Llama-3.1-8B | ||
| tokenizer: | ||
| name: meta-llama/Llama-3.1-8B-Instruct | ||
| chat_template: default | ||
| dtensor_cfg: | ||
| lora_cfg: | ||
| enabled: true | ||
| dim: 128 | ||
| alpha: 128 | ||
| train_global_batch_size: 128 | ||
| max_total_sequence_length: 4096 | ||
| make_sequence_length_divisible_by: 2 | ||
| optimizer: | ||
| kwargs: | ||
| lr: 2.0e-05 | ||
| weight_decay: 0.01 | ||
| eps: 1.0e-08 | ||
| data: | ||
| dataset_name: tulu3 | ||
| add_generation_prompt: true | ||
| seed: 42 | ||
| logger: | ||
| log_dir: logs/sft-tmblog-llama3.1-8b | ||
| tensorboard_enabled: false | ||
| wandb: | ||
| project: nemo-rl | ||
| name: sft-tmblog-llama3.1-8b | ||
| tensorboard: | ||
| log_dir: tb_logs-sft-dev-tulu3 | ||
| cluster: | ||
| gpus_per_node: 8 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
| #!/bin/bash | ||
|
|
||
| # clean up checkpoint directory on exit | ||
| trap "rm -rf /tmp/lora_sft_checkpoints" EXIT | ||
|
|
||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) | ||
| PROJECT_ROOT=$(realpath $SCRIPT_DIR/../..) | ||
| # Mark the current repo as safe, since wandb fetches metadata about the repo | ||
| git config --global --add safe.directory $PROJECT_ROOT | ||
|
|
||
| set -eou pipefail | ||
|
|
||
| EXP_NAME=$(basename $0 .sh) | ||
| EXP_DIR=$SCRIPT_DIR/$EXP_NAME | ||
| LOG_DIR=$EXP_DIR/logs | ||
| JSON_METRICS=$EXP_DIR/metrics.json | ||
| RUN_LOG=$EXP_DIR/run.log | ||
| export PYTHONPATH=${PROJECT_ROOT}:${PYTHONPATH:-} | ||
|
|
||
| rm -rf $EXP_DIR $LOG_DIR | ||
| mkdir -p $EXP_DIR $LOG_DIR | ||
|
|
||
| cd $PROJECT_ROOT | ||
| uv run coverage run -a --data-file=$PROJECT_ROOT/tests/.coverage --source=$PROJECT_ROOT/nemo_rl \ | ||
| $PROJECT_ROOT/examples/run_sft.py \ | ||
| policy.model_name=Qwen/Qwen3-0.6B \ | ||
| cluster.gpus_per_node=2 \ | ||
| sft.max_num_steps=3 \ | ||
| sft.val_batches=1 \ | ||
| sft.val_period=3 \ | ||
| policy.dtensor_cfg.lora.enabled=true \ | ||
| logger.tensorboard_enabled=true \ | ||
| logger.log_dir=$LOG_DIR \ | ||
| logger.wandb_enabled=false \ | ||
| logger.monitor_gpus=true \ | ||
| checkpointing.enabled=true \ | ||
| checkpointing.save_period=3 \ | ||
| checkpointing.checkpoint_dir=/tmp/lora_sft_checkpoints \ | ||
| "$@" \ | ||
| 2>&1 | tee $RUN_LOG | ||
|
|
||
| uv run tests/json_dump_tb_logs.py $LOG_DIR --output_path $JSON_METRICS | ||
|
|
||
| uv run tests/check_metrics.py $JSON_METRICS \ | ||
| 'data["train/loss"]["3"] < 5.9' | ||
|
|
43 changes: 43 additions & 0 deletions
43
tests/test_suites/llm/sft-llama3.1-8b-1n8g-fsdp2tp1-lora.sh.disabled
This file contains hidden or 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,43 @@ | ||
| #!/bin/bash | ||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) | ||
| source $SCRIPT_DIR/common.env | ||
|
|
||
| # ===== BEGIN CONFIG ===== | ||
| NUM_NODES=1 | ||
| STEPS_PER_RUN=50 | ||
| MAX_STEPS=50 | ||
| NUM_RUNS=$(( (MAX_STEPS + STEPS_PER_RUN - 1) / STEPS_PER_RUN )) # Round up | ||
| NUM_MINUTES=30 | ||
| # ===== END CONFIG ===== | ||
|
|
||
| exit_if_max_steps_reached | ||
|
|
||
| # Run the experiment | ||
| cd $PROJECT_ROOT | ||
| uv run examples/run_sft.py \ | ||
| --config $CONFIG_PATH \ | ||
| sft.max_num_steps=$MAX_STEPS \ | ||
| logger.log_dir=$LOG_DIR \ | ||
| logger.wandb_enabled=True \ | ||
| logger.wandb.project=ruit_personal_debug \ | ||
| logger.wandb.name=$EXP_NAME \ | ||
| logger.monitor_gpus=True \ | ||
| logger.tensorboard_enabled=True \ | ||
| checkpointing.enabled=True \ | ||
| checkpointing.checkpoint_dir=$CKPT_DIR \ | ||
| $@ \ | ||
| 2>&1 | tee $RUN_LOG | ||
|
|
||
| # Convert tensorboard logs to json | ||
| uv run tests/json_dump_tb_logs.py $LOG_DIR --output_path $JSON_METRICS | ||
|
|
||
| # TODO: memory check will fail due to OOM tracked here https://github.com/NVIDIA-NeMo/RL/issues/263 | ||
|
|
||
| # Only run metrics if the target step is reached | ||
| if [[ $(jq 'to_entries | .[] | select(.key == "train/loss") | .value | keys | map(tonumber) | max' $JSON_METRICS) -ge $MAX_STEPS ]]; then | ||
| uv run tests/check_metrics.py $JSON_METRICS \ | ||
| 'data["train/loss"]["1"] < 1.0' \ | ||
| 'data["train/loss"]["50"] < 0.8' \ | ||
| 'max(data["ray/node.0.gpu.0.mem_gb"]) < 50' \ | ||
| 'mean(data["timing/train/total_step_time"], 2) < 10' | ||
| fi |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.