From 0bb31754eb3f4faaddc28496d0547e69337a0987 Mon Sep 17 00:00:00 2001 From: Sitavi <80586127+Sitavi@users.noreply.github.com> Date: Mon, 29 Jun 2026 20:48:31 +0200 Subject: [PATCH 1/2] Support nnsight >= 0.6 in activation collection nnsight 0.6 reworked the tracing/.save() mechanism (mount-once, never unmount) and removed the proxy `.output.stop()` early-stop plus the scan/validate trace kwargs. - cache.py: capture the tracer (`with model.trace(...) as tracer:`) and call `tracer.stop()` instead of the removed `last_submodule.output.stop()`. - cache.py, buffer.py: drop the scan/validate trace kwargs (no-ops in 0.6). - pyproject: require nnsight>=0.6. ActivationCache.collect() output is unchanged: activations are bit-identical under nnsight 0.6.3 vs 0.5.15 (verified on a 3B model). --- dictionary_learning/buffer.py | 8 ++------ dictionary_learning/cache.py | 11 ++++------- pyproject.toml | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/dictionary_learning/buffer.py b/dictionary_learning/buffer.py index c4635c4..f27cfbe 100644 --- a/dictionary_learning/buffer.py +++ b/dictionary_learning/buffer.py @@ -3,12 +3,8 @@ import gc from tqdm import tqdm -from .config import DEBUG - -if DEBUG: - tracer_kwargs = {"scan": True, "validate": True} -else: - tracer_kwargs = {"scan": False, "validate": False} +# nnsight >= 0.6 removed the scan/validate trace kwargs (tracing is always lazy). +tracer_kwargs = {} class ActivationBuffer: diff --git a/dictionary_learning/cache.py b/dictionary_learning/cache.py index 81279e5..b5ecf25 100644 --- a/dictionary_learning/cache.py +++ b/dictionary_learning/cache.py @@ -10,17 +10,14 @@ from multiprocessing import Pool, Manager import time import json -from .config import DEBUG from .utils import ( dtype_to_str, str_to_dtype, torch_to_numpy_dtype, ) -if DEBUG: - tracer_kwargs = {"scan": True, "validate": True} -else: - tracer_kwargs = {"scan": False, "validate": False} +# nnsight >= 0.6 removed the scan/validate trace kwargs (tracing is always lazy). +tracer_kwargs = {} import torch from typing import Tuple @@ -640,7 +637,7 @@ def collect( with model.trace( tokens, **tracer_kwargs, - ): + ) as tracer: for i, submodule in enumerate(submodules): local_activations = ( ActivationCache.get_activations(submodule, io) @@ -650,7 +647,7 @@ def collect( activation_cache[i].append(local_activations) if last_submodule is not None: - last_submodule.output.stop() + tracer.stop() for i in range(len(submodules)): activation_cache[i][-1] = activation_cache[i][-1][ diff --git a/pyproject.toml b/pyproject.toml index 74f93fe..34de1de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ classifiers = [ ] dependencies = [ "torch", - "nnsight>=0.4,<0.6", + "nnsight>=0.6", "einops", "pytest", "datasets", From 18f94c742517807d1b8b384479a50159e1d0d7c6 Mon Sep 17 00:00:00 2001 From: Sitavi <80586127+Sitavi@users.noreply.github.com> Date: Thu, 2 Jul 2026 17:12:04 +0200 Subject: [PATCH 2/2] Remove now-dead tracer_kwargs from cache/buffer The scan/validate kwargs were dropped for nnsight 0.6, leaving tracer_kwargs as an empty dict splatted into .trace(). Remove it and the ** splats (cache.py, buffer.py). interp.py keeps its own (still uses invoker_args). --- dictionary_learning/buffer.py | 6 ------ dictionary_learning/cache.py | 4 ---- 2 files changed, 10 deletions(-) diff --git a/dictionary_learning/buffer.py b/dictionary_learning/buffer.py index f27cfbe..43401c0 100644 --- a/dictionary_learning/buffer.py +++ b/dictionary_learning/buffer.py @@ -3,9 +3,6 @@ import gc from tqdm import tqdm -# nnsight >= 0.6 removed the scan/validate trace kwargs (tracing is always lazy). -tracer_kwargs = {} - class ActivationBuffer: """ @@ -119,7 +116,6 @@ def refresh(self): with t.no_grad(): with self.model.trace( self.text_batch(), - **tracer_kwargs, invoker_args={"truncation": True, "max_length": self.ctx_len}, ): if self.io == "in": @@ -257,7 +253,6 @@ def refresh(self): with t.no_grad(): with self.model.trace( self.text_batch(), - **tracer_kwargs, invoker_args={"truncation": True, "max_length": self.ctx_len}, remote=self.remote, ): @@ -449,7 +444,6 @@ def refresh(self): with t.no_grad(), self.model.trace( self.token_batch(), - **tracer_kwargs, invoker_args={"truncation": True, "max_length": self.ctx_len}, ): if self.io in ["in", "in_and_out"]: diff --git a/dictionary_learning/cache.py b/dictionary_learning/cache.py index b5ecf25..e42fb80 100644 --- a/dictionary_learning/cache.py +++ b/dictionary_learning/cache.py @@ -16,9 +16,6 @@ torch_to_numpy_dtype, ) -# nnsight >= 0.6 removed the scan/validate trace kwargs (tracing is always lazy). -tracer_kwargs = {} - import torch from typing import Tuple @@ -636,7 +633,6 @@ def collect( if overwrite or shape is None: with model.trace( tokens, - **tracer_kwargs, ) as tracer: for i, submodule in enumerate(submodules): local_activations = (