A comprehensive Python debugging toolkit for PyTorch and ML workflows. Easy Debug provides utilities to dump, view, and compare tensors, arrays, and other data structures during model training and inference.
- π Easy Dump: Save tensors, arrays, and complex data structures with automatic format detection
- ποΈ Easy View: Inspect binary files (.pt, .npy, .json, .pkl) in a human-readable format
- βοΈ Easy Compare: Compare dumped files or entire directories with detailed diff reports
- π― Automatic Format Detection: Smart file extension detection based on data type
- π Rich Statistics: Get detailed statistics for tensors and arrays
- π Flexible Configuration: Control dump behavior via environment variables
git clone https://github.com/nex-agi/easy-debug.git
cd easy-debug
pip install -e .pip install easy-debugDump values during training or inference:
from easy_debug import easy_dump
import torch
# Enable dumping via environment variable
import os
os.environ["ENABLE_EASY_DUMP"] = "1"
# Dump a tensor
tensor = torch.randn(3, 4)
easy_dump(tensor, keys=["layer1", "activation"], training_step=100)
# Dump a dictionary
data = {"loss": 0.5, "accuracy": 0.95}
easy_dump(data, keys=["metrics"], training_step=100)Inspect dumped files:
# View a .pt file
python -m easy_debug.easy_view logs/default/run_*/step_*.pt
# Save output to file
python -m easy_debug.easy_view data.pt -o output.txt
# Limit recursion depth for nested structures
python -m easy_debug.easy_view data.pt --max-depth 5Compare two files or directories:
# Compare two files
python -m easy_debug.easy_compare file1.pt file2.pt
# Detailed comparison
python -m easy_debug.easy_compare file1.pt file2.pt --detailed
# Compare specific keys in JSON files
python -m easy_debug.easy_compare file1.json file2.json --keys loss accuracy
# Compare two directories
python -m easy_debug.easy_compare --mode=folder --source dir1 --baseline dir2ENABLE_EASY_DUMP: Set to "1" to enable dumping (default: "0")EASY_DUMP_PATH: Custom subdirectory underlogs/(default: "default")EASY_DUMP_ROOT: Root directory for all logs (default: "logs")
Create a .env file in your project root:
EASY_DUMP_PATH=my_experimentDumps are organized as follows:
logs/
<EASY_DUMP_PATH>/
<run_id>/
step_000100_func_forward_layer1_activation_uuid_a1b2c3.pt
step_000100_func_backward_gradients_uuid_d4e5f6.json
...
Each run gets a unique ID (timestamp-based). Files are named with:
- Training step
- Calling function name
- Custom keys
- Unique UUID
Easy Debug automatically selects the appropriate format:
torch.Tensorβ.ptnumpy.ndarrayβ.npydict/listwith tensors β.ptdict/list(JSON-compatible) β.json- Complex objects β
.pkl - Other types β
.txt
from easy_debug.easy_dump import set_run_id, reset_run_id
# Set custom run ID
set_run_id("experiment_v1")
# Reset to create new run
reset_run_id()def my_formatter(value):
return f"Custom format: {value}"
easy_dump(data, keys=["test"], value_formatter=my_formatter)from easy_debug.easy_compare import compare_values, load_file
val1 = load_file("file1.pt")
val2 = load_file("file2.pt")
equal, message = compare_values(val1, val2, detailed=True)
if equal:
print("Files are equal!")
else:
print(f"Differences: {message}")See the examples/ directory for complete examples:
basic_usage.py: Simple dumping and viewingtraining_loop.py: Integration with PyTorch trainingcomparison_workflow.py: Comparing experiment results
- Python >= 3.8
- PyTorch >= 1.9.0
- NumPy >= 1.19.0
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
If you use Easy Debug in your research, please cite:
@software{easy_debug,
title = {Easy Debug: A Debugging Toolkit for PyTorch and ML Workflows},
author = {Nex-AGI Team},
year = {2026},
url = {https://github.com/nex-agi/easy-debug}
}Copyright (c) Nex-AGI. All rights reserved.