This section describes how NeMo Gym components interact during startup and execution. For an overview of the three server types (Model, Resources, Agent), see core-components.
When you run ng_run, the system starts up in four phases:
The ng_run command uses Hydra to parse command-line arguments. Users specify configuration files via +config_paths:
Configuration is loaded from multiple sources in order of priority (later sources override earlier):
config_pathsenv.yaml file (for sensitive values like API keys)Port allocation: Users can explicitly specify host and port in their config. If not provided, the framework automatically allocates ports from available system ports, tracking used ports to prevent conflicts.
The system initializes a Ray cluster for distributed coordination. If ray_head_node_address is specified in the config, it connects to an existing cluster; otherwise, it starts a new one.
Servers are started in two stages:
Head Server: Started as a background thread in the main process. Provides endpoints for config discovery (/global_config_dict_yaml) and server instance listing (/server_instances).
Server Subprocesses: Each configured server is spawned as an independent OS process:
http://{host}:{port}.NEMO_GYM_CONFIG_DICT.NEMO_GYM_CONFIG_PATH.Health Check: The main process polls each server’s HTTP endpoint until all return 200, then reports “All servers ready!”
Once all servers are healthy, the system enters steady state:
When the user presses Ctrl+C (or the process receives SIGINT):
During a single rollout, servers communicate via HTTP. This example shows a math problem with tool use:
Key Design Points:
/v1/responses endpoints compatible with the OpenAI Responses APIWhen you run ng_collect_rollouts, the system collects training data by executing rollouts in parallel:
The client first queries the Head Server to discover server addresses from the global config, then reads input JSONL and dispatches prompts to the Agent. Completed rollouts are written to output JSONL.
Concurrency behavior differs by use case:
ng_collect_rollouts): A semaphore gates concurrency via num_samples_in_parallel to control load.