diffai
๐ค AI/ML specialized diff tool - Focus on model changes, not formatting noise
English README | ๆฅๆฌ่ช็ README
A next-generation diff tool specialized for AI/ML workflows that understands model structures, tensor statistics, and experiment data - not just text changes. Perfect for PyTorch, Safetensors, JSON configs, and structured data.
# Traditional diff can't understand model structure
# diffai shows semantic model changes
โจ Key Features
- ๐ง AI/ML Specialized: Native support for PyTorch (.pt/.pth) and Safetensors (.safetensors) models
- ๐ Tensor Analysis: Automatic calculation of tensor statistics (mean, std, min, max, shape)
- ๐ฅ Advanced Analytics: Layer impact analysis, quantization analysis, change magnitude sorting
- ๐ ML Statistics: Detailed model statistics with
--stats
flag - ๐ง Multiple Formats: JSON, YAML, TOML, XML, INI, CSV support (inherited from diffx)
- ๐ค MLOps Friendly: Clean CLI output perfect for automation and CI/CD pipelines
- โก Fast: Built in Rust for maximum performance with large model files
- ๐ฏ Semantic Awareness: Focuses on meaningful changes, ignores formatting noise
๐ Why diffai over generic diff tools?
Traditional diff tools fail with AI/ML workflows:
Challenge | Traditional Tools | diffai |
---|---|---|
Binary model files | "Binary files differ" ๐ซ | Tensor-level analysis โ |
Large files (GB+) | Memory issues ๐ซ | Efficient streaming โ |
Statistical changes | No insight ๐ซ | Mean/std/shape comparison โ |
ML-specific formats | No support ๐ซ | Native PyTorch/Safetensors โ |
Experiment tracking | Manual work ๐ซ | Automated analysis โ |
๐ Real-World Use Cases
๐ฌ Model Development
# Compare before/after fine-tuning
# Analyze quantization impact
# Track training progress
๐ MLOps & Production
# CI/CD model validation
# A/B testing preparation
# Experiment configuration tracking
๐ Research & Experimentation
# Architecture comparison
# Hyperparameter impact analysis
# Data drift detection in model weights
๐ฅ Advanced Analytics Features
# Layer-by-layer impact analysis
# Quantization analysis for model optimization
# Sort changes by magnitude (biggest changes first)
# Detailed statistics and model analysis
# Combined advanced analysis
๐๏ธ Architecture
System Overview
graph TB
subgraph Core["diffai-core"]
B[Format Parsers]
C[Semantic Diff Engine]
D[ML Model Analyzer]
E[Output Formatters]
B --> C
D --> C
C --> E
end
F[CLI Tool] --> Core
subgraph Formats["Input Formats"]
H[PyTorch .pt/.pth]
I[Safetensors .safetensors]
J[JSON/YAML/TOML]
K[XML/INI/CSV]
end
Formats --> B
I --> D
subgraph Output["Output Formats"]
L[CLI Display with AI symbols]
M[JSON Output]
N[YAML Output]
end
E --> Output
Project Structure
diffai/
โโโ diffai-core/ # Core diff library with ML support
โโโ diffai-cli/ # CLI wrapper
โโโ tests/ # Comprehensive test suite
โ โโโ fixtures/ # Test data including ML models
โ โโโ integration/ # CLI integration tests
โ โโโ unit/ # Core library unit tests
โ โโโ output/ # Test intermediate files
โโโ docs/ # AI/ML focused documentation
โโโ examples/ # Real-world ML use cases
โโโ scripts/ # Model generation utilities
Technology Stack
- Rust (Fast, safe, memory-efficient for large models)
- AI/ML:
candle-core
,safetensors
,bytemuck
for tensor processing - Parsers:
serde_json
,serde_yml
,toml
,quick-xml
,csv
- CLI:
clap
(argument parsing),colored
(AI-friendly output)
๐ Quick Start
Installation
# Install from crates.io
# Or build from source
Basic Usage
# Compare ML model files
# Compare with different output formats
# Advanced ML-specific options
# Directory comparison for experiment tracking
ML Model Analysis Examples
# Fine-tuning analysis
# Output:
# ๐ tensor.transformer.h.0.attn.weight: mean=0.0023โ0.0156, std=0.0891โ0.1234
# โฌ tensor.classifier.weight: [768, 1000] -> [768, 10]
# Quantization impact assessment
# Output:
# ๐ tensor.conv1.weight: mean=0.0045โ0.0043, std=0.2341โ0.2298
# No differences found (within epsilon tolerance)
# Training checkpoint progression
# Output:
# ๐ tensor.layers.0.weight: mean=-0.0012โ0.0034, std=1.2341โ0.8907
# ๐ tensor.layers.1.bias: mean=0.1234โ0.0567, std=0.4567โ0.3210
๐ Integration Examples
CI/CD Pipeline
name: Model Validation
on:
jobs:
model-diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install diffai
run: cargo install diffai
- name: Compare model changes
run: |
diffai models/baseline.safetensors models/candidate.safetensors \
--output json > model_diff.json
# Process model_diff.json for deployment decisions
MLflow Integration
=
=
# Log model comparison to MLflow
Pre-commit Hook
#!/bin/bash
# .git/hooks/pre-commit
if | ; then
if ; then
fi
fi
๐ฏ Relationship to diffx
diffai
is a specialized fork of the diffx
project, inheriting its robust structured data comparison capabilities while adding AI/ML-specific features:
Inherited from diffx
- โ Semantic diff for JSON, YAML, TOML, XML, INI, CSV
- โ Format auto-detection from file extensions
- โ Multiple output formats (CLI, JSON, YAML, Unified)
- โ Advanced filtering (regex, path-based, epsilon tolerance)
- โ Directory comparison with recursive traversal
Added for AI/ML
- ๐ PyTorch model support (.pt, .pth files)
- ๐ Safetensors support (.safetensors files)
- ๐ Tensor statistics (mean, std, min, max, shape, dtype)
- ๐ ML-friendly CLI output with specialized symbols
- ๐ Model architecture analysis (layer counts, parameter counts)
- ๐ Future: Integration with MLOps tools, experiment tracking
๐ฎ Roadmap
Phase 1: Core ML Features โ COMPLETED
- โ PyTorch/Safetensors file parsing
- โ Tensor shape and statistics comparison
- โ AI-friendly CLI output with symbols
Phase 2: Experiment Analysis (Next)
- ๐ Hyperparameter comparison from JSON/YAML configs
- ๐ Learning curve analysis from training logs
- ๐ Statistical significance testing for metric changes
Phase 3: MLOps Integration
- ๐ MLflow integration for automatic experiment comparison
- ๐ Weights & Biases export functionality
- ๐ DVC compatibility for data/model versioning
Phase 4: Advanced Analytics
- ๐ Gradient analysis for training debugging
- ๐ Attention pattern comparison for transformer models
- ๐ Embedding space analysis for representation learning
๐ Documentation
For comprehensive documentation, see our docs directory:
- Installation Guide - Setup for various environments
- Basic Usage - Command reference and examples
- ML Workflows - Integration with ML development
- Architecture - Design principles and architecture
๐ค Contributing
We welcome contributions from the AI/ML community! See CONTRIBUTING.md for guidelines.
Areas where we need help:
- ๐ง Additional ML framework support (TensorFlow, ONNX, JAX)
- ๐ Advanced statistical analysis features
- ๐ง MLOps tool integrations
- ๐ Documentation and examples
- ๐งช Testing with real-world models
๐ Community
- GitHub Discussions: Share use cases and get help
- Issues: Report bugs or request features
- Pull Requests: Contribute code or documentation
๐ License
MIT License - see LICENSE for details.
Built with โค๏ธ for the AI/ML community. Inspired by the need for better model comparison tools in modern ML workflows.