Nodes/ComfyUI QwenScope/Capture Residual
ComfyUI Node

Capture Residual

Capture Residual — raw hidden states for people who don't want the SAE in the way

By Nynxz·Created 4 months ago·Updated 4 months ago· 0
Capture Residual
  • model
  • hidden
  • info
prompt
layer12
templateraw

Capture Residual is the lower-level cousin of Analyze Prompt. Where Analyze runs the residual through an SAE and hands you interpretable features, this node just grabs the raw hidden state at one transformer layer and hands you the numbers. No SAE, no feature decoding, no visualizer wiring - just [seq_len, d_model] activations as a LATENT.

You'd reach for it for two reasons. Either you're doing your own analysis - you have a favorite probing method, a custom projection, or you just want to eyeball the residual for a specific token - or you're experimenting with custom direction vectors and want a capture path that doesn't force an SAE on you.

How it works

Mechanically it's the same trick as the other capture nodes: a forward hook registered on model.model.layers[layer] grabs the residual output after that layer during a single forward pass, then the hook is removed. It runs under torch.no_grad(), so it's cheap and doesn't burn gradient memory. The template input lets you wrap the prompt in Qwen's think/no-think ChatML form if you care about matching generation-time input shape.

Outputs: hidden is a LATENT holding the captured [seq, d_model] hidden state, and info reports the shape and layer. That LATENT type is a bit of a wink - QwenScope's own Residual Steer node accepts a LATENT direction input, so a captured residual can be turned straight into a steer plan if you want to build directions from actual model activations rather than SAE features.

The inputs

  • model - QSCOPE_MODEL from Load Qwen Model.
  • prompt - the text to run. (Nothing fires if it's empty; give it something to chew on.)
  • layer - which transformer layer to capture. Default 12 is middle-ish on small models; check your model's layer count.
  • template - raw / think / no_think.

Installing it

One pack, one install: ComfyUI Manager → search "ComfyUI QwenScope", or

cd ComfyUI/custom_nodes
git clone https://github.com/Nynxz/ComfyUI-QwenScope

restart. Dependencies are transformers, huggingface_hub, safetensors, Pillow, numpy - you almost certainly already have them. No SAE downloads happen here, since this node never touches one.

Common issues

The usual trap is forgetting this node doesn't produce features: its output is a LATENT, so don't wire it into Feature Heatmap or Top Features - those want QSCOPE_FEATURES. If you're capturing a multi-token prompt and then feeding the whole thing into Residual Steer, remember the direction gets flattened to a single vector, so you'll usually want a short, targeted prompt (or your own pooling) rather than a paragraph.

CategoryQwenScope/Capture

Inputs (4)

NameTypeDefaultDescription
modelQSCOPE_MODEL
promptSTRING
layerINT120–127
templateCOMBOraw3 options: raw, think, no_think

Outputs (2)

NameTypeDescription
hiddenLATENT
infoSTRING