pub mod health;
pub mod performance;
pub mod tensor_analysis;
pub mod weight_analysis;
pub use health::*;
pub use performance::*;
pub use tensor_analysis::*;
pub use weight_analysis::*;
use anyhow::Result;
use scirs2_core::ndarray;
pub struct DebugUtils;
impl DebugUtils {
pub async fn quick_health_check<T>(model: &T) -> Result<HealthCheckResult> {
HealthChecker::quick_health_check(model).await
}
pub fn score_to_status(score: f64) -> String {
HealthChecker::score_to_status(score)
}
pub fn generate_debug_summary(
config: &crate::DebugConfig,
results: &[crate::SimplifiedDebugResult],
) -> DebugSummary {
HealthChecker::generate_debug_summary(config, results)
}
pub async fn export_debug_data(
session: &crate::DebugSession,
format: ExportFormat,
output_path: &str,
) -> Result<String> {
HealthChecker::export_debug_data(session, format, output_path).await
}
pub fn create_debug_template(template_type: DebugTemplate) -> crate::DebugConfig {
HealthChecker::create_debug_template(template_type)
}
pub fn analyze_tensors_batch(tensors: &[ndarray::ArrayD<f32>]) -> Result<BatchTensorAnalysis> {
TensorAnalyzer::analyze_tensors_batch(tensors)
}
pub fn compute_tensor_statistics(tensor: &ndarray::ArrayD<f32>) -> Result<TensorStatistics> {
TensorAnalyzer::compute_tensor_statistics(tensor)
}
pub fn detect_tensor_anomalies(stats: &TensorStatistics) -> Vec<TensorAnomaly> {
TensorAnalyzer::detect_tensor_anomalies(stats)
}
pub fn compare_tensors(
baseline: &ndarray::ArrayD<f32>,
current: &ndarray::ArrayD<f32>,
) -> Result<TensorComparisonResult> {
TensorAnalyzer::compare_tensors(baseline, current)
}
pub fn hash_config(config: &crate::DebugConfig) -> String {
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
let mut hasher = DefaultHasher::new();
format!("{:?}", config).hash(&mut hasher);
format!("{:x}", hasher.finish())
}
}
#[macro_export]
macro_rules! debug_tensor {
($session:expr, $tensor:expr, $name:expr) => {
$session.debug_tensor($tensor, $name)
};
($tensor:expr) => {
trustformers_debug::utilities::TensorAnalyzer::compute_tensor_statistics($tensor)
};
}
#[macro_export]
macro_rules! debug_gradient {
($session:expr, $layer_name:expr, $gradients:expr) => {
$session.debug_gradients($layer_name, $gradients)
};
}
#[macro_export]
macro_rules! quick_debug {
($model:expr, $level:expr) => {
trustformers_debug::quick_debug($model, $level).await
};
}
#[macro_export]
macro_rules! perf_checkpoint {
($monitor:expr, $name:expr) => {
$monitor.checkpoint($name)
};
}
#[macro_export]
macro_rules! perf_end_checkpoint {
($monitor:expr, $name:expr) => {
$monitor.end_checkpoint($name)
};
}