neuraldbg 1.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- neuraldbg-1.3.0/LICENSE.md +21 -0
- neuraldbg-1.3.0/PKG-INFO +327 -0
- neuraldbg-1.3.0/README.md +289 -0
- neuraldbg-1.3.0/neuraldbg/__init__.py +840 -0
- neuraldbg-1.3.0/neuraldbg/enhanced_causality.py +239 -0
- neuraldbg-1.3.0/neuraldbg.egg-info/PKG-INFO +327 -0
- neuraldbg-1.3.0/neuraldbg.egg-info/SOURCES.txt +10 -0
- neuraldbg-1.3.0/neuraldbg.egg-info/dependency_links.txt +1 -0
- neuraldbg-1.3.0/neuraldbg.egg-info/requires.txt +12 -0
- neuraldbg-1.3.0/neuraldbg.egg-info/top_level.txt +1 -0
- neuraldbg-1.3.0/pyproject.toml +71 -0
- neuraldbg-1.3.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2025] [Lemniscate-SHA-256] [SENOUVO Jacques-Charles Gad]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
neuraldbg-1.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: neuraldbg
|
|
3
|
+
Version: 1.3.0
|
|
4
|
+
Summary: Causal inference engine for deep learning training dynamics
|
|
5
|
+
Author-email: SENOUVO Jacques-Charles Gad <neuraldbg@lemniscate.ai>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/LambdaSection/NeuralDBG
|
|
8
|
+
Project-URL: Repository, https://github.com/LambdaSection/NeuralDBG
|
|
9
|
+
Project-URL: Documentation, https://github.com/LambdaSection/NeuralDBG#readme
|
|
10
|
+
Project-URL: Changelog, https://github.com/LambdaSection/NeuralDBG/blob/main/CHANGELOG.md
|
|
11
|
+
Project-URL: Issues, https://github.com/LambdaSection/NeuralDBG/issues
|
|
12
|
+
Keywords: deep-learning,pytorch,debugging,causal-inference,training-dynamics,gradient-analysis,machine-learning
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Topic :: Software Development :: Debuggers
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE.md
|
|
28
|
+
Requires-Dist: torch>=2.0.0
|
|
29
|
+
Requires-Dist: psutil>=5.9.0
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
32
|
+
Requires-Dist: coverage>=7.0; extra == "dev"
|
|
33
|
+
Provides-Extra: mlops
|
|
34
|
+
Requires-Dist: mlflow>=2.13.0; extra == "mlops"
|
|
35
|
+
Provides-Extra: docs
|
|
36
|
+
Requires-Dist: pdoc>=14.0.0; extra == "docs"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# NeuralDBG
|
|
40
|
+
|
|
41
|
+
A causal inference engine for deep learning training that provides **structured explanations** of neural network training failures. Understand *why* your model failed during training through semantic analysis and abductive reasoning, not raw tensor inspection.
|
|
42
|
+
|
|
43
|
+
[](https://opensource.org/licenses/MIT)
|
|
44
|
+
[](https://www.python.org/downloads/)
|
|
45
|
+
[](https://github.com/Lemniscate-world/Neural/actions)
|
|
46
|
+
[](https://github.com/Lemniscate-world/Neural/actions)
|
|
47
|
+
[](https://github.com/PyCQA/bandit)
|
|
48
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
49
|
+
|
|
50
|
+
## Overview
|
|
51
|
+
|
|
52
|
+
NeuralDBG treats training as a **semantic trace of learning dynamics** rather than a black box. It extracts meaningful events and provides causal hypotheses about training failures, enabling researchers to:
|
|
53
|
+
|
|
54
|
+
- **Identify gradient health transitions** (stable -> vanishing/saturated)
|
|
55
|
+
- **Detect activation regime shifts** (normal -> saturated/dead)
|
|
56
|
+
- **Detect optimizer instability** (loss plateaus, spikes, divergence)
|
|
57
|
+
- **Catch data anomalies** (NaN, Inf, distribution shifts)
|
|
58
|
+
- **Track propagation of instabilities** through network layers
|
|
59
|
+
- **Generate ranked causal explanations** for training failures
|
|
60
|
+
|
|
61
|
+
Unlike traditional monitoring tools (TensorBoard, Weights & Biases), NeuralDBG focuses on **causal inference** rather than metric tracking.
|
|
62
|
+
|
|
63
|
+
## Key Features
|
|
64
|
+
|
|
65
|
+
- **Semantic Event Extraction**: Detects meaningful transitions in training dynamics
|
|
66
|
+
- **Causal Compression**: Identifies first occurrences and propagation patterns
|
|
67
|
+
- **Post-Mortem Reasoning**: Provides ranked hypotheses about failure causes
|
|
68
|
+
- **Optimizer Instability Detection**: Tracks loss plateaus, spikes, and divergence
|
|
69
|
+
- **Data Anomaly Detection**: Catches NaN, Inf, and distribution shifts in inputs
|
|
70
|
+
- **Event Collapsing**: Merges sequential events into summary traces
|
|
71
|
+
- **Compiler-Aware**: Operates at module boundaries to survive torch.compile
|
|
72
|
+
- **Non-Invasive**: Wraps existing PyTorch training loops without code changes
|
|
73
|
+
- **Minimal API**: Focused on explanations, not raw data dumps
|
|
74
|
+
|
|
75
|
+
## Quick Start
|
|
76
|
+
|
|
77
|
+
### Installation
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install neuraldbg
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Contributor Onboarding
|
|
84
|
+
|
|
85
|
+
For a new collaborator, run:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
make bootstrap
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This one-command setup:
|
|
92
|
+
- verifies or recreates `.venv`
|
|
93
|
+
- installs runtime, development, and MLflow/MLOps dependencies
|
|
94
|
+
- activates the repository git hooks
|
|
95
|
+
- installs the project in editable mode
|
|
96
|
+
|
|
97
|
+
Then activate the environment:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
source .venv/bin/activate
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Validation sync is intentionally opt-in because it depends on `VALIDATION_BUNDLE_TOKEN` and rewrites protected local files:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
bash scripts/bootstrap.sh --with-validation-sync
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Docker Development (Hermetic Workspace)
|
|
110
|
+
|
|
111
|
+
Use Docker to keep a reproducible local environment across machines and contributors.
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# Build image
|
|
115
|
+
docker-compose build
|
|
116
|
+
|
|
117
|
+
# Start the dev container (one-command startup)
|
|
118
|
+
docker-compose up -d
|
|
119
|
+
|
|
120
|
+
# Open a shell in the running workspace
|
|
121
|
+
docker-compose exec neuraldbg-dev bash
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Equivalent shortcuts via `Makefile`:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
make build
|
|
128
|
+
make up
|
|
129
|
+
make shell
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Run tests inside Docker:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
docker-compose run --rm neuraldbg-dev bash -lc "pytest"
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Or:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
make test-docker
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Persistent volumes are mounted to:
|
|
145
|
+
- `/data` (host: `./data`)
|
|
146
|
+
- `/models` (host: `./models`)
|
|
147
|
+
- `/outputs` (host: `./outputs`)
|
|
148
|
+
|
|
149
|
+
Stop containers:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
docker-compose down
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Basic Usage
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
import torch
|
|
159
|
+
import torch.nn as nn
|
|
160
|
+
from neuraldbg import NeuralDbg
|
|
161
|
+
|
|
162
|
+
# Your existing model and training setup
|
|
163
|
+
model = nn.Sequential(nn.Linear(10, 5), nn.ReLU(), nn.Linear(5, 1))
|
|
164
|
+
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
|
|
165
|
+
criterion = nn.MSELoss()
|
|
166
|
+
|
|
167
|
+
# Wrap your training loop
|
|
168
|
+
with NeuralDbg(model) as dbg:
|
|
169
|
+
for step, (inputs, targets) in enumerate(dataloader):
|
|
170
|
+
optimizer.zero_grad()
|
|
171
|
+
|
|
172
|
+
outputs = model(inputs)
|
|
173
|
+
loss = criterion(outputs, targets)
|
|
174
|
+
loss.backward()
|
|
175
|
+
optimizer.step()
|
|
176
|
+
|
|
177
|
+
# Events are extracted automatically
|
|
178
|
+
|
|
179
|
+
# After training failure, query for explanations
|
|
180
|
+
explanations = dbg.explain_failure()
|
|
181
|
+
print(explanations[0]) # "Gradient vanishing originated in layer 'linear1' at step 234, likely due to LR × activation mismatch (confidence: 0.87)"
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Inference API
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
# Get ranked causal hypotheses for the failure
|
|
188
|
+
hypotheses = dbg.get_causal_hypotheses()
|
|
189
|
+
|
|
190
|
+
# Query specific causal chains
|
|
191
|
+
chain = dbg.trace_causal_chain('vanishing_gradients')
|
|
192
|
+
|
|
193
|
+
# Check for coupled failures
|
|
194
|
+
couplings = dbg.detect_coupled_failures()
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Optimizer Instability Detection
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
with NeuralDbg(model) as dbg:
|
|
201
|
+
for step in range(num_steps):
|
|
202
|
+
dbg.step = step
|
|
203
|
+
output = model(inputs)
|
|
204
|
+
loss = criterion(output, targets)
|
|
205
|
+
loss.backward()
|
|
206
|
+
|
|
207
|
+
# Feed loss values for optimizer instability detection
|
|
208
|
+
dbg.record_loss(loss.item())
|
|
209
|
+
|
|
210
|
+
optimizer.step()
|
|
211
|
+
|
|
212
|
+
# Detect loss plateaus, spikes, or divergence
|
|
213
|
+
hypotheses = dbg.explain_failure("optimizer_instability")
|
|
214
|
+
for h in hypotheses:
|
|
215
|
+
print(h.description) # "Loss spike detected at step 50..."
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Data Anomaly Detection
|
|
219
|
+
|
|
220
|
+
Data anomalies (NaN, Inf, distribution shifts) are detected automatically
|
|
221
|
+
from layer inputs during the forward pass -- no extra API call needed:
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
with NeuralDbg(model) as dbg:
|
|
225
|
+
# ... training loop ...
|
|
226
|
+
pass
|
|
227
|
+
|
|
228
|
+
# Check for data issues
|
|
229
|
+
hypotheses = dbg.explain_failure("data_anomaly")
|
|
230
|
+
for h in hypotheses:
|
|
231
|
+
print(h.description) # "NaN values detected in input to layer 'linear1'..."
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Event Collapsing
|
|
235
|
+
|
|
236
|
+
Compress sequential events in the same layer into summary traces:
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
# Get compressed event timeline
|
|
240
|
+
collapsed = dbg._collapse_events()
|
|
241
|
+
print(f"{len(dbg.events)} raw events -> {len(collapsed)} collapsed")
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Architecture
|
|
245
|
+
|
|
246
|
+
### Core Components
|
|
247
|
+
|
|
248
|
+
- **Semantic Event Extractor**: Detects meaningful transitions in learning dynamics
|
|
249
|
+
- **Causal Compressor**: Identifies patterns and propagation in training failures
|
|
250
|
+
- **Post-Mortem Reasoner**: Generates ranked hypotheses about failure causes
|
|
251
|
+
- **Compiler-Aware Monitor**: Operates at safe boundaries for optimization compatibility
|
|
252
|
+
|
|
253
|
+
### Event Types
|
|
254
|
+
|
|
255
|
+
| Event Type | Source | Detects |
|
|
256
|
+
|------------|--------|---------|
|
|
257
|
+
| `gradient_health_transition` | Backward hooks | Vanishing, exploding, saturated gradients |
|
|
258
|
+
| `activation_regime_shift` | Forward hooks | Dead neurons, saturated activations |
|
|
259
|
+
| `optimizer_instability` | `record_loss()` | Loss plateaus, spikes, divergence |
|
|
260
|
+
| `data_anomaly` | Forward hooks (inputs) | NaN, Inf, distribution shifts |
|
|
261
|
+
|
|
262
|
+
### Event Structure
|
|
263
|
+
|
|
264
|
+
Each semantic event represents:
|
|
265
|
+
- Transition type (gradient_health, activation_regime, optimizer_instability, data_anomaly)
|
|
266
|
+
- Layer/parameter identifier
|
|
267
|
+
- Step range of occurrence
|
|
268
|
+
- Confidence score
|
|
269
|
+
- Causal metadata (propagation patterns, coupled failures)
|
|
270
|
+
|
|
271
|
+
## Target Users
|
|
272
|
+
|
|
273
|
+
- **ML Researchers** seeking causal explanations for training failures
|
|
274
|
+
- **PhD Students** analyzing learning dynamics in novel architectures
|
|
275
|
+
- **Research Engineers** understanding optimization instabilities
|
|
276
|
+
|
|
277
|
+
*Not intended for production monitoring, metric tracking, or no-code users.*
|
|
278
|
+
|
|
279
|
+
## Supported Failure Types
|
|
280
|
+
|
|
281
|
+
- `vanishing_gradients` -- Root cause + saturation coupling
|
|
282
|
+
- `exploding_gradients` -- First layer to explode
|
|
283
|
+
- `dead_neurons` -- Neuron death in activation layers
|
|
284
|
+
- `saturated_activations` -- Activation saturation patterns
|
|
285
|
+
- `optimizer_instability` -- Loss plateaus, spikes, divergence (with gradient cross-reference)
|
|
286
|
+
- `data_anomaly` -- NaN/Inf/distribution shift in inputs
|
|
287
|
+
|
|
288
|
+
## Limitations (MVP Scope)
|
|
289
|
+
|
|
290
|
+
- PyTorch only
|
|
291
|
+
- Focus on semantic events, not tensor inspection
|
|
292
|
+
- Command-line interface only
|
|
293
|
+
- Compiler-aware (torch.compile compatible)
|
|
294
|
+
|
|
295
|
+
## Contributing
|
|
296
|
+
|
|
297
|
+
This is an MVP focused on proving the concept of causal inference for training dynamics. Contributions should align with the core mission of providing structured explanations for training failures.
|
|
298
|
+
|
|
299
|
+
1. Fork the repository
|
|
300
|
+
2. Create a feature branch
|
|
301
|
+
3. Add tests for new functionality
|
|
302
|
+
4. Ensure all tests pass
|
|
303
|
+
5. Submit a pull request
|
|
304
|
+
|
|
305
|
+
## License
|
|
306
|
+
|
|
307
|
+
MIT License - see [LICENSE.md](LICENSE.md) for details.
|
|
308
|
+
|
|
309
|
+
## Documentation
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
- [CHANGELOG.md](CHANGELOG.md) - Version history and notable changes
|
|
313
|
+
- [logic_graph.md](logic_graph.md) - System architecture and data flow
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
## Citation
|
|
317
|
+
|
|
318
|
+
If you use NeuralDBG in your research, please cite:
|
|
319
|
+
|
|
320
|
+
```bibtex
|
|
321
|
+
@misc{neuraldbg2025,
|
|
322
|
+
title={NeuralDBG: A Causal Inference Engine for Deep Learning Training Dynamics},
|
|
323
|
+
author={SENOUVO Jacques-Charles Gad},
|
|
324
|
+
year={2025},
|
|
325
|
+
url={https://github.com/Lemniscate-world/Neural}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# NeuralDBG
|
|
2
|
+
|
|
3
|
+
A causal inference engine for deep learning training that provides **structured explanations** of neural network training failures. Understand *why* your model failed during training through semantic analysis and abductive reasoning, not raw tensor inspection.
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.python.org/downloads/)
|
|
7
|
+
[](https://github.com/Lemniscate-world/Neural/actions)
|
|
8
|
+
[](https://github.com/Lemniscate-world/Neural/actions)
|
|
9
|
+
[](https://github.com/PyCQA/bandit)
|
|
10
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
NeuralDBG treats training as a **semantic trace of learning dynamics** rather than a black box. It extracts meaningful events and provides causal hypotheses about training failures, enabling researchers to:
|
|
15
|
+
|
|
16
|
+
- **Identify gradient health transitions** (stable -> vanishing/saturated)
|
|
17
|
+
- **Detect activation regime shifts** (normal -> saturated/dead)
|
|
18
|
+
- **Detect optimizer instability** (loss plateaus, spikes, divergence)
|
|
19
|
+
- **Catch data anomalies** (NaN, Inf, distribution shifts)
|
|
20
|
+
- **Track propagation of instabilities** through network layers
|
|
21
|
+
- **Generate ranked causal explanations** for training failures
|
|
22
|
+
|
|
23
|
+
Unlike traditional monitoring tools (TensorBoard, Weights & Biases), NeuralDBG focuses on **causal inference** rather than metric tracking.
|
|
24
|
+
|
|
25
|
+
## Key Features
|
|
26
|
+
|
|
27
|
+
- **Semantic Event Extraction**: Detects meaningful transitions in training dynamics
|
|
28
|
+
- **Causal Compression**: Identifies first occurrences and propagation patterns
|
|
29
|
+
- **Post-Mortem Reasoning**: Provides ranked hypotheses about failure causes
|
|
30
|
+
- **Optimizer Instability Detection**: Tracks loss plateaus, spikes, and divergence
|
|
31
|
+
- **Data Anomaly Detection**: Catches NaN, Inf, and distribution shifts in inputs
|
|
32
|
+
- **Event Collapsing**: Merges sequential events into summary traces
|
|
33
|
+
- **Compiler-Aware**: Operates at module boundaries to survive torch.compile
|
|
34
|
+
- **Non-Invasive**: Wraps existing PyTorch training loops without code changes
|
|
35
|
+
- **Minimal API**: Focused on explanations, not raw data dumps
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install neuraldbg
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Contributor Onboarding
|
|
46
|
+
|
|
47
|
+
For a new collaborator, run:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
make bootstrap
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This one-command setup:
|
|
54
|
+
- verifies or recreates `.venv`
|
|
55
|
+
- installs runtime, development, and MLflow/MLOps dependencies
|
|
56
|
+
- activates the repository git hooks
|
|
57
|
+
- installs the project in editable mode
|
|
58
|
+
|
|
59
|
+
Then activate the environment:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
source .venv/bin/activate
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Validation sync is intentionally opt-in because it depends on `VALIDATION_BUNDLE_TOKEN` and rewrites protected local files:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
bash scripts/bootstrap.sh --with-validation-sync
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Docker Development (Hermetic Workspace)
|
|
72
|
+
|
|
73
|
+
Use Docker to keep a reproducible local environment across machines and contributors.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Build image
|
|
77
|
+
docker-compose build
|
|
78
|
+
|
|
79
|
+
# Start the dev container (one-command startup)
|
|
80
|
+
docker-compose up -d
|
|
81
|
+
|
|
82
|
+
# Open a shell in the running workspace
|
|
83
|
+
docker-compose exec neuraldbg-dev bash
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Equivalent shortcuts via `Makefile`:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
make build
|
|
90
|
+
make up
|
|
91
|
+
make shell
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Run tests inside Docker:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
docker-compose run --rm neuraldbg-dev bash -lc "pytest"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Or:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
make test-docker
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Persistent volumes are mounted to:
|
|
107
|
+
- `/data` (host: `./data`)
|
|
108
|
+
- `/models` (host: `./models`)
|
|
109
|
+
- `/outputs` (host: `./outputs`)
|
|
110
|
+
|
|
111
|
+
Stop containers:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
docker-compose down
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Basic Usage
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
import torch
|
|
121
|
+
import torch.nn as nn
|
|
122
|
+
from neuraldbg import NeuralDbg
|
|
123
|
+
|
|
124
|
+
# Your existing model and training setup
|
|
125
|
+
model = nn.Sequential(nn.Linear(10, 5), nn.ReLU(), nn.Linear(5, 1))
|
|
126
|
+
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
|
|
127
|
+
criterion = nn.MSELoss()
|
|
128
|
+
|
|
129
|
+
# Wrap your training loop
|
|
130
|
+
with NeuralDbg(model) as dbg:
|
|
131
|
+
for step, (inputs, targets) in enumerate(dataloader):
|
|
132
|
+
optimizer.zero_grad()
|
|
133
|
+
|
|
134
|
+
outputs = model(inputs)
|
|
135
|
+
loss = criterion(outputs, targets)
|
|
136
|
+
loss.backward()
|
|
137
|
+
optimizer.step()
|
|
138
|
+
|
|
139
|
+
# Events are extracted automatically
|
|
140
|
+
|
|
141
|
+
# After training failure, query for explanations
|
|
142
|
+
explanations = dbg.explain_failure()
|
|
143
|
+
print(explanations[0]) # "Gradient vanishing originated in layer 'linear1' at step 234, likely due to LR × activation mismatch (confidence: 0.87)"
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Inference API
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
# Get ranked causal hypotheses for the failure
|
|
150
|
+
hypotheses = dbg.get_causal_hypotheses()
|
|
151
|
+
|
|
152
|
+
# Query specific causal chains
|
|
153
|
+
chain = dbg.trace_causal_chain('vanishing_gradients')
|
|
154
|
+
|
|
155
|
+
# Check for coupled failures
|
|
156
|
+
couplings = dbg.detect_coupled_failures()
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Optimizer Instability Detection
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
with NeuralDbg(model) as dbg:
|
|
163
|
+
for step in range(num_steps):
|
|
164
|
+
dbg.step = step
|
|
165
|
+
output = model(inputs)
|
|
166
|
+
loss = criterion(output, targets)
|
|
167
|
+
loss.backward()
|
|
168
|
+
|
|
169
|
+
# Feed loss values for optimizer instability detection
|
|
170
|
+
dbg.record_loss(loss.item())
|
|
171
|
+
|
|
172
|
+
optimizer.step()
|
|
173
|
+
|
|
174
|
+
# Detect loss plateaus, spikes, or divergence
|
|
175
|
+
hypotheses = dbg.explain_failure("optimizer_instability")
|
|
176
|
+
for h in hypotheses:
|
|
177
|
+
print(h.description) # "Loss spike detected at step 50..."
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Data Anomaly Detection
|
|
181
|
+
|
|
182
|
+
Data anomalies (NaN, Inf, distribution shifts) are detected automatically
|
|
183
|
+
from layer inputs during the forward pass -- no extra API call needed:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
with NeuralDbg(model) as dbg:
|
|
187
|
+
# ... training loop ...
|
|
188
|
+
pass
|
|
189
|
+
|
|
190
|
+
# Check for data issues
|
|
191
|
+
hypotheses = dbg.explain_failure("data_anomaly")
|
|
192
|
+
for h in hypotheses:
|
|
193
|
+
print(h.description) # "NaN values detected in input to layer 'linear1'..."
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Event Collapsing
|
|
197
|
+
|
|
198
|
+
Compress sequential events in the same layer into summary traces:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
# Get compressed event timeline
|
|
202
|
+
collapsed = dbg._collapse_events()
|
|
203
|
+
print(f"{len(dbg.events)} raw events -> {len(collapsed)} collapsed")
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Architecture
|
|
207
|
+
|
|
208
|
+
### Core Components
|
|
209
|
+
|
|
210
|
+
- **Semantic Event Extractor**: Detects meaningful transitions in learning dynamics
|
|
211
|
+
- **Causal Compressor**: Identifies patterns and propagation in training failures
|
|
212
|
+
- **Post-Mortem Reasoner**: Generates ranked hypotheses about failure causes
|
|
213
|
+
- **Compiler-Aware Monitor**: Operates at safe boundaries for optimization compatibility
|
|
214
|
+
|
|
215
|
+
### Event Types
|
|
216
|
+
|
|
217
|
+
| Event Type | Source | Detects |
|
|
218
|
+
|------------|--------|---------|
|
|
219
|
+
| `gradient_health_transition` | Backward hooks | Vanishing, exploding, saturated gradients |
|
|
220
|
+
| `activation_regime_shift` | Forward hooks | Dead neurons, saturated activations |
|
|
221
|
+
| `optimizer_instability` | `record_loss()` | Loss plateaus, spikes, divergence |
|
|
222
|
+
| `data_anomaly` | Forward hooks (inputs) | NaN, Inf, distribution shifts |
|
|
223
|
+
|
|
224
|
+
### Event Structure
|
|
225
|
+
|
|
226
|
+
Each semantic event represents:
|
|
227
|
+
- Transition type (gradient_health, activation_regime, optimizer_instability, data_anomaly)
|
|
228
|
+
- Layer/parameter identifier
|
|
229
|
+
- Step range of occurrence
|
|
230
|
+
- Confidence score
|
|
231
|
+
- Causal metadata (propagation patterns, coupled failures)
|
|
232
|
+
|
|
233
|
+
## Target Users
|
|
234
|
+
|
|
235
|
+
- **ML Researchers** seeking causal explanations for training failures
|
|
236
|
+
- **PhD Students** analyzing learning dynamics in novel architectures
|
|
237
|
+
- **Research Engineers** understanding optimization instabilities
|
|
238
|
+
|
|
239
|
+
*Not intended for production monitoring, metric tracking, or no-code users.*
|
|
240
|
+
|
|
241
|
+
## Supported Failure Types
|
|
242
|
+
|
|
243
|
+
- `vanishing_gradients` -- Root cause + saturation coupling
|
|
244
|
+
- `exploding_gradients` -- First layer to explode
|
|
245
|
+
- `dead_neurons` -- Neuron death in activation layers
|
|
246
|
+
- `saturated_activations` -- Activation saturation patterns
|
|
247
|
+
- `optimizer_instability` -- Loss plateaus, spikes, divergence (with gradient cross-reference)
|
|
248
|
+
- `data_anomaly` -- NaN/Inf/distribution shift in inputs
|
|
249
|
+
|
|
250
|
+
## Limitations (MVP Scope)
|
|
251
|
+
|
|
252
|
+
- PyTorch only
|
|
253
|
+
- Focus on semantic events, not tensor inspection
|
|
254
|
+
- Command-line interface only
|
|
255
|
+
- Compiler-aware (torch.compile compatible)
|
|
256
|
+
|
|
257
|
+
## Contributing
|
|
258
|
+
|
|
259
|
+
This is an MVP focused on proving the concept of causal inference for training dynamics. Contributions should align with the core mission of providing structured explanations for training failures.
|
|
260
|
+
|
|
261
|
+
1. Fork the repository
|
|
262
|
+
2. Create a feature branch
|
|
263
|
+
3. Add tests for new functionality
|
|
264
|
+
4. Ensure all tests pass
|
|
265
|
+
5. Submit a pull request
|
|
266
|
+
|
|
267
|
+
## License
|
|
268
|
+
|
|
269
|
+
MIT License - see [LICENSE.md](LICENSE.md) for details.
|
|
270
|
+
|
|
271
|
+
## Documentation
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
- [CHANGELOG.md](CHANGELOG.md) - Version history and notable changes
|
|
275
|
+
- [logic_graph.md](logic_graph.md) - System architecture and data flow
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
## Citation
|
|
279
|
+
|
|
280
|
+
If you use NeuralDBG in your research, please cite:
|
|
281
|
+
|
|
282
|
+
```bibtex
|
|
283
|
+
@misc{neuraldbg2025,
|
|
284
|
+
title={NeuralDBG: A Causal Inference Engine for Deep Learning Training Dynamics},
|
|
285
|
+
author={SENOUVO Jacques-Charles Gad},
|
|
286
|
+
year={2025},
|
|
287
|
+
url={https://github.com/Lemniscate-world/Neural}
|
|
288
|
+
}
|
|
289
|
+
```
|