Neural network observability toolkit for PyTorch
Project description
🔭 Neural Observatory
A tool for neural network observability, diagnostics, and analysis framework for PyTorch.
A scientific instrumentation framework that allows researchers and engineers to inspect, analyze, monitor, debug, and understand the internal behavior of neural networks during training and inference.
Features
Core Diagnostics
- Dead Neuron Detection — Identify inactive neurons that contribute nothing to learning
- Gradient Health Monitoring — Detect vanishing and exploding gradients
- Activation Analysis — Statistical summaries and anomaly detection
- Parameter Health Tracking — Monitor weight drift and update magnitudes
- Numerical Anomaly Detection — Flag NaN/Inf and activation spikes
Design Philosophy
- Non-invasive — Uses PyTorch's official hooks, leaves no trace
- Extensible — Plugin-based analyzer and reporter system
- Memory-efficient — Configurable sampling, circular buffers, stats-only mode
- Production-capable — Multiple storage backends and output formats
Compatibility Matrix
| Feature | CPU | CUDA | MPS | DDP |
|---|---|---|---|---|
| Activations | ✅ | ✅ | ✅ | ❌ |
| Gradients | ✅ | ✅ | ✅ | ❌ |
| SQLite | ✅ | ✅ | ✅ | ✅ |
| HTML Report | ✅ | ✅ | ✅ | ✅ |
Version Compatibility
| PyTorch | Status |
|---|---|
| 2.1 | ✅ |
| 2.2 | ✅ |
| 2.3 | ✅ |
| Nightly | Experimental |
Supported Layers
Currently monitors the following standard PyTorch layer types (custom layers are also supported if they output tensors):
LinearConv(Conv1d, Conv2d, Conv3d, ConvTranspose)EmbeddingLayerNorm&BatchNormLSTM/GRUTransformer&MultiheadAttention
Limitations
To ensure stability, please be aware of the following current limitations:
- No DDP (Distributed Data Parallel) support yet
- No FSDP support
- TorchScript not tested
torch.compilecompatibility is experimental- Quantized models are only partially supported
Quick Start
from neural_observatory import Observatory
import torch.nn as nn
# Create model
model = nn.Sequential(
nn.Linear(10, 32),
nn.ReLU(),
nn.Linear(32, 2),
)
# Initialize and start monitoring
obs = Observatory(model)
obs.watch()
# Training loop
for epoch in range(num_epochs):
for X, y in train_loader:
# IMPORTANT: Call step() *before* the forward pass
obs.step(step=global_step, epoch=epoch)
output = model(X)
loss = criterion(output, y)
loss.backward()
optimizer.step()
# Generate diagnostics
obs.stop()
report = obs.report()
obs.console_report()
Installation
From Source
git clone https://github.com/omidNomiri/Neural_Observatory.git
cd Neural_Observatory
pip install -e .
With Development Tools
pip install -e ".[dev]"
Documentation
Architecture
Neural Observatory is built in modular layers:
Model Execution
↓
Hooks (observation points)
↓
Collectors (raw data capture)
↓
Storage (in-memory/disk)
↓
Analysis Engine (compute diagnostics)
↓
Reporting (human/machine output)
Configuration
from neural_observatory import Observatory, ObservatoryConfig
config = ObservatoryConfig(
activation_sample_rate=1, # Collect every forward pass
gradient_sample_rate=1, # Collect every backward pass
parameter_sample_rate=10, # Snapshot parameters every N steps
max_observations=1000, # Circular buffer size per layer
stats_only_mode=False, # Keep raw tensors
store_on_cpu=True, # Move tensors off GPU
)
obs = Observatory(model, config=config)
Custom Analyzers
Create custom analyzers by subclassing BaseAnalyzer:
from neural_observatory import BaseAnalyzer
class CustomAnalyzer(BaseAnalyzer):
@property
def name(self) -> str:
return "my_custom_analyzer"
def analyze(self, observations):
results = []
activations = observations.get("activations", {})
for layer_name, obs_list in activations.items():
result = self._make_result(
analyzer_name=self.name,
layer_name=layer_name,
severity=0.5,
metrics={"custom_metric": 42.0},
warnings=["Custom warning"],
)
results.append(result)
return results
obs.register_analyzer(CustomAnalyzer(config=obs.config))
Memory Safety
Neural Observatory implements strict memory safety:
- No Graph Retention — All tensors are detached immediately after observation
- CPU Movement — Tensors are moved to CPU before storage (configurable)
- Circular Buffers — Fixed-size buffers prevent unbounded memory growth
- Deep Copying — Tensor data is safely copied to prevent inplace-op corruption
- Stats-Only Mode — Discard raw tensors, keep only statistics
Testing
pytest tests/
pytest --cov=neural_observatory tests/
Roadmap
- Core activation, gradient, and parameter monitoring
- Dead neuron and vanishing/exploding gradient detection
- Inplace operation compatibility (
inplace=True) - Memory-safe tensor copying (prevent silent data corruption)
- SQLite and In-Memory storage backends
- Add support for Distributed Data Parallel (DDP) and FSDP
- Deep compatibility testing with
torch.compile - Add embedding drift detection over training epochs
- Implement attention weight visualization tools
- Add Neural Collapse detection metrics
- Write integration tests for Vision Transformers (ViT) and LLMs
- Set up automated Sphinx documentation hosting
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file neural_observatory-0.1.0b1.tar.gz.
File metadata
- Download URL: neural_observatory-0.1.0b1.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58197893d89c1758e562745fedd1ce2cd65f89034fe11dd30e3c6241a8477155
|
|
| MD5 |
d5de77544255570be8087ef8db88a884
|
|
| BLAKE2b-256 |
560057cad9f78e98ca2c33e9b0269c6f3cad029fdb0ef6882ea1c2b616190fbc
|
File details
Details for the file neural_observatory-0.1.0b1-py3-none-any.whl.
File metadata
- Download URL: neural_observatory-0.1.0b1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0dece2d89e7c3fc9d27149978d37b842c341b456a9c7edaf5e92c0674a1b6ca
|
|
| MD5 |
7004fcabc60092216a0cb3df994a7a18
|
|
| BLAKE2b-256 |
1d2d4e96a0f49dc934d501eed85949bc2d7472670b4200f93290711dafd4fe6c
|