Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions dictionary_learning/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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,
):
Expand Down Expand Up @@ -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"]:
Expand Down
11 changes: 2 additions & 9 deletions dictionary_learning/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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][
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
]
dependencies = [
"torch",
"nnsight>=0.4,<0.6",
"nnsight>=0.6",
"einops",
"pytest",
"datasets",
Expand Down
Loading