nemo_gym.server_utils
nemo_gym.server_utils
Module Contents
Classes
Functions
Data
DISCONNECTED_CLIENT_OS_HELP_TEXT
DISCONNECTED_CLIENT_OS_PRINT_INTERVAL
IS_NEMO_GYM_FASTAPI_ENTRYPOINT_KEY_NAME
IS_NEMO_GYM_FASTAPI_WORKER_KEY_NAME
_GLOBAL_AIOHTTP_CLIENT_REQUEST_DEBUG
_NUM_SERVER_DISCONNECTED_ERROR
_TELEMETRY_SERVER_TYPE_BY_BASE
API
Bases: BaseModel
All instances of BaseServer are queryable using ServerClient.
Bases: BaseModel
Bases: BaseServer
Clear the serialized global config cache.
Bases: ProfilingMiddlewareInputConfig
Bases: BaseModel
Bases: BaseModel
Parameters:
str The name of the server you are trying to call.
str The URL path in the server you are trying to call e.g. “/v1/responses”.
Build a client from the fully resolved global config.
Gym-launched server processes reuse the config injected by their parent. Other processes fetch the config from the head server.
Parameters:
str The name of the server you are trying to call.
str The URL path in the server you are trying to call e.g. “/v1/responses”.
Bases: BaseModel
Bases: BaseServer
Apply OTel FastAPI auto-instrumentation to app, if telemetry is exporting.
Gives every server the inbound half of context propagation plus dimensioned
http.server.* metrics, which is why Gym does not use nemo-lens’s undimensioned
gym.server.request_duration_ms (see nemo_gym/telemetry/metrics.py).
A server whose instrumentation could not be applied keeps serving; it just does not extract inbound trace context.
Initialise this process’s nemo-lens telemetry. Idempotent, once per process.
Every Gym server is its own process with its own providers — there is no parent
handle to inherit, only the NEMO_GYM_OTEL_* environment the orchestrator
exported before spawning it. A failure here is logged and swallowed: telemetry
must never stop a server from serving.
Bases: BaseModel
Bases: NamedTuple
Strip the query string from a URL before it becomes a span attribute.
Query strings in Gym carry API keys and, on rollout-prefixed routes, task content. The path is the useful part for a trace; the query is a leak waiting to happen.
Return the Gym server-type name for server_cls, or None if it is not one.
_request_with_retries wrapped in a CLIENT span, with traceparent injected.
Uses nemo_gym.telemetry.spans.client_span rather than nemo-lens’s managed_span
because the latter cannot set SpanKind — see that module for why an INTERNAL span
is wrong on a cross-service hop.
Injection happens inside the span so the header carries this span as the parent — the receiving server’s FastAPI instrumentation extracts it and its SERVER span becomes our child. That edge is what makes one rollout a single trace across three processes.
Retries reuse the same span rather than starting one per attempt: the caller asked for one logical request, and the retry count is recorded as an attribute instead.
Append a rollout prefix to a model-server root URL.
Initialize ray cluster in a process.
We store the Ray address in the global config dict so that child processes can connect to it.
This avoids the need to start a new Ray cluster in each child process.
Note: This function will modify the global config dict - update ray_head_node_address
Make an outbound HTTP call through Gym’s shared aiohttp client.
This is the only place Gym talks to another server, so it is also the only place
trace context has to be injected: every agent -> model and agent -> resources hop goes
through here. CLAUDE.md bans httpx precisely to keep it that way.
Return the leading model-server path prefix for a rollout, if available.