OpenViSTAI · Agents · Blockchain · Crypto
Menu
AI Developer Tools & SDKs

Surgeon Pytorch

Surgeon Pytorch is a Python library that lets developers inspect intermediate layers of PyTorch models and extract parts of their computation graphs without changing the original model code. Its `Inspect` wrapper returns selected layer outputs during a full model pass; `Extract` creates a model that returns specified graph nodes and can define new inputs for an extracted subpart.

Independent OpenViST project profile, based on linked sources.

Surgeon Pytorch — OpenViST project profile in AI Developer Tools & SDKs.
OpenViST project illustration. See the linked sources for product details.
Understand the project

Practical overview

When it fits

Use it when you need intermediate values or a separable graph subpart from a PyTorch model without editing the original model code.

Who it is for

  • Python developers debugging or analyzing PyTorch models
  • Researchers examining activations, embeddings, or attention-related outputs
  • Model developers applying losses to intermediate layers or working with extracted subparts

Documented uses

  • List named layers or graph nodes in a PyTorch model.
  • Read one or more intermediate layer outputs during a normal forward pass.
  • Return selected graph nodes through an extracted model.
  • Run or train a model subpart independently for debugging or experimentation.
Before you choose

Requirements & limits

The project is open source under the MIT license. The README documents installation with pip.

  • Inspect runs the entire model and returns selected layer outputs alongside its normal result.
  • Extract returns selected graph nodes from an extracted model and can specify new input nodes.
  • The documented default extraction tracer is PyTorch FX’s torch.fx.Tracer.
  • Changing an input node may not remove other dependencies; the extracted model’s summary shows required inputs and outputs.

Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.

Source-based practical guide

Inspect selected outputs during a model pass

Return one or more intermediate layer outputs alongside a PyTorch model’s normal output.

Before you start

  • Python environment with PyTorch installed
  • A PyTorch model and its layer names

Steps

  1. Install the package with the command below.

    Documented command
    pip install surgeon-pytorch
  2. Use get_layers(model) to list the model’s layers.

  3. Wrap the model with Inspect(model, layer='layer_name'), or pass a list of layer names.

  4. Call the wrapped model with an input; it returns the model result and the selected layer output or outputs.

Expected outcome

The forward call provides the original model output together with selected intermediate activations.

Guide limitations

  • Inspect executes the entire model on each forward call.
  • The README’s examples assume the requested layer names are present in the model.
Source-based practical guide

Extract a graph node as a model output

Create a model that returns a selected intermediate graph node.

Before you start

  • Python environment with PyTorch installed
  • A PyTorch model whose computation graph can be traced

Steps

  1. Install the package with the command below.

    Documented command
    pip install surgeon-pytorch
  2. Use get_nodes(model) to list intermediate graph nodes.

  3. Create an extracted model with Extract(model, node_out='node_name').

  4. Pass an input to the extracted model to obtain the selected node’s output.

Expected outcome

The extracted model returns the requested intermediate node output.

Guide limitations

  • The documented default tracer is torch.fx.Tracer.
  • Changing an input node may leave other dependencies on earlier inputs; inspect model_ext.summary to see required inputs and outputs.
Evidence and transparency

Sources & review

Source record details
Source availability
Active
Sources checked
16 October 2026
Original website title
archinetai/surgeon-pytorch · Official homepage title · retained in its source language