trustformers-debug 0.2.1

Advanced debugging tools for TrustformeRS models
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
//! # TrustformeRS Debug
//!
//! Advanced debugging tools for TrustformeRS models including tensor inspection,
//! gradient debugging, and model diagnostics.

// Allow ambiguous glob re-exports - documented below with clear guidance on which version to use
#![allow(ambiguous_glob_reexports)]
// Allow large error types in Result (TrustformersError is large by design)
#![allow(clippy::result_large_err)]
// Allow large enum variants (debug reports contain comprehensive data)
#![allow(clippy::large_enum_variant)]
// Allow common patterns in debugging/profiling code
#![allow(clippy::too_many_arguments)]
#![allow(clippy::type_complexity)]
#![allow(clippy::excessive_nesting)]
// Allow manual clamp pattern (.max().min()) - more explicit and doesn't panic on NaN
#![allow(clippy::manual_clamp)]
// Allow range loops for better readability in array indexing
#![allow(clippy::needless_range_loop)]
// Not all types need Default implementations
#![allow(clippy::new_without_default)]
// Style preferences for vec initialization
#![allow(clippy::vec_init_then_push)]
// Allow format! in format args for clarity
#![allow(clippy::format_in_format_args)]
// Empty lines after attributes are intentional for readability
#![allow(clippy::empty_line_after_outer_attr)]
#![allow(clippy::empty_line_after_doc_comments)]
// Allow await holding lock in debug code where it's safe
#![allow(clippy::await_holding_lock)]
// Allow if-else with same body in debug code for clarity
#![allow(clippy::if_same_then_else)]
// Allow double-ended iterator last when it's clearer
#![allow(clippy::double_ended_iterator_last)]
// Allow manual strip for explicit string handling
#![allow(clippy::manual_strip)]
// Allow derivable impls when Default has complex semantics
#![allow(clippy::derivable_impls)]
// Allow needless question mark in debug code for clarity
#![allow(clippy::needless_question_mark)]
// Allow let_and_return for clarity in complex expressions
#![allow(clippy::let_and_return)]
// Allow field reassign with default in test code
#![allow(clippy::field_reassign_with_default)]
// Allow filter_map when pattern matching different variants
#![allow(clippy::unnecessary_filter_map)]
// Allow uppercase acronyms like LSTM, GPU, etc.
#![allow(clippy::upper_case_acronyms)]
// Allow never_loop in streaming code (intentional drain patterns)
#![allow(clippy::never_loop)]

// New visualization and analysis modules
pub mod activation_visualizer;
pub mod attention_visualizer;
pub mod graph_visualizer;
pub mod mlflow_integration;
pub mod netron_export;
pub mod performance_tuning;
pub mod stability_checker;
pub mod tensorboard_integration;
pub mod unified_debug_session;
pub mod visualization_plugins;
pub mod weight_analyzer;

pub mod advanced_gpu_profiler;
pub mod advanced_ml_debugging;
pub mod ai_code_analyzer;
pub mod anomaly_detector;
pub mod architecture_analysis;
pub mod auto_debugger;
pub mod behavior_analysis;
pub mod cicd_integration;
pub mod collaboration;
pub mod computation_graph;
pub mod dashboard;
pub mod data_export;
pub mod differential_debugging;
pub mod distributed_debugger;
pub mod distributed_profiling;
pub mod environmental_monitor;
pub mod error_recovery;
pub mod flame_graph_profiler;
pub mod gradient_debugger;
pub mod health_checker;
pub mod hooks;
pub mod ide_integration;
pub mod interactive_debugger;
pub(crate) mod interpretability;
pub mod interpretability_tools;
pub mod kernel_optimizer;
pub mod large_model_viz;
pub mod llm_debugging;
pub mod memory_profiler;
pub mod model_diagnostics;
pub mod model_diagnostics_main;
pub use model_diagnostics_main::{ModelDiagnostics, ModelDiagnosticsReport};

// Import specific types from model_diagnostics to avoid conflicts
pub use model_diagnostics::{
    ActivationHeatmap,
    ActiveAlert,
    // Advanced analytics
    AdvancedAnalytics,
    AlertConfig,
    // Alert system
    AlertManager,
    AlertSeverity,
    AlertStatistics,

    AlertStatus,
    AlertThresholds,
    AnalyticsConfig,
    AnalyticsReport,
    AnomalyDetectionResults,
    ArchitecturalAnalysis,
    AttentionVisualization,
    AutoDebugConfig,
    // Auto-debugging system
    AutoDebugger,
    ConvergenceStatus,
    DebuggingRecommendation,
    DebuggingReport,
    HiddenStateAnalysis,

    IdentifiedIssue,
    IssueCategory,
    IssueSeverity,

    LayerActivationStats,
    LayerAnalysis,
    LayerAnalysisConfig,

    // Layer analysis (prefixed to avoid conflicts)
    LayerAnalyzer,
    ModelArchitectureInfo,
    ModelDiagnosticAlert,
    // Core types that don't conflict
    ModelPerformanceMetrics,
    OverfittingIndicator,
    // Performance analysis (prefixed to avoid conflicts)
    PerformanceAnalyzer,
    PerformanceAnomaly,

    PerformanceSummary,
    PlateauInfo,
    StatisticalAnalysis,
    TrainingDynamics,
    // Training analysis (prefixed to avoid conflicts)
    TrainingDynamicsAnalyzer,

    TrainingStability,
    UnderfittingIndicator,
    WeightDistribution,
};
pub mod neural_network_debugging;
pub mod profiler;
pub mod quantum_debugging;
pub mod realtime_dashboard;
pub mod regression_detector;
pub mod report_generation;
pub mod simulation_tools;
pub mod streaming_debugger;
pub mod team_dashboard;
pub mod tensor_inspector;
pub mod training_dynamics;
pub mod utilities;
pub mod visualization;
#[cfg(feature = "wasm")]
pub mod wasm_interface;

/// Lock-free single-producer/multi-consumer ring buffer used by
/// [`dashboard_ws`] to fan out live training events without an unbounded
/// backlog. Was previously compiled (`mod ring_buffer;` was missing from
/// this file) but never reachable from outside the crate, so its tests
/// never ran; declared here rather than deleted since [`dashboard_ws`]
/// depends on it and both are real, working implementations.
pub mod ring_buffer;

/// Trace-export formats for profiling data: Chrome/Perfetto JSON, Tracy
/// CSV, and a unified CSV/JSON exporter. Re-exported under the `export`
/// namespace (not glob-imported at the crate root) because its
/// [`export::ExportFormat`] name collides with unrelated `ExportFormat`
/// types already defined in [`data_export`] and [`netron_export`].
pub mod export;

/// Real-time training-event streaming over Server-Sent Events (SSE), with
/// no third-party web-framework dependency. Re-exported under the
/// `dashboard_ws` namespace (not glob-imported) because its
/// [`dashboard_ws::DashboardConfig`] name collides with the crate's several
/// other `DashboardConfig` types (see [`realtime_dashboard`],
/// [`team_dashboard`]).
pub mod dashboard_ws;

/// Performance-regression detectors: baseline comparison
/// ([`regression::RegressionDetector`]) plus streaming z-score/CUSUM
/// change-point detection. Re-exported under the `regression` namespace
/// (not glob-imported) because [`regression::RegressionDetector`] and
/// [`regression::RegressionSeverity`] collide with the unrelated types of
/// the same name in [`regression_detector`] (the crate's original,
/// still-primary regression-detection module).
pub mod regression;

// GPU profiling imports (specific to avoid conflicts)
pub use advanced_gpu_profiler::{
    AdvancedGpuMemoryProfiler, AdvancedGpuProfilingConfig, CrossDeviceTransfer,
    GpuMemoryAllocation, GpuMemoryType, HighImpactOptimization, KernelOptimizationSummaryReport,
    MemoryAnalysisReport, MemoryFragmentationSnapshot,
};

// Kernel optimization imports (specific)
pub use kernel_optimizer::{
    KernelOptimizationAnalyzer, KernelOptimizationConfig, KernelOptimizationReport,
    KernelProfileData,
};

// ============================================================================
// New Visualization and Analysis Tools (TODO.md implementations)
// ============================================================================

// TensorBoard Integration
pub use tensorboard_integration::{
    create_graph_node, tensor_to_histogram_values, GraphDef, GraphNode as TensorBoardGraphNode,
    HistogramEvent, ScalarEvent, TensorBoardWriter, TextEvent,
};

// Netron/ONNX Export
pub use netron_export::{
    AttributeValue, ExportFormat, GraphNode as NetronGraphNode, ModelGraph, ModelMetadata,
    NetronExporter, NetronModel, TensorData, TensorInfo,
};

// Activation Visualizer
pub use activation_visualizer::{
    ActivationConfig, ActivationData, ActivationHeatmap as ActivationVisualizerHeatmap,
    ActivationHistogram, ActivationStatistics, ActivationVisualizer,
};

// Attention Visualizer
pub use attention_visualizer::{
    AttentionAnalysis, AttentionFlow, AttentionHeatmap as AttentionVisualizerHeatmap,
    AttentionType, AttentionVisualizer, AttentionVisualizerConfig, AttentionWeights, ColorScheme,
};

// Stability Checker
pub use stability_checker::{
    IssueKind, StabilityChecker, StabilityConfig, StabilityIssue, StabilitySummary,
};

// Graph Visualizer
pub use graph_visualizer::{
    ComputationGraph, GraphColorScheme, GraphEdge, GraphNode as GraphVisualizerNode,
    GraphStatistics, GraphVisualizer, GraphVisualizerConfig, LayoutDirection,
};

// Unified Debug Session Manager
pub use unified_debug_session::{SessionSummary, UnifiedDebugSession, UnifiedDebugSessionConfig};

// Weight Analyzer
pub use weight_analyzer::{
    InitializationScheme, WeightAnalysis, WeightAnalyzer, WeightAnalyzerConfig, WeightHistogram,
    WeightStatistics,
};

// MLflow Integration
pub use mlflow_integration::{
    ArtifactType, MLflowClient, MLflowConfig, MLflowDebugSession, MetricPoint, RunInfo, RunStatus,
    TrackingMode,
};

// Visualization Plugin System
pub use visualization_plugins::{
    OutputFormat as PluginOutputFormat, PluginConfig, PluginManager, PluginMetadata, PluginResult,
    VisualizationData, VisualizationPlugin,
};

// Performance Tuning
pub use performance_tuning::{
    Difficulty, HardwareType, ImpactEstimate, PerformanceSnapshot,
    PerformanceSummary as TuningPerformanceSummary, PerformanceTuner, Priority, Recommendation,
    RecommendationCategory, TunerConfig, TuningReport,
};

// ============================================================================
// Module Re-exports
// ============================================================================
//
// ⚠️  TYPE NAME CONFLICTS (Documented for clarity):
// The following types are defined in multiple modules. The LAST import wins in Rust.
// If you need a specific version, import directly from the module:
//
// - `LRScheduleType`: defined in `training_dynamics` (PRIMARY) and `advanced_ml_debugging`
//   → Use `training_dynamics::LRScheduleType` for training schedules
//   → Use `advanced_ml_debugging::LRScheduleType` for ML debugging contexts
//
// - `RiskLevel`: defined in `llm_debugging` (PRIMARY) and `advanced_ml_debugging`
//   → Use `llm_debugging::RiskLevel` for LLM safety analysis
//   → Use `advanced_ml_debugging::RiskLevel` for general ML risk assessment
//
// - `InteractionType`: defined in `simulation_tools` (PRIMARY) and `advanced_ml_debugging`
//   → Use `simulation_tools::InteractionType` for simulation interactions
//   → Use `advanced_ml_debugging::InteractionType` for ML component interactions
//
// - `BottleneckType`: defined in `profiler` (PRIMARY) and `advanced_ml_debugging`
//   → Use `profiler::BottleneckType` for performance bottlenecks
//   → Use `advanced_ml_debugging::BottleneckType` for ML-specific bottlenecks
//
// - `FeatureSensitivityAnalysis`: defined in `simulation_tools` (PRIMARY) and `advanced_ml_debugging`
//   → Use `simulation_tools::FeatureSensitivityAnalysis` for simulation feature analysis
//   → Use `advanced_ml_debugging::FeatureSensitivityAnalysis` for ML feature analysis
//
// - `RobustnessAssessment`: defined in `simulation_tools` (PRIMARY) and `advanced_ml_debugging`
//   → Use `simulation_tools::RobustnessAssessment` for simulation robustness
//   → Use `advanced_ml_debugging::RobustnessAssessment` for ML robustness
//
// - `PatternType`: defined in `memory_profiler` (PRIMARY) and `ai_code_analyzer`
//   → Use `memory_profiler::PatternType` for memory allocation patterns
//   → Use `ai_code_analyzer::PatternType` for code patterns
//
// - `IssueType`: defined in `auto_debugger` (PRIMARY) and `ai_code_analyzer`
//   → Use `auto_debugger::IssueType` for debugging issues
//   → Use `ai_code_analyzer::IssueType` for code analysis issues
//
// ============================================================================

// Primary exports (order determines which type wins for ambiguous names)
// Note: New visualization modules are explicitly imported above to avoid conflicts
pub use advanced_ml_debugging::*;
pub use ai_code_analyzer::*;
pub use anomaly_detector::*;
pub use architecture_analysis::*;
pub use auto_debugger::*;
pub use behavior_analysis::*;
pub use cicd_integration::*;
pub use collaboration::*;
pub use computation_graph::*;
pub use dashboard::*;
pub use data_export::*;
pub use differential_debugging::*;
pub use distributed_debugger::*;
pub use distributed_profiling::*;
pub use environmental_monitor::*;
pub use error_recovery::*;
pub use flame_graph_profiler::*;
pub use gradient_debugger::*;
pub use health_checker::*;
pub use hooks::*;
pub use ide_integration::*;
pub use interactive_debugger::*;
pub use large_model_viz::*;
pub use llm_debugging::*;
pub use memory_profiler::*;
pub use model_diagnostics::*;
pub use neural_network_debugging::*;
pub use profiler::*;
pub use quantum_debugging::*;
pub use realtime_dashboard::{AlertSeverity as DashboardAlertSeverity, *};
pub use regression_detector::*;
pub use report_generation::*;
pub use simulation_tools::*;
pub use streaming_debugger::*;
pub use team_dashboard::*;
pub use tensor_inspector::*;
pub use training_dynamics::*; // LRScheduleType from here is PRIMARY
pub use utilities::*;
pub use visualization::*;
#[cfg(feature = "wasm")]
pub use wasm_interface::*;

use scirs2_core::ndarray::ArrayD; // SciRS2 Integration Policy

// ============================================================================
// NEW MODULAR ARCHITECTURE
// ============================================================================

/// Core debugging session and configuration management
pub mod core;

/// Simplified debugging interface with one-line functions
pub mod interface;

/// Guided debugging system with step-by-step workflows
pub mod guided;

/// Interactive tutorial and learning system
pub mod tutorial;

/// Context-aware help system
pub mod help;

/// Performance optimization system for production debugging
pub mod performance;

// Re-export all public items from modules for backward compatibility
pub use core::*;
pub use guided::*;
pub use help::*;
pub use interface::*;
pub use performance::*;
pub use tutorial::*;

// Interpretability types (real implementations from interpretability_tools module)
pub use interpretability_tools::{
    InterpretabilityAnalyzer, InterpretabilityConfig, InterpretabilityReport,
};