Skip to navigation

nemo_gym.client.server_client

View as Markdown

ServerClient, which finds Gym servers through the head server and calls them, and server URLs.

Module Contents

Classes

NameDescription
ServerClient-

Functions

NameDescription
_connectable_client_hostReturn a connectable client host for a server bind address.
apply_rollout_prefixAppend the rollout prefix and, while traces export, the current span’s trace context to a model-server root URL.
get_server_url-
rollout_path_prefixReturn the leading model-server path prefix for a rollout, if available.
setup_server_client-
trace_context_path_segmentReturn /ng-trace/<traceparent> for the current span, or "" while traces are off or no span is current.

Data

NEMO_GYM_MODEL_SERVER_BASE_URL_ENV_VAR_NAME

NEMO_GYM_MODEL_SERVER_NAME_ENV_VAR_NAME

SESSION_ID_KEY

ServerStatus

_TRACEPARENT_PATTERN

logger

API

class nemo_gym.client.server_client.ServerClient()

Bases: BaseModel

_checkpoint_enabled
Optional[bool] = PrivateAttr(default=None)
_server_base_urls
dict[str, str] = PrivateAttr(default_factory=dict)
global_config_dict
DictConfig
head_server_config
BaseServerConfig
model_config
= ConfigDict(arbitrary_types_allowed=True)
nemo_gym.client.server_client.ServerClient._build_server_base_url(
server_config_dict: omegaconf.OmegaConf
) -> str
nemo_gym.client.server_client.ServerClient._client_host(
host: str
) -> str
staticmethod

Return a connectable host for a server bind address.

Wildcard addresses are valid for binding a server but are not valid advertised client targets. In particular, proxy-aware HTTP clients can route 0.0.0.0 through an external proxy instead of reaching the local server.

nemo_gym.client.server_client.ServerClient._resolve_base_url(
server_name: str
) -> str
nemo_gym.client.server_client.ServerClient.assistant_message_header(
model_server_name: str
) -> bytes | None

Read the optional header property of harnesses using this model server.

The property lives on the harness package so model workers need not import an agent’s app or install its runtime dependencies.

nemo_gym.client.server_client.ServerClient.checkpoint_enabled() -> bool

Return whether the global checkpoint: block enables partial-rollout checkpointing.

nemo_gym.client.server_client.ServerClient.get(
server_name: str,
url_path: str,
kwargs: typing.Unpack[aiohttp.client._RequestOptions] = {}
) -> aiohttp.ClientResponse
async

Args: server_name: str The name of the server you are trying to call. url_path: str The URL path in the server you are trying to call e.g. “/v1/responses”.

classmethod

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.

nemo_gym.client.server_client.ServerClient.load_head_server_config() -> nemo_gym.config.config_types.BaseServerConfig
classmethod
nemo_gym.client.server_client.ServerClient.model_post_init(
context: typing.Any
) -> None
nemo_gym.client.server_client.ServerClient.poll_for_status(
server_name: str,
timeout_seconds: float = 5
nemo_gym.client.server_client.ServerClient.post(
server_name: str,
url_path: str,
kwargs: typing.Unpack[aiohttp.client._RequestOptions] = {}
) -> aiohttp.ClientResponse
async

Args: server_name: str The name of the server you are trying to call. url_path: str The URL path in the server you are trying to call e.g. “/v1/responses”.

nemo_gym.client.server_client.ServerClient.request(
server_name: str,
url_path: str,
method: str,
_control: bool = False,
_resend_after_disconnect: bool = True,
kwargs: typing.Unpack[aiohttp.client._RequestOptions] = {}
) -> aiohttp.ClientResponse
async

Call another server. _control sends the call over the reserved control pool.

nemo_gym.client.server_client._connectable_client_host(
host: str
) -> str

Return a connectable client host for a server bind address.

nemo_gym.client.server_client.apply_rollout_prefix(
base_url: str,
rollout_id: typing.Optional[str],
token_capture: bool = False,
trace_context: bool = True
) -> str

Append the rollout prefix and, while traces export, the current span’s trace context to a model-server root URL.

Every caller hands the result to a client Gym does not instrument (a harness in a sandbox, a third-party client library), which is why the trace context travels in the URL here; Gym’s own clients send the traceparent header instead and use url_path_for_run.

The span named is the one current when the URL is built, so pass trace_context=False for a URL that is built once and reused across rollouts (a cached client): otherwise every later rollout’s calls would be parented to the first one’s span.

nemo_gym.client.server_client.get_server_url(
server_name: str
) -> str
nemo_gym.client.server_client.rollout_path_prefix(
rollout_id: typing.Optional[str],
token_capture: bool = False
) -> str

Return the leading model-server path prefix for a rollout, if available.

nemo_gym.client.server_client.setup_server_client(
head_server_config: typing.Optional[nemo_gym.config.config_types.BaseServerConfig] = None
nemo_gym.client.server_client.trace_context_path_segment() -> str

Return /ng-trace/<traceparent> for the current span, or "" while traces are off or no span is current.

TraceContextPathMiddleware on the receiving Gym server turns it back into the header.

nemo_gym.client.server_client.NEMO_GYM_MODEL_SERVER_BASE_URL_ENV_VAR_NAME = 'NEMO_GYM_MODEL_SERVER_BASE_URL'
nemo_gym.client.server_client.NEMO_GYM_MODEL_SERVER_NAME_ENV_VAR_NAME = 'NEMO_GYM_MODEL_SERVER_NAME'
nemo_gym.client.server_client.SESSION_ID_KEY = 'session_id'
nemo_gym.client.server_client.ServerStatus = Union[Literal['success'], Literal['connection_error'], Literal['timeout'], Liter...
nemo_gym.client.server_client._TRACEPARENT_PATTERN = '00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}'
nemo_gym.client.server_client.logger = logging.getLogger(__name__)