torsh-package
Model packaging and distribution system for the ToRSh deep learning framework.
Overview
torsh-package provides functionality similar to PyTorch's torch.package for creating self-contained model packages that include code, weights, dependencies, and metadata. This enables easy model distribution, deployment, and reproducibility across different environments.
Features
- Self-contained Packages: Bundle models with code, weights, and dependencies
- Version Management: Package versioning with compatibility tracking
- Resource Management: Efficient storage and retrieval of model assets
- Metadata Tracking: Comprehensive manifest with dependency information
- Cross-platform: Platform-independent package format
- Incremental Updates: Support for package updates and patches
Modules
exporter: Package creation and export functionalityimporter: Package loading and import functionalitymanifest: Package metadata and dependency managementresources: Resource storage and retrieval systemversion: Package versioning and compatibility
Usage
Creating a Package
use *;
use Module;
// Create package exporter
let config = ExportConfig ;
let mut exporter = new;
// Add model to package
exporter.add_model?;
// Add additional resources
exporter.add_resource?;
exporter.add_resource?;
// Export package
exporter.export_to_file?;
Loading a Package
use *;
// Load package
let package = load?;
// Get model from package
let model = package.get_model?;
// Get additional resources
let config = package.get_resource?;
let preprocess_code = package.get_resource?;
// Check package metadata
println!;
println!;
println!;
Package Information
use *;
// Load package without extracting
let package_info = inspect?;
println!;
println!;
println!;
println!;
println!;
println!;
Version Management
use *;
// Check version compatibility
let package_version = parse?;
let required_version = parse?;
if package_version.satisfies else
// Update package
let mut updater = new?;
updater.update_model?;
updater.increment_version?;
updater.save?;
Resource Types
use *;
// Supported resource types
let resources = vec!;
for in resources
Package Format
The torsh-package format uses a structured archive containing:
package.torsh
├── manifest.json # Package metadata and dependency info
├── models/ # Model weights and architectures
│ └── my_model.safetensors
├── code/ # Python/Rust code files
│ └── preprocessing.py
├── resources/ # Additional resources
│ ├── config.json
│ └── tokenizer.json
└── metadata/ # Version and compatibility info
└── package.info
Advanced Features
Incremental Updates
use *;
// Create incremental update
let patch = new?
.update_model?
.add_resource?
.remove_resource?;
// Apply patch
patch.save_as_patch?;
// Apply patch to existing package
let updated_package = load?
.apply_patch?;
Dependency Management
use *;
// Specify dependencies
let dependencies = new
.add_torsh_version?
.add_python_package?
.add_python_package?
.add_system_requirement?;
exporter.set_dependencies?;
Dependencies
torsh-core: Core types and error handlingtorsh-nn: Neural network modulesserde: Serialization supportzip: Archive compression and extractionchrono: Date and time handlingsemver: Semantic versioning
Performance
torsh-package is optimized for:
- Fast package creation with streaming compression
- Lazy loading of resources to minimize memory usage
- Efficient delta updates for large models
- Parallel compression and decompression
Compatibility
- PyTorch: Compatible with torch.package format (import/export)
- HuggingFace: Integration with HuggingFace Hub model format
- ONNX: Support for ONNX model packaging
- MLflow: Integration with MLflow model registry
Security
- Package integrity verification with checksums
- Code signing support for trusted packages
- Sandboxed execution environment for untrusted code
- Dependency vulnerability scanning
Examples
See the examples/ directory for:
- Complete model packaging workflows
- Package distribution and deployment
- Version management and updates
- Integration with model registries