trustformers_debug/utilities/
mod.rs1pub mod health;
11pub mod performance;
12pub mod tensor_analysis;
13pub mod weight_analysis;
14
15pub use health::*;
17pub use performance::*;
18pub use tensor_analysis::*;
19pub use weight_analysis::*;
20
21use anyhow::Result;
22use scirs2_core::ndarray; pub struct DebugUtils;
26
27impl DebugUtils {
28 pub async fn quick_health_check<T>(model: &T) -> Result<HealthCheckResult> {
30 HealthChecker::quick_health_check(model).await
31 }
32
33 pub fn score_to_status(score: f64) -> String {
35 HealthChecker::score_to_status(score)
36 }
37
38 pub fn generate_debug_summary(
40 config: &crate::DebugConfig,
41 results: &[crate::SimplifiedDebugResult],
42 ) -> DebugSummary {
43 HealthChecker::generate_debug_summary(config, results)
44 }
45
46 pub async fn export_debug_data(
48 session: &crate::DebugSession,
49 format: ExportFormat,
50 output_path: &str,
51 ) -> Result<String> {
52 HealthChecker::export_debug_data(session, format, output_path).await
53 }
54
55 pub fn create_debug_template(template_type: DebugTemplate) -> crate::DebugConfig {
57 HealthChecker::create_debug_template(template_type)
58 }
59
60 pub fn analyze_tensors_batch(tensors: &[ndarray::ArrayD<f32>]) -> Result<BatchTensorAnalysis> {
62 TensorAnalyzer::analyze_tensors_batch(tensors)
63 }
64
65 pub fn compute_tensor_statistics(tensor: &ndarray::ArrayD<f32>) -> Result<TensorStatistics> {
67 TensorAnalyzer::compute_tensor_statistics(tensor)
68 }
69
70 pub fn detect_tensor_anomalies(stats: &TensorStatistics) -> Vec<TensorAnomaly> {
72 TensorAnalyzer::detect_tensor_anomalies(stats)
73 }
74
75 pub fn compare_tensors(
77 baseline: &ndarray::ArrayD<f32>,
78 current: &ndarray::ArrayD<f32>,
79 ) -> Result<TensorComparisonResult> {
80 TensorAnalyzer::compare_tensors(baseline, current)
81 }
82
83 pub fn hash_config(config: &crate::DebugConfig) -> String {
85 use std::collections::hash_map::DefaultHasher;
86 use std::hash::{Hash, Hasher};
87
88 let mut hasher = DefaultHasher::new();
89 format!("{:?}", config).hash(&mut hasher);
90 format!("{:x}", hasher.finish())
91 }
92}
93
94#[macro_export]
96macro_rules! debug_tensor {
97 ($session:expr, $tensor:expr, $name:expr) => {
98 $session.debug_tensor($tensor, $name)
99 };
100 ($tensor:expr) => {
101 trustformers_debug::utilities::TensorAnalyzer::compute_tensor_statistics($tensor)
102 };
103}
104
105#[macro_export]
106macro_rules! debug_gradient {
107 ($session:expr, $layer_name:expr, $gradients:expr) => {
108 $session.debug_gradients($layer_name, $gradients)
109 };
110}
111
112#[macro_export]
113macro_rules! quick_debug {
114 ($model:expr, $level:expr) => {
115 trustformers_debug::quick_debug($model, $level).await
116 };
117}
118
119#[macro_export]
120macro_rules! perf_checkpoint {
121 ($monitor:expr, $name:expr) => {
122 $monitor.checkpoint($name)
123 };
124}
125
126#[macro_export]
127macro_rules! perf_end_checkpoint {
128 ($monitor:expr, $name:expr) => {
129 $monitor.end_checkpoint($name)
130 };
131}