Skip to content

base

base

NNsight

NNsight(*args, **kwargs)

Bases: Envoy

Base NNsight wrapper around any torch.nn.Module.

Wraps a PyTorch module with NNsight's intervention capabilities, enabling access to and modification of intermediate activations during model execution via the tracing context.

This is the simplest entry point for wrapping arbitrary models. For HuggingFace language models, use :class:LanguageModel instead.

Example::

import torch
from nnsight import NNsight

net = torch.nn.Sequential(
    torch.nn.Linear(5, 10),
    torch.nn.Linear(10, 2),
)
model = NNsight(net)

with model.trace(torch.rand(1, 5)):
    hidden = model[0].output.save()
PARAMETER DESCRIPTION
*args

Positional arguments forwarded to :class:Envoy. The first argument should be a torch.nn.Module.

DEFAULT: ()

**kwargs

Keyword arguments forwarded to :class:Envoy.

DEFAULT: {}

__getstate__

__getstate__()

__setstate__

__setstate__(state)