Expand description
§ToRSh Utilities
torsh-utils provides essential utility functions and tools for the ToRSh deep learning framework.
This crate contains functionality for development, deployment, profiling, and model management.
§Features
§🔧 Development Tools
- Benchmarking: Comprehensive model performance analysis with timing and memory tracking
- Profiling: Advanced bottleneck detection with flame graphs, memory profiling, and GPU analysis
- Environment Collection: System and framework information gathering for debugging
§📊 Monitoring & Visualization
- TensorBoard Integration: Compatible logging for training metrics, histograms, and graphs
- Interactive Visualizations: D3.js-based model architecture visualization
- Real-time Monitoring: Live performance metrics and memory tracking
§🚀 Deployment Tools
- Mobile Optimization: Model compression, quantization, and platform-specific optimizations
- C++ Extensions: Build custom CUDA kernels and operations
- Model Zoo: Pre-trained model management with HuggingFace Hub integration
§Quick Start
Add to your Cargo.toml:
[dependencies]
torsh-utils = { version = "0.1.1", features = ["tensorboard", "collect_env"] }§Basic Usage Examples
§Benchmarking a Model
use torsh_utils::prelude::*;
// Configure benchmarking
let config = BenchmarkConfig {
warmup_iterations: 10,
benchmark_iterations: 100,
batch_sizes: vec![1, 8, 16, 32],
input_shapes: vec![vec![3, 224, 224]],
profile_memory: true,
..Default::default()
};
// Benchmark your model (model would be your actual neural network)
// let model = MyModel::new();
// let results = benchmark_model(&model, config)?;
// print_benchmark_results(&results);§Profiling Bottlenecks
use torsh_utils::prelude::*;
// Profile model performance
// let model = MyModel::new();
// let report = profile_bottlenecks(
// &model,
// &[1, 3, 224, 224],
// 100,
// true // profile backward pass
// )?;
//
// // Print recommendations
// print_bottleneck_report(&report);§TensorBoard Logging
use torsh_utils::prelude::*;
let mut writer = SummaryWriter::new("runs/experiment1")?;
// Log training metrics
for epoch in 0..10 {
let loss = 0.5 / (epoch + 1) as f32; // Example loss
writer.add_scalar("loss/train", loss, Some(epoch as i64))?;
}§Mobile Optimization
use torsh_utils::prelude::*;
// Configure mobile optimization
let config = MobileOptimizerConfig {
quantize: true,
fuse_ops: true,
remove_dropout: true,
fold_bn: true,
backend: MobileBackend::Cpu,
..Default::default()
};
// Optimize model for mobile (model would be your actual neural network)
// let optimized = optimize_for_mobile(&model, config)?;§Model Zoo Usage
use torsh_utils::prelude::*;
// Create model zoo
let mut zoo = ModelZoo::new("~/.torsh/models")?;
// Search for models
// let models = zoo.search_models("resnet", Some(ModelSearchQuery::new()))?;
// Download a model
// let model_info = zoo.download_model("resnet50-imagenet", None)?;§Module Overview
benchmark: Model performance benchmarking with comprehensive metricsbottleneck: Advanced profiling for performance bottleneck detectioncollect_env: System and environment information collectioncpp_extension: C++ and CUDA extension building utilitiesmobile_optimizer: Mobile deployment optimization toolsmodel_zoo: Pre-trained model repository and managementtensorboard: TensorBoard-compatible logging and visualization
§Feature Flags
tensorboard(default): Enable TensorBoard integrationcollect_env(default): Enable environment information collection
§Architecture
This crate is designed to work seamlessly with the ToRSh ecosystem:
- Integrates with
torsh-corefor device abstraction - Uses
torsh-tensorfor tensor operations - Compatible with
torsh-nnfor neural network modules - Leverages
torsh-profilerfor performance profiling
§Best Practices
- Benchmarking: Always use warmup iterations to avoid cold start overhead
- Profiling: Profile with representative workloads
- Mobile Optimization: Test on actual target devices
- TensorBoard: Use meaningful tag names for easier analysis
- Model Zoo: Verify checksums for downloaded models
§PyTorch Migration
For users migrating from PyTorch:
SummaryWriteris compatible withtorch.utils.tensorboard.SummaryWriterbenchmark_modelprovides similar functionality totorch.utils.benchmark- Mobile optimization is similar to
torch.utils.mobile_optimizer
§Examples
See the examples/ directory for complete working examples:
benchmark_model.rs: Complete benchmarking workflowprofile_bottlenecks.rs: Performance profiling examplemobile_optimization.rs: Model optimization for mobile deploymenttensorboard_logging.rs: Training visualization with TensorBoard
Modules§
- benchmark
- Model Performance Benchmarking
- bottleneck
- Advanced Performance Bottleneck Profiling
- collect_
env - Environment Information Collection
- cpp_
extension - C++ Extension utilities for ToRSh
- mobile_
optimizer - Auto-generated module structure
- model_
zoo - Auto-generated module structure
- prelude
- Re-export commonly used items for convenience.
- tensorboard
- Auto-generated module structure