Skip to main content

dead-relu-viz

Visualize dead ReLU neurons directly on a PyTorch model's architecture graph.

A dead neuron is one whose activation never leaves zero across an entire dataset — a common failure mode after a bad weight init or too high a learning rate. dead-relu-viz propagates your data through your model, measures which Conv2d/Linear units never activate, and overlays the result on the model's architecture graph (built with torchview), so you can spot where dead neurons are concentrated at a glance.

Works with any PyTorch nn.Module and any DataLoader — not tied to a specific model or dataset.

Installation

pip install dead-relu-viz

Graphviz must also be installed on your system (it's what torchview uses to render the graph):

apt install graphviz      # Debian/Ubuntu
brew install graphviz     # macOS

Usage

In a Jupyter notebook:

from dead_relu_viz import visualization

# model: any PyTorch nn.Module
# data_loader: any DataLoader
visualization(model, data_loader, with_activation=True, dpi=300)

This displays the model's architecture graph inline, with each Conv2d/Linear layer that contains dead neurons highlighted in red and annotated with the count and percentage of dead units.

Call it with with_activation=False (the default) to just render the plain architecture graph, without running any data through the model.

Arguments

  • model — any PyTorch model (nn.Module).
  • data — a DataLoader used to measure activations.
  • with_activation — False (default): plain torchview graph. True: graph annotated with dead neurons in red.
  • device — device used to run the model when measuring activations (defaults to CUDA if available, else CPU).
  • dpi — if set, overrides the graph's rendering resolution (e.g. dpi=300).
  • exclude_from_dead_check — layer names (as in model.named_modules()) to skip when coloring dead neurons — still measured and printed, just not flagged red. Useful for layers where "dead" isn't meaningful (e.g. a layer followed by a sigmoid instead of a ReLU).

Example

See cnn-activations for two worked examples (a small CNN trained on CIFAR-10, and GMIC, a breast-cancer screening model) using this tool.

License

MIT

Metadata

Release files for dead-relu-viz 0.1.0

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

Source distribution (sdist)

Source distribution for dead-relu-viz 0.1.0
File Size Uploaded
dead_relu_viz-0.1.0.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dead-relu-viz 0.1.0
File Interpreter ABI Platform
dead_relu_viz-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / dead_relu_viz-0.1.0.tar.gz

Download URL dead_relu_viz-0.1.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
485dc37c7456761b7bddd5b9fc68f8a9fcbadc623c5add4201b50e6d23f4d05f
BLAKE2b-256 checksum
How to use checksums
e28b6aab0ac21ff84dcc2072bbbaa96c92d395b36ae22f6e1dc392c9a214fd64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / dead_relu_viz-0.1.0-py3-none-any.whl

Download URL dead_relu_viz-0.1.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
941da900ee99fab2a64493862c4e6a3860c6008e1d648c26f89617e5fdfbb7b8
BLAKE2b-256 checksum
How to use checksums
73622d699dd0267c027e16cf042dbf9b4c12df00910820c13d6765dd50618611
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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