Skip to content

backend

backend

Run a trace on a remote nnsight-serve engine.

The backend for model.trace(..., serve=url). The trace is written against a meta model — no GPU, no weights — serialized in the same form the remote (NDIF) path uses, and sent to a running nnsight-serve instance. The server runs it and returns the saved values, which are pushed back into the caller's frame exactly as a local run would, so reading a .save()d value after the block just works::

model = VLLM("gpt2")                                       # no GPU needed
with model.trace("Hello", serve="http://host:8000", api_key="..."):
    logits = model.logits.save()
logits                                                     # pushed back here

api_key (optional) is sent as the ndif-api-key header. The server's response is a torch.save of {"saves": {name: value}, "error": <deferred or None>} — saved values only, so read generated tokens by saving tracer.result. A build or runtime error comes back as error and is re-raised at the client with its real type and traceback; a transport/service failure (e.g. the engine not ready) surfaces as ConnectionError.

LocalServeBackend

LocalServeBackend(model: Any, host: str, api_key: Optional[str] = None)

Bases: Backend

Send a trace to an nnsight-serve instance and bring its saves home.

model instance-attribute

model = model

host instance-attribute

host = host.rstrip('/')

api_key instance-attribute

api_key = api_key

__call__

__call__(tracer: 'Tracer') -> None