TrustformeRS Debug
Advanced debugging and analysis tools for TrustformeRS machine learning models.
Overview
TrustformeRS Debug provides comprehensive debugging capabilities for deep learning models, including tensor inspection, gradient flow analysis, model diagnostics, performance profiling, and automated debugging hooks. These tools help identify training issues, performance bottlenecks, and model problems early in the development process.
Features
🔍 Tensor Inspector
- Real-time Analysis: Inspect tensor statistics, distributions, and patterns
- Anomaly Detection: Automatically detect NaN, infinite, and extreme values
- Memory Tracking: Monitor memory usage and identify memory leaks
- Comparison Tools: Compare tensors across different training steps or layers
📈 Gradient Debugger
- Flow Analysis: Track gradient flow through model layers
- Problem Detection: Identify vanishing and exploding gradients
- Dead Neuron Detection: Find layers with inactive neurons
- Trend Analysis: Monitor gradient patterns over training steps
🏥 Model Diagnostics
- Training Dynamics: Analyze convergence, stability, and learning efficiency
- Architecture Analysis: Evaluate model structure and parameter efficiency
- Performance Monitoring: Track training metrics and detect anomalies
- Health Assessment: Overall model health scoring and recommendations
🎣 Debugging Hooks
- Automated Monitoring: Set up conditional debugging triggers
- Layer-specific Tracking: Monitor specific layers or operations
- Custom Callbacks: Implement custom debugging logic
- Alert System: Real-time notifications for debugging events
📊 Visualization
- Interactive Plots: Generate comprehensive debugging visualizations
- Dashboard Creation: Build debugging dashboards with multiple plots
- Terminal Visualization: ASCII plots for headless environments
- Export Capabilities: Save plots and data in multiple formats
⚡ Performance Profiler
- Execution Timing: Profile layer and operation execution times
- Memory Profiling: Track memory usage patterns
- Bottleneck Detection: Identify performance bottlenecks automatically
- Optimization Suggestions: Get recommendations for performance improvements
Quick Start
Basic Usage
use ;
use Array;
async
Advanced Configuration
use ;
let config = DebugConfig ;
let mut debug_session = new;
Using Debugging Hooks
use ;
let mut debug_session = debug_session;
// Create a hook to monitor specific layers
let hook = new
.trigger
.action
.layer_patterns
.max_executions
.build;
let hook_id = debug_session.hooks_mut.register_hook?;
// Execute hooks during model execution
let tensor_data = vec!;
let results = debug_session.hooks_mut.execute_hooks;
Visualization
use ;
let config = VisualizationConfig ;
let mut visualizer = new;
// Plot tensor distribution
let values = vec!;
visualizer.plot_tensor_distribution?;
// Plot gradient flow over time
let steps = vec!;
let gradients = vec!;
visualizer.plot_gradient_flow?;
// Create dashboard
let plot_names = visualizer.get_plot_names;
let dashboard = visualizer.create_dashboard?;
Key Components
Tensor Inspector
The tensor inspector provides detailed analysis of tensor values:
- Statistical Analysis: Mean, standard deviation, min/max, norms
- Distribution Analysis: Histograms, percentiles, outlier detection
- Quality Checks: NaN/infinite value detection, sparsity analysis
- Memory Tracking: Memory usage per tensor, leak detection
let tensor_id = debug_session.tensor_inspector_mut
.inspect_tensor?;
// Get tensor information
let info = debug_session.tensor_inspector.get_tensor_info;
println!;
Gradient Debugger
Monitor gradient flow to identify training problems:
- Flow Tracking: Record gradient norms, means, and patterns
- Problem Detection: Vanishing/exploding gradients, dead neurons
- Trend Analysis: Gradient evolution over training steps
- Health Assessment: Overall gradient flow health scoring
// Record gradients for a layer
debug_session.gradient_debugger_mut
.record_gradient_flow?;
// Analyze gradient health
let analysis = debug_session.gradient_debugger.analyze_gradient_flow;
println!;
Model Diagnostics
Comprehensive model-level analysis:
- Training Dynamics: Convergence analysis, stability assessment
- Architecture Evaluation: Parameter efficiency, layer analysis
- Performance Tracking: Training metrics, memory usage
- Anomaly Detection: Performance degradation, instability detection
// Record model architecture
let arch_info = ModelArchitectureInfo ;
debug_session.model_diagnostics_mut.record_architecture;
// Record training metrics
let metrics = ModelPerformanceMetrics ;
debug_session.model_diagnostics_mut.record_performance;
Performance Profiler
Identify performance bottlenecks:
- Execution Timing: Layer and operation profiling
- Memory Analysis: Memory usage patterns and leaks
- Bottleneck Detection: Automatic performance issue identification
- Optimization Recommendations: Actionable performance suggestions
let profiler = debug_session.profiler_mut;
// Profile layer execution
profiler.start_timer;
// ... layer computation ...
let duration = profiler.end_timer;
// Record detailed layer metrics
profiler.record_layer_execution;
Terminal Visualization
For headless environments, use ASCII-based visualizations:
use TerminalVisualizer;
let terminal_viz = new;
// ASCII histogram
let histogram = terminal_viz.ascii_histogram;
println!;
// ASCII line plot
let line_plot = terminal_viz.ascii_line_plot;
println!;
Integration with Training
Integrate debugging seamlessly into your training loop:
use ;
let mut debug_session = debug_session;
debug_session.start.await?;
for epoch in 0..num_epochs
// Generate comprehensive debug report
let report = debug_session.stop.await?;
Best Practices
Performance Considerations
- Sampling: Use sampling rate < 1.0 for expensive operations
- Selective Monitoring: Monitor only critical layers during training
- Batch Processing: Process debug operations in batches when possible
- Memory Management: Clear debug data periodically for long training runs
Debugging Workflow
- Start Simple: Begin with basic tensor inspection and gradient monitoring
- Add Hooks: Use automated hooks for continuous monitoring
- Analyze Patterns: Look for trends in gradient flow and model metrics
- Visualize Results: Create dashboards for comprehensive analysis
- Act on Insights: Apply recommendations from debug reports
Common Use Cases
- Training Instability: Use gradient debugger to identify vanishing/exploding gradients
- Memory Issues: Monitor tensor memory usage and detect leaks
- Performance Optimization: Profile layer execution and identify bottlenecks
- Model Health: Track training dynamics and convergence patterns
- Debugging New Architectures: Comprehensive monitoring during model development
Examples
See the examples/ directory for comprehensive demonstrations:
debug_session_demo.rs: Complete debugging workflow examples- More examples coming soon...
Contributing
We welcome contributions to improve TrustformeRS Debug! Please see the main repository contributing guidelines.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.