-
Notifications
You must be signed in to change notification settings - Fork 192
add support for nsys profile #667
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 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a9ab333
add support for nsys profile
wedu-nvidia 0ccc215
refractor logic
wedu-nvidia c78f1f7
Merge branch 'main' of github.com:NVIDIA/NeMo-Skills into wedu/nsys_p…
wedu-nvidia a70e02a
update nsys profiling for both sft and grpo
wedu-nvidia 7a1a8d0
update
wedu-nvidia 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 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 |
|---|---|---|
|
|
@@ -59,6 +59,8 @@ class NemoRLTask: | |
| log_dir: str | ||
| env_variables: dict | ||
| backend: str | ||
| nsys_profile: bool | ||
| profile_step_range: str | ||
| extra_arguments: str = "" | ||
|
|
||
| def format_train_args(self): | ||
|
|
@@ -94,20 +96,28 @@ def format_wandb_args(self): | |
|
|
||
| def get_cmd(self): | ||
| self.logging_params = self.format_wandb_args() | ||
|
|
||
| nsight_cmd = ( | ||
| f'export LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/cuda/lib:/usr/local/nvidia/lib64:/usr/local/nvidia/lib:/usr/lib/x86_64-linux-gnu" && ' | ||
| f"export NRL_NSYS_PROFILE_STEP_RANGE={self.profile_step_range} && " | ||
| 'export NRL_NSYS_WORKER_PATTERNS="*policy*,*vllm*" && ' | ||
| if self.nsys_profile is True | ||
| else "" | ||
| ) | ||
| cmd = ( | ||
| f"export PYTHONPATH=$PYTHONPATH:/nemo_run/code:/opt/NeMo-RL && " | ||
| f"export UV_PROJECT=/opt/NeMo-RL && " | ||
| f"echo 'Starting training' && " | ||
| f"NRL_FORCE_REBUILD_VENVS=true uv run --active python /nemo_run/code/nemo_skills/training/nemo_rl/start_sft.py " | ||
| f" {self.format_train_args()} " | ||
| f" {self.format_data_args()} " | ||
| f" {self.logging_params} " | ||
| f" {self.extra_arguments} " | ||
| "export PYTHONPATH=$PYTHONPATH:/nemo_run/code:/opt/NeMo-RL && " | ||
| "export UV_PROJECT=/opt/NeMo-RL && " | ||
| f"{nsight_cmd}" | ||
| "echo 'Starting training' && " | ||
| "NRL_FORCE_REBUILD_VENVS=true uv run --active " | ||
| "python /nemo_run/code/nemo_skills/training/nemo_rl/start_sft.py " | ||
| f"{self.format_train_args()} {self.format_data_args()} " | ||
| f"{self.logging_params} {self.extra_arguments}" | ||
| ) | ||
|
|
||
| return cmd | ||
|
|
||
|
|
||
|
|
||
| def get_training_cmd( | ||
| cluster_config, | ||
| partition, | ||
|
|
@@ -125,6 +135,8 @@ def get_training_cmd( | |
| log_dir, | ||
| env_variables, | ||
| backend, | ||
| nsys_profile, | ||
| profile_step_range, | ||
| ): | ||
| timeout = get_timeout(cluster_config, partition) | ||
|
|
||
|
|
@@ -144,6 +156,8 @@ def get_training_cmd( | |
| log_dir=log_dir, | ||
| env_variables=env_variables, | ||
| backend=backend, | ||
| nsys_profile=nsys_profile, | ||
| profile_step_range=profile_step_range, | ||
| ) | ||
|
|
||
| return task.get_cmd() | ||
|
|
@@ -197,6 +211,8 @@ def sft_nemo_rl( | |
| wandb_project: str = typer.Option("nemo-skills", help="Weights & Biases project name"), | ||
| wandb_group: str = typer.Option(None, help="Weights & Biases group name."), | ||
| disable_wandb: bool = typer.Option(False, help="Disable wandb logging"), | ||
| nsys_profile: bool = typer.Option(False, help="Profile GPU with Nsight Systems for selected Ray workers via env var matching."), | ||
| profile_step_range: str = typer.Option(None, help="Environment variable to control which training steps the profiler captures."), | ||
| partition: str = typer.Option( | ||
| None, help="Can specify if need interactive jobs or a specific non-default partition" | ||
| ), | ||
|
|
@@ -267,6 +283,22 @@ def sft_nemo_rl( | |
| ) | ||
| env_variables = get_env_variables(cluster_config) | ||
|
|
||
| if nsys_profile: | ||
| if "RAY_LOG_SYNC_FREQUENCY" not in env_variables: | ||
| raise typer.BadParameter( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't raise error, just add it directly to cluster config's env vars with a logic like this https://github.com/NVIDIA/NeMo-Skills/blob/main/nemo_skills/pipeline/utils/exp.py#L452 |
||
| "Nsight Systems profiling requires the 'RAY_LOG_SYNC_FREQUENCY' environment variable.\n" | ||
| 'Add it in your cluster config, e.g.: env_vars: ["RAY_LOG_SYNC_FREQUENCY=20"] ' | ||
| "(the FREQUENCY value controls how often logs are synced; 20 is usually a good choice)." | ||
| ) | ||
|
|
||
| if profile_step_range is None: | ||
| raise typer.BadParameter( | ||
| "Nsight Systems profiling requires 'profile_step_range'.\n" | ||
| "Format: START:STOP (1-indexed, STOP exclusive, same as slice syntax arr[start:stop]). " | ||
| "Example: '3:5' profiles steps 3 and 4 only. " | ||
| "NOTE: START must be ≥ 1, so '0:10' is invalid." | ||
| ) | ||
|
|
||
| if backend == "megatron": | ||
| if "HF_HOME" not in env_variables: | ||
| raise typer.BadParameter( | ||
|
|
@@ -301,6 +333,8 @@ def sft_nemo_rl( | |
| log_dir=f"{log_dir}/training-logs", | ||
| env_variables=env_variables, | ||
| backend=backend, | ||
| nsys_profile=nsys_profile, | ||
| profile_step_range=profile_step_range, | ||
| ) | ||
|
|
||
| server_config = None | ||
|
|
||
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.
we don't need this, let's just have one
nsys_step_rangeand if it's specified, we do profiling with that range