diffai
AI/ML specialized diff tool for PyTorch, Safetensors, NumPy, and MATLAB files
A next-generation diff tool specialized for AI/ML and scientific computing workflows that understands model structures, tensor statistics, and numerical data - not just text changes. Native support for PyTorch, Safetensors, NumPy arrays, MATLAB files, and structured data.
# Traditional diff fails with binary model files
# diffai shows meaningful model changes with full analysis
)
)
Key Features
- AI/ML Native: Direct support for PyTorch (.pt/.pth), Safetensors (.safetensors), NumPy (.npy/.npz), and MATLAB (.mat) files
- Tensor Analysis: Automatic calculation of tensor statistics (mean, std, min, max, shape, memory usage)
- Comprehensive ML Analysis: 30+ analysis functions including quantization, architecture, memory, convergence, anomaly detection, and deployment readiness - all enabled by default
- Scientific Data Support: NumPy arrays and MATLAB matrices with complex number support
- Pure Rust Implementation: No system dependencies, works on Windows/Linux/macOS without additional installations
- Multiple Output Formats: Colored CLI, JSON for MLOps integration, YAML for human-readable reports
- Fast and Memory Efficient: Built in Rust for handling large model files efficiently
Why diffai?
Traditional diff tools are inadequate for AI/ML workflows:
Challenge | Traditional Tools | diffai |
---|---|---|
Binary model files | "Binary files differ" | Tensor-level analysis with statistics |
Large files (GB+) | Memory issues or failures | Efficient streaming and chunked processing |
Statistical changes | No semantic understanding | Mean/std/shape comparison with significance |
ML-specific formats | No support | Native PyTorch/Safetensors/NumPy/MATLAB |
Scientific workflows | Text-only comparison | Numerical array analysis and visualization |
diffai vs MLOps Tools
diffai complements existing MLOps tools by focusing on structural comparison rather than experiment management:
Aspect | diffai | MLflow / DVC / ModelDB |
---|---|---|
Focus | "Making incomparable things comparable" | Systematization, reproducibility, CI/CD integration |
Data Assumption | Unknown origin files / black-box generated artifacts | Well-documented and tracked data |
Operation | Structural and visual comparison optimization | Version control and experiment tracking specialization |
Scope | Visualization of "ambiguous structures" including JSON/YAML/model files | Experiment metadata, version management, reproducibility |
Installation
From crates.io (Recommended)
From Source
Quick Start
Basic Model Comparison
# Compare PyTorch models with full analysis (default)
# Compare Safetensors with complete ML analysis
# Compare NumPy arrays
# Compare MATLAB files
ML Analysis Features
# Full ML analysis runs automatically for PyTorch/Safetensors
# Outputs: 30+ analysis types including quantization, architecture, memory, etc.
# JSON output for automation
# Detailed diagnostic information with verbose mode
# YAML output for human-readable reports
📚 Documentation
- Working Examples & Demonstrations - See diffai in action with real outputs
- API Documentation - Rust library documentation
- User Guide - Comprehensive usage guide
- ML Analysis Guide - Deep dive into ML-specific features
Supported File Formats
ML Model Formats
- Safetensors (.safetensors) - HuggingFace standard format
- PyTorch (.pt, .pth) - PyTorch model files with Candle integration
Scientific Data Formats
- NumPy (.npy, .npz) - NumPy arrays with full statistical analysis
- MATLAB (.mat) - MATLAB matrices with complex number support
Structured Data Formats
- JSON (.json) - JavaScript Object Notation
- YAML (.yaml, .yml) - YAML Ain't Markup Language
- TOML (.toml) - Tom's Obvious Minimal Language
- XML (.xml) - Extensible Markup Language
- INI (.ini) - Configuration files
- CSV (.csv) - Comma-separated values
ML Analysis Functions
Automatic Comprehensive Analysis (v0.3.4)
When comparing PyTorch or Safetensors files, diffai automatically runs 30+ ML analysis features:
Automatic Features Include:
- Statistical Analysis: Detailed tensor statistics (mean, std, min, max, shape, memory)
- Quantization Analysis: Analyze quantization effects and efficiency
- Architecture Comparison: Compare model architectures and structural changes
- Memory Analysis: Analyze memory usage and optimization opportunities
- Anomaly Detection: Detect numerical anomalies in model parameters
- Convergence Analysis: Analyze convergence patterns in model parameters
- Gradient Analysis: Analyze gradient information when available
- Deployment Readiness: Assess production deployment readiness
- Regression Testing: Automatic performance degradation detection
- Plus 20+ additional specialized features
Future Enhancements
- TensorFlow format support (.pb, .h5, SavedModel)
- ONNX format support
- Advanced visualization and charting features
Design Philosophy
diffai provides comprehensive analysis by default for ML models, eliminating choice paralysis. Users get all relevant insights without needing to remember or specify dozens of analysis flags.
Debugging and Diagnostics
Verbose Mode (--verbose
/ -v
)
Get comprehensive diagnostic information for debugging and performance analysis:
# Basic verbose output
# Verbose with structured data filtering
Verbose output includes:
- Configuration diagnostics: Format settings, filters, analysis modes
- File analysis: Paths, sizes, detected formats, processing context
- Performance metrics: Processing time, difference counts, optimization status
- Directory statistics: File counts, comparison summaries (with
--recursive
)
Example verbose output:
=== diffai verbose mode enabled ===
Configuration:
Input format: Safetensors
Output format: Cli
ML analysis: Full analysis enabled (all 30 features)
Epsilon tolerance: 0.001
File analysis:
Input 1: model1.safetensors
Input 2: model2.safetensors
Detected format: Safetensors
File 1 size: 1048576 bytes
File 2 size: 1048576 bytes
Processing results:
Total processing time: 1.234ms
Differences found: 15
ML/Scientific data analysis completed
📚 See Verbose Output Guide for detailed usage
Output Formats
CLI Output (Default)
Colored, human-readable output with intuitive symbols:
~
Changed tensors/arrays with statistical comparison+
Added tensors/arrays with metadata-
Removed tensors/arrays with metadata
JSON Output
Structured output for MLOps integration and automation:
|
YAML Output
Human-readable structured output for documentation:
Real-World Use Cases
Research & Development
# Compare model before and after fine-tuning (full analysis automatic)
# Outputs: learning_progress, convergence_analysis, parameter stats, and 27 more analyses
# Analyze architectural changes during development
# Outputs: architecture_comparison, param_efficiency_analysis, and full ML analysis
MLOps & CI/CD
# Automated model validation in CI/CD (comprehensive analysis)
# Outputs: deployment_readiness, regression_test, risk_assessment, and 27 more analyses
# Performance impact assessment with JSON output for automation
# Outputs: quantization_analysis, memory_analysis, performance_impact_estimate, etc.
Scientific Computing
# Compare NumPy experiment results
# Analyze MATLAB simulation data
# Compare compressed NumPy archives
Experiment Tracking
# Generate comprehensive reports
# A/B test analysis
Command-Line Options
Basic Options
-f, --format <FORMAT>
- Specify input file format-o, --output <OUTPUT>
- Choose output format (cli, json, yaml)-r, --recursive
- Compare directories recursively
Note: For ML models (PyTorch/Safetensors), comprehensive analysis including statistics runs automatically
Advanced Options
--path <PATH>
- Filter differences by specific path--ignore-keys-regex <REGEX>
- Ignore keys matching regex pattern--epsilon <FLOAT>
- Set tolerance for float comparisons--array-id-key <KEY>
- Specify key for array element identification--sort-by-change-magnitude
- Sort by change magnitude
Examples
Basic Tensor Comparison (Automatic)
JSON Output for Automation
{
}
Scientific Data Analysis
MATLAB File Comparison
Performance
diffai is optimized for large files and scientific workflows:
- Memory Efficient: Streaming processing for GB+ files
- Fast: Rust implementation with optimized tensor operations
- Scalable: Handles models with millions/billions of parameters
- Cross-Platform: Works on Windows, Linux, and macOS without dependencies
Contributing
We welcome contributions! Please see CONTRIBUTING for guidelines.
Development Setup
Running Tests
# Run all tests
# Run specific test categories
License
This project is licensed under the MIT License - see the LICENSE file for details.
Related Projects
- diffx - General-purpose structured data diff tool (diffai's sibling project)
- safetensors - Simple, safe way to store and distribute tensors
- PyTorch - Machine learning framework
- NumPy - Fundamental package for scientific computing with Python