diff --git a/dictionary_learning/buffer.py b/dictionary_learning/buffer.py index c4635c4..43401c0 100644 --- a/dictionary_learning/buffer.py +++ b/dictionary_learning/buffer.py @@ -3,13 +3,6 @@ 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} - class ActivationBuffer: """ @@ -123,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": @@ -261,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, ): @@ -453,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 81279e5..e42fb80 100644 --- a/dictionary_learning/cache.py +++ b/dictionary_learning/cache.py @@ -10,18 +10,12 @@ 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} - import torch from typing import Tuple @@ -639,8 +633,7 @@ def collect( if overwrite or shape is None: with model.trace( tokens, - **tracer_kwargs, - ): + ) as tracer: for i, submodule in enumerate(submodules): local_activations = ( ActivationCache.get_activations(submodule, io) @@ -650,7 +643,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",