API Reference
Auto-generated reference documentation for the nemo_gym Python package.
This reference is built from docstrings in the source code. Browse the sidebar to explore modules, classes, and functions.
Repository Layout
The nemo_gym Package
nemo_gym is split into packages, each with one job. The packages form layers: a package builds only on packages below it, so lower packages never depend on higher ones.
Read the diagram top to bottom, and left to right within a group: each package may use any package after it, and none before it.
nemo_gym.verifiers sits outside the layers. It runs inside a Harbor task’s verifier sandbox, so it uses only the standard library.
Servers, benchmarks, and other code outside nemo_gym/ import from the package, such as from nemo_gym.server_runtime import ..., rather than from the modules inside it.
Old Import Paths
Modules that moved when nemo_gym was split into packages keep their old import paths, such as nemo_gym.server_utils, until release 0.10.0. Each use of an old path emits a DeprecationWarning that names the new one. To update your code, run python scripts/migrate_imports.py <path> from a Gym checkout.
Planning and running single tasks in-process
To run a benchmark task by task from Python, plan it once with plan_benchmark, then run each task through
TaskRunner.run_task against Gym servers that are already running:
plan_benchmark builds the same plan as gym eval plan and collates the benchmark’s rows. It reads no
command-line arguments and does not set Gym’s process-wide configuration, so a long-lived process can call it.
Start the servers with gym env start --benchmark NAME first. The registry server is the server that serves the
run’s config and the other servers’ addresses.
What is experimental
Import everything from nemo_gym.environment: plan_benchmark, serve_benchmark, TaskRunner, PlannedBenchmark,
RolloutOutcome, TaskFailure and EvalPlan. The error type is nemo_gym.config.ConfigError.
This API is experimental: signatures, result fields and behavior may change or be removed without a deprecation
period. plan_benchmark, serve_benchmark, TaskRunner and run_task warn on stderr the first time they are used
in a process. A test pins the current names and fields so that a change is deliberate.
run_task runs one rollout of a task and returns its typed RolloutOutcome:
rewardis None when no reward exists, as for a failed/run.failureis aTaskFailurewhen a failure was reported.maskedis True when the verifier says the reward is not a valid measurement of the evaluated system, such as a lost session (it reports a reward of 0 and masks it). The outcome keeps that reward, so a caller that computes scores must leave masked rollouts out. A failed/runhas no sample, so itsmaskedis False and itsrewardis None.promptandoutputareresponses_create_params.inputandresponse.outputas JSON text, for display. They are None for a result without that shape, such as a native episode result.
A failed /run (a client error, a bad JSON body, a timeout or an unusable reply) does not raise: the outcome has a
failure and no reward. A connection that was refused is resent for a minute and one that dropped is sent twice, as
gym eval run does. Any other exception, such as a programming error, and cancellation propagate.
A failure reports what Gym observed and leaves the decision to you:
TaskRunner.run_task also counts the rollout in gym.rollout.completed_total: failed when the outcome has a failure
(labeled with its kind), otherwise scored when it has a reward and unscored when it has none. This is Gym’s record of
what the rollout returned; a caller may apply another rule to the same outcome. A result is a failure when it carries
failure_kind; a routing class alone does not make it one. A scored rollout with a finite reward is
also counted in gym.rollout.rewarded_total, masked rewards included. They are exported when telemetry is on in the
calling process: call nemo_gym.telemetry.setup.init_telemetry first.
RolloutOutcome.raw holds Gym’s raw /run response (the failure record for a failed /run). Its keys are not part
of the contract: depend on the other fields, and use raw for debugging.
Constraints
serve_benchmarksets the process’s Gym configuration, asgym env startdoes, so serve one benchmark per process.- Benchmark names resolve relative to the working directory,
NEMO_GYM_EXTRA_ROOTSand the install root. - Preparing a benchmark’s data and installing a server’s environment write beside their source, so the Gym checkout or install must be writable.
- To serve from another process, pass
registry_porttoserve_benchmarkand build theTaskRunnerwith the same port, for exampleBaseServerConfig(host="127.0.0.1", port=port).PlannedBenchmark.to_jsonandfrom_jsoncarry a plan between processes.