Skip to content

Commit

Permalink
Made TorchLens compatible with sparse tensors.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMark Taylor committed Jan 13, 2025
1 parent e07e784 commit 6745a86
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name="torchlens",
version="0.1.26",
version="0.1.27",
description="A package for extracting activations from PyTorch models",
long_description="A package for extracting activations from PyTorch models. Contains functionality for "
"extracting model activations, visualizing a model's computational graph, and "
Expand Down
3 changes: 2 additions & 1 deletion torchlens/helper_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def get_tensor_memory_amount(t: torch.Tensor) -> int:
cpu_data = clean_cpu(t.data)
if cpu_data.dtype == torch.bfloat16:
cpu_data = clean_to(cpu_data, torch.float16)
return getsizeof(np.array(cpu_data))
return getsizeof(np.array(clean_dense(cpu_data)))


def human_readable_size(size: int, decimal_places: int = 1) -> str:
Expand Down Expand Up @@ -627,6 +627,7 @@ def human_readable_size(size: int, decimal_places: int = 1) -> str:
clean_cpu = copy.deepcopy(torch.Tensor.cpu)
clean_cuda = copy.deepcopy(torch.Tensor.cuda)
clean_to = copy.deepcopy(torch.Tensor.to)
clean_dense = copy.deepcopy(torch.Tensor.to_dense)


def print_override(t: torch.Tensor, func_name: str):
Expand Down

0 comments on commit 6745a86

Please sign in to comment.