Skip to content

Sweep and summarize

Everything a job saves is downloaded. Over a dataset, activations and logits add up to gigabytes, and the number you wanted from them is small. Compute that number on the server and save it.

The pattern

For each of 40 movie reviews, this session saves one number: the logit for " positive" minus the logit for " negative".

import nnsight
from nnsight import TransformersModel

model = TransformersModel("Qwen/Qwen3-8B")
pos = model.tokenizer.encode(" positive")[0]
neg = model.tokenizer.encode(" negative")[0]

with model.session(remote=True, verbose=True):
    from datasets import load_dataset

    rows = load_dataset("nyu-mll/glue", "sst2", split="validation[:40]")
    margins = nnsight.save([])

    for start in range(0, len(rows), 10):
        prompts = [f"Review: {s.strip()}\nSentiment:" for s in rows[start : start + 10]["sentence"]]
        with model.trace(prompts):
            logits = model.lm_head.output[:, -1]
            margins.extend((logits[:, pos] - logits[:, neg]).float().tolist())

print(len(margins), [round(m, 2) for m in margins[:5]])
# [remote] payload: 5,839 bytes (compressed)
# ...
# [remote] result: 602 bytes
# 40 [9.5, -2.25, 7.38, 4.38, -8.88]

verbose=True prints the size of the request and of the result. Both are a few kilobytes: the dataset never left the server, and 40 numbers came back.

The same sweep, saving the logits

Saving the last-token logits for the same 40 reviews returns a [40, 151936] tensor.

with model.session(remote=True, verbose=True):
    from datasets import load_dataset

    rows = load_dataset("nyu-mll/glue", "sst2", split="validation[:40]")
    saved = nnsight.save([])

    for start in range(0, len(rows), 10):
        prompts = [f"Review: {s.strip()}\nSentiment:" for s in rows[start : start + 10]["sentence"]]
        with model.trace(prompts):
            saved.append(model.lm_head.output[:, -1])
# [remote] payload: 5,829 bytes (compressed)
# ...
# [remote] result: 9,205,124 bytes

The same 40 reviews now cost a 9 MB download, and the size grows with every row.

Ways to reduce

You want Save
The predicted token logits[:, -1].argmax(-1)
How much the model prefers one answer The difference of two logits
A statistic of a layer hidden.norm(dim=-1), a mean, or a projection onto a direction
A probe's accuracy The count of correct predictions
Activations you do need One layer and one position, cast with .float().cpu()

When you need activations for many prompts, save them in chunks over several jobs (Long run with progress), so no single download is large.