Skip to navigation

nemo_gym.orchestration.executors.script_templates

View as MarkdownOpen in Claude

Module Contents

Functions

NameDescription
bash_var-
escape_for_single_quoted_blockMake body safe to embed inside a single-quoted bash -c '...' block.
render_driver_entrypointRender the srun entrypoint for the driver step.
render_export_tailRender the part of the driver script that runs gym eval run, then each export of its rollouts.
render_gym_cmdRender a bash array with each argument on its own line.
render_health_checkhost is emitted verbatim so it may be a shell expansion: a service pinned to
render_ray_prelude-
render_repo_checkoutRender an &&-chained command that installs git if missing, then clones and checks out ref.
render_vllm_ray_symmetric_runRender the Ray head/worker bootstrap that wraps a single vLLM instance’s TP/PP command so
render_write_file_from_base64Render a command that reconstructs content at dest_path via a base64 round-trip.

Data

DRIVER_FAILURE_ENV

ENSURE_RAY_INSTALLED

EVAL_SUCCEEDED_MARKER_ENV

EXPORT_STEP_MODULE

RAY_SERVE_PROXY_PREFER_LOCAL_NODE_ROUTING

RAY_SERVE_QUEUE_LENGTH_RESPONSE_DEADLINE_S

RAY_SYMMETRIC_RUN_CLUSTER_WAIT_TIMEOUT_S

_DECLARED_EXTRAS_FILTER

_HEALTH_WAIT_MULTI

_RAY_PRELUDE

_VLLM_RAY_SYMMETRIC_RUN

API

nemo_gym.orchestration.executors.script_templates.bash_var(
name: str
) -> str
nemo_gym.orchestration.executors.script_templates.escape_for_single_quoted_block(
body: str
) -> str

Make body safe to embed inside a single-quoted bash -c '...' block.

POSIX shells do not nest single quotes: an inner quote ENDS the outer string rather than nesting in it. Every value that had to be quoted — a Hydra override containing a space, or any of the JSON blobs vLLM flags take (--hf-overrides '{"architectures":[...]}') — would otherwise break out of the block and word-split. Both failure modes have been observed on real submissions: Hydra rejecting +multistage.stages=[{num_tasks: on its own, and /usr/bin/env: Argument list too long from a multi-node vLLM command whose JSON flags reopened the quoting.

'"'"' is the standard end-quote / literal-quote / reopen-quote sequence. It leaves $VAR and $(( )) untouched, which matters: the inner shell is the one meant to expand them.

nemo_gym.orchestration.executors.script_templates.render_driver_entrypoint(
repo: str | None,
ref: str | None,
prepare_cmd: str | None,
command: str | None = None,
extras: tuple[str, ...] = (),
cleanup: bool = False,
record_install_failure: bool = False,
private_uv: bool = False,
export_tail: str | None = None
) -> str

Render the srun entrypoint for the driver step.

When either gym_install or prepare is needed, wraps everything in a single bash -c so prepare and run happen in the same srun step and container.

command replaces the gym eval run invocation for a benchmark whose harness is not Gym’s own runner. It is emitted verbatim, so it may be a multi-line script; everything before it (the install, and prepare) is unchanged.

extras are optional-dependency groups installed with the checkout; the server venvs Gym builds copy their telemetry packages from this process, so the driver is where telemetry has to be installed for any server to have it. ray is always added: gym needs Ray to start a server that declares ray_enabled = True. An extra the checkout does not define is dropped with a notice, since uv errors on it.

record_install_failure writes driver_install_failed to the file named by $GYM_DRIVER_FAILURE_FILE when the install exits with a failure status (1 to 128; a signal is not an install failure), for the guard of the next segment. It replaces the EXIT trap, so it cannot be combined with cleanup.

private_uv gives the install its own uv binary inside its temporary directory (a copy of a working uv, else a fresh install there), keeps uv’s cache on the host’s local disk in this user’s own directory only, and gives the install its own managed Pythons. Concurrent installs on other hosts replace the shared ~/.local/bin/uv and cache entries on a network home, and a uv running from those files then dies with SIGBUS.

cleanup removes the temporary checkout ($GYM_SRC) through an EXIT trap when the step exits.

export_tail (see render_export_tail) takes the place of exec "$@", so the exports run in the same step and container as the run, where gym is installed.

nemo_gym.orchestration.executors.script_templates.render_export_tail(
bench_dir: pathlib.Path,
exports: list[tuple[str, list[str]]]
) -> str

Render the part of the driver script that runs gym eval run, then each export of its rollouts.

exports pairs an exporter name with its shell-quoted override arguments for EXPORT_STEP_MODULE. The run is a child, not exec’d, so the script can go on to the exports; TERM, which is what the driver gets at the time limit, is passed on to it, so an interrupted run behaves as it did when it was exec’d. The run’s exit code goes to <bench_dir>/eval.exit and is the script’s exit code: the exports are reported in their own result files and cannot change it. They run only after a successful run, so a partial run is never exported, and an export that already succeeded is not repeated (the export step decides that from its result file).

nemo_gym.orchestration.executors.script_templates.render_gym_cmd(
subcommand: str,
var_name: str,
args: list[str]
) -> str

Render a bash array with each argument on its own line.

nemo_gym.orchestration.executors.script_templates.render_health_check(
name: str,
port: int,
path: str,
timeout: int,
host: str = 'localhost'
) -> str

host is emitted verbatim so it may be a shell expansion: a service pinned to a node pool answers on that pool’s head, not on the node running this script.

nemo_gym.orchestration.executors.script_templates.render_ray_prelude() -> str
nemo_gym.orchestration.executors.script_templates.render_repo_checkout(
repo: str,
ref: str,
dest: str | None = None
) -> str

Render an &&-chained command that installs git if missing, then clones and checks out ref.

dest is emitted verbatim so it may be a shell expression (the driver passes "$GYM_SRC/gym" to clone outside the job directory); omit it to clone into a directory named after the repo in the current one.

nemo_gym.orchestration.executors.script_templates.render_vllm_ray_symmetric_run(
inner_cmd: str,
total_nodes: int,
resource_flags: str
) -> str

Render the Ray head/worker bootstrap that wraps a single vLLM instance’s TP/PP command so it spans multiple Slurm nodes.

Uses ray symmetric-run when available (Ray >= 2.50), which starts/joins a Ray cluster across every task and runs the entrypoint only on the elected head node. Containers with an older Ray pin fall back to manually starting head/worker Ray processes, keyed on Slurm’s per-node task rank ($SLURM_NODEID).

nemo_gym.orchestration.executors.script_templates.render_write_file_from_base64(
content: str,
dest_path: str
) -> str

Render a command that reconstructs content at dest_path via a base64 round-trip.

nemo_gym.orchestration.executors.script_templates.DRIVER_FAILURE_ENV = 'GYM_DRIVER_FAILURE_FILE'
nemo_gym.orchestration.executors.script_templates.ENSURE_RAY_INSTALLED = 'command -v ray >/dev/null 2>&1 || pip install -q "ray[default,serve]==2.59.0"'
nemo_gym.orchestration.executors.script_templates.EVAL_SUCCEEDED_MARKER_ENV = 'GYM_EVAL_SUCCEEDED_MARKER'
nemo_gym.orchestration.executors.script_templates.EXPORT_STEP_MODULE = 'nemo_gym.orchestration.export_step'
nemo_gym.orchestration.executors.script_templates.RAY_SERVE_PROXY_PREFER_LOCAL_NODE_ROUTING = 0
nemo_gym.orchestration.executors.script_templates.RAY_SERVE_QUEUE_LENGTH_RESPONSE_DEADLINE_S = 1.0
nemo_gym.orchestration.executors.script_templates.RAY_SYMMETRIC_RUN_CLUSTER_WAIT_TIMEOUT_S = 600
nemo_gym.orchestration.executors.script_templates._DECLARED_EXTRAS_FILTER = 'import sys, tomllib\ndeclared = set(tomllib.load(open("pyproject.toml", "rb"))....
nemo_gym.orchestration.executors.script_templates._HEALTH_WAIT_MULTI = '# Wait for {name} (try multiple health endpoints)\necho "Waiting for {name} at ...
nemo_gym.orchestration.executors.script_templates._RAY_PRELUDE = '# Resolve the head node IP for multi-node vLLM services (spanning nodes via Ray...
nemo_gym.orchestration.executors.script_templates._VLLM_RAY_SYMMETRIC_RUN = "bash -lc '\n export RAY_SYMMETRIC_RUN_CLUSTER_WAIT_TIMEOUT=" + str(RAY_SYMME...