nemo_gym.server_runtime.base_server
nemo_gym.server_runtime.base_server
Module Contents
Classes
Functions
Data
_TELEMETRY_SERVER_TYPE_BY_BASE
API
Bases: BaseModel
All instances of BaseServer are queryable using ServerClient.
Bases: HttpToolsProtocol
Uvicorn’s httptools protocol with TCP keepalive on every accepted connection.
A model server answers only after generation finishes, so a client connection can carry no bytes for many
minutes. Stateful network hops on some paths evict flows that stay idle that long, which silently drops the
eventual reply and leaves the client waiting on a half-open connection. Keepalive probes keep the flow alive and
let the kernel reap peers that are really gone. Uses the same global_aiohttp_tcp_keepalive_* settings as the
outgoing client connections.
Handed to uvicorn as partial(KeepaliveHttpToolsProtocol, keepalive=(idle, interval, probes)): multi-worker
uvicorn pickles its config into worker processes, so this class must stay importable at module level.
The part of an httpx.Request the rollout-prefix hooks use: a URL whose type parses a string.
Bases: BaseServer
The reply for an exception the route did not handle.
Apply OTel FastAPI auto-instrumentation to app, if telemetry is exporting traces.
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).
The instrumentor costs tens of microseconds per request even when no span is exported, so a
metrics-only run skips it and does without the http.server.* metrics.
A server whose instrumentation could not be applied keeps serving; it just does not extract inbound trace context.
Why this server cannot run with num_workers > 1, or None when it can.
With several workers, uvicorn imports the entrypoint in each worker and serves its module-level app.
A server whose state or resources several workers cannot share overrides this and returns the reason,
and run_webserver refuses num_workers > 1 with it before uvicorn starts.
The reason reads as the end of the sentence “<server> needs num_workers=1: <reason>”.
It is a method rather than a class attribute so that a server can decide from its config.
Arguments to install_session_routing: where requests name their session, and how long ownership lasts.
A server that sets routes_sessions_to_owner implements it.
Take part in partial-rollout checkpoints on the app setup_webserver built, if it does not yet.
Called for every server, so a server whose setup_webserver builds its own app takes part too.
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 supervisor
exported before spawning it. A failure here is logged and swallowed: telemetry
must never stop a server from serving.
Bases: BaseModel
Bases: BaseModel
Bases: BaseModel
Bases: BaseModel
The index in path just past its first count non-empty segments; repeated slashes are kept as sent.
Return the Gym server-type name for server_cls, or None if it is not one.
Scheme, lowercased host, effective port and path segments, as HTTP clients normalize them.
An httpx.AsyncClient request event hook that applies with_rollout_prefix to every request.
Raise when the server asks for several workers but cannot run with them.
An httpx.Client request event hook that applies with_rollout_prefix to every request.
Insert /ng-rollout/<current rollout> after the matching base URL, for clients with a fixed base URL.
A long-lived client (for example one a resources server calls from verify()) keeps one base URL; this
rewrites each request URL instead, so the call reaches the Gym model server exactly like a prefixed one.
Only URLs under one of base_urls are changed, compared by scheme, host (case-insensitive), effective port
and whole path segments. A URL whose path below the base already carries a rollout prefix is left as it is.
Without a current rollout the URL is unchanged, and the model server forwards the call without capture.
The current rollout is a ContextVar: a synchronous client run through asyncio.to_thread or
contextvars.copy_context().run sees it, one run through loop.run_in_executor or a thread pool does not.