-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add SlurmRay launcher and transform API for launchers #159
Open
hemildesai
wants to merge
1
commit into
main
Choose a base branch
from
hemil/ray-launcher
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.
Open
Changes from all commits
Commits
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import os | ||
from dataclasses import dataclass, field | ||
from typing import Optional, Type | ||
|
||
from nemo_run.config import ConfigurableMixin, Script | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class Launcher(ConfigurableMixin): | ||
nsys_profile: bool = False | ||
nsys_folder: str = "nsys_profile" | ||
nsys_trace: list[str] = field(default_factory=lambda: ["nvtx", "cuda"]) | ||
|
||
def get_nsys_prefix(self, profile_dir: str) -> Optional[list[str]]: | ||
"""Make a command prefix for nsys profiling""" | ||
if self.nsys_profile: | ||
profile_out_path = os.path.join(profile_dir, self.nsys_folder) | ||
args = [ | ||
"profile", | ||
"-s", | ||
"none", | ||
"-t", | ||
",".join(self.nsys_trace), | ||
"-o", | ||
f"{profile_out_path}/profile_%p", | ||
"--force-overwrite", | ||
"true", | ||
"--capture-range=cudaProfilerApi", | ||
"--capture-range-end=stop", | ||
"--cuda-graph-trace=node", | ||
] | ||
return args | ||
|
||
def transform(self, cmd: list[str]) -> Optional[Script]: ... | ||
Check notice Code scanning / CodeQL Statement has no effect Note
This statement has no effect.
|
||
|
||
|
||
@dataclass(kw_only=True) | ||
class Torchrun(Launcher): | ||
rdzv_backend: str = "c10d" | ||
rdzv_port: int = 29500 | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class FaultTolerance(Launcher): | ||
cfg_path: str = "" | ||
finished_flag_file: str = "" | ||
job_results_file: str = "" | ||
rdzv_backend: str = "c10d" | ||
rdzv_port: int = 29500 | ||
workload_check_interval: Optional[float] = None | ||
initial_rank_heartbeat_timeout: Optional[float] = None | ||
rank_heartbeat_timeout: Optional[float] = None | ||
rank_termination_signal: Optional[str] = None | ||
log_level: Optional[str] = None | ||
max_restarts: Optional[int] = None | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class SlurmRay(Launcher): | ||
""" | ||
Transforms a provided cmd into a Ray launcher bash script for SlurmExecutor. | ||
The Ray launcher script sets up a Ray cluster on Slurm nodes, with the head node starting Ray head | ||
and executing the provided command. Worker nodes start Ray and wait. | ||
""" | ||
|
||
port: int = 6379 | ||
|
||
def transform(self, cmd: list[str]) -> Optional[Script]: | ||
""" | ||
Transforms the provided cmd into a Ray launcher bash script for SlurmExecutor. | ||
""" | ||
cmd_to_run = " ".join(cmd) | ||
# Build the Ray launcher bash script. Braces in shell variables are escaped as {{ and }} | ||
ray_script = f""" | ||
# Check that a command was provided. | ||
if [ "$#" -lt 1 ]; then | ||
echo "Usage: $0 <command>" | ||
exit 1 | ||
fi | ||
|
||
# Function to start the Ray head node. | ||
start_head() {{ | ||
echo "Starting Ray head node on ${{HEAD_IP}}" | ||
ray start --head --node-ip-address=${{HEAD_IP}} --port={self.port} | ||
export RAY_ADDRESS="${{HEAD_IP}}:{self.port}" | ||
}} | ||
|
||
# Function to start a Ray worker node. | ||
start_worker() {{ | ||
# Obtain the head node's hostname from the SLURM_NODELIST. | ||
echo "Starting Ray worker node. Connecting to head ${{HEAD_IP}}" | ||
ray start --address=${{HEAD_IP}}:{self.port} | ||
}} | ||
|
||
# If this is the head node, start the head; otherwise, start a worker. | ||
if [ -z "$SLURM_NODEID" ] || [ "$SLURM_NODEID" == "0" ]; then | ||
start_head | ||
else | ||
start_worker | ||
fi | ||
|
||
# Only the head node executes the command. | ||
if [ -z "$SLURM_NODEID" ] || [ "$SLURM_NODEID" == "0" ]; then | ||
echo "Running command: {cmd_to_run}" | ||
# Use eval so the given command is executed with its arguments. | ||
eval "{cmd_to_run}" | ||
echo "Command finished. Shutting down Ray on head node." | ||
ray stop | ||
# Optionally, you could touch a file to signal the worker nodes to shut down. | ||
fi | ||
|
||
# For worker nodes, simply wait so that Ray stays active. | ||
if [ -n "$SLURM_NODEID" ] && [ "$SLURM_NODEID" != "0" ]; then | ||
echo "Worker node running. Waiting for the Ray head to finish." | ||
while true; do | ||
sleep 15 | ||
done | ||
fi | ||
""" | ||
# Return a new Script object with the inline content | ||
return Script(inline=ray_script) | ||
|
||
|
||
LAUNCHER_MAP: dict[str, Type[Launcher]] = { | ||
"torchrun": Torchrun, | ||
"ft": FaultTolerance, | ||
"slurm_ray": SlurmRay, | ||
} |
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
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.
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.
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns Note