Skip to main content

ActivationScope

Jan Miksa @ IDEAS Research Institute

High-performance PyTorch activation tracker with online reduction functionality for efficient model analysis.

Built on Python + C++ with native libtorch hooks and TorchScript (torch.jit.script) reductions compiled to .pt files.

Key Benefits

  • Zero‑copy read‑back: activation tensors are shared between C++ and Python without extra copies.
  • Native C++ hooks: no Python compute overhead per forward pass.
  • Flexible policy knobs (StoragePolicy, ReductionPolicy, CapturePolicy, CaptureMode) let you balance memory, compute, and I/O.
  • Direct-to-disk streaming (StoragePolicy.DISK) — activations are written directly from C++ to disk. Ideal for long-running training loops with very large models. Activations are read back on demand from .dat files.
  • Works with large models (e.g., diffusion) and supports streaming statistics for online use cases.

Quick Start

Every tracked layer stores full activations by default — no registration needed:

import activationscope

with activationscope.ActivationScope().track(model) as tracker:
    for x, y in dataloader:
        out = model(x)
        loss.backward()

acts = tracker.activations  # {layer_name: [Tensor, ...]} across all batches

Performance

Toy model — 48 × Linear(256,256), batch=32, 200 forwards, CPU

Approach ms/forward Overhead vs baseline Data captured
No tracking 2.05 — —
Naive Python hooks 3.13 +52.7% 594 MiB
ActivationScope 2.65 +29.2% 594 MiB
  • Peak VMS identical — Scope 402,506 vs Naive 402,630 MiB (~0.03% diff, within ASLR noise)
  • 1.18× faster than naive Python hooks (3.13 → 2.65 ms/fwd)
  • 95 layers tracked (inputs + outputs across 48 linear layers)
  • Zero-copy readback: 594 MiB in 2.4 ms

Run it yourself:

# Toy model (fast, GPU or CPU)
PYTHONPATH=. python -m benchmark.runner

# Pretrained ResNet-18 (requires torchvision)
PYTHONPATH=. python -m benchmark.runner --model resnet18

Usage Guide

For detailed usage instructions, see the Usage Documentation.

Development Guide

Documentation and developer setup information is available in Development Documentation.

Design Documentation

The design document outlining the architecture and implementation details can be found in Design Documentation.

Metadata

Release files for activationscope 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for activationscope 0.1.4
File Size Uploaded
activationscope-0.1.4.tar.gz 51.5 kB Details

Release files / activationscope-0.1.4.tar.gz

Download URL activationscope-0.1.4.tar.gz
Size 51.5 kB
Tags Source
SHA-256 checksum
How to use checksums
10b40808df4963a04fe42776ffac7c025e008513f757747bed5a04919f8f532f
BLAKE2b-256 checksum
How to use checksums
10e46ccff5f383e6c4f6f169695c326db908bd028abaea0612eae802c416a1ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.1.4 This release

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page