.pte format for use in React Native applications.
Overview
Migrating models to ExecuTorch involves:- Preparing your PyTorch model
- Exporting to ATEN dialect
- Converting to Edge dialect
- Applying optimizations (quantization, backend delegation)
- Generating the final
.ptefile - Testing and validation
Prerequisites
Install ExecuTorch and dependencies:Basic Migration Workflow
Step 1: Prepare Your Model
Start with a PyTorch model in evaluation mode:Step 2: Create Example Inputs
Define representative inputs matching your model’s expected format:Step 3: Export to ATEN Dialect
Step 4: Convert to Edge Dialect
Step 5: Generate .pte File
Complete Example: Image Classification
Here’s a complete example for a ResNet model:Migrating Hugging Face Models
Using optimum-executorch
The easiest way to export Hugging Face models:Supported Task Types
Manual Hugging Face Export
For more control:Adding Optimizations
Quantization
Reduce model size and improve speed:Backend Delegation (XNNPACK)
Core ML Backend (iOS)
Combined: Quantization + XNNPACK
Handling Dynamic Shapes
For models that accept variable input sizes:Testing Exported Models
Validate with Python
Test your.pte file before using in React Native:
Compare with Original Model
Common Migration Issues
Unsupported Operations
Problem: Model contains ops not supported by ExecuTorch Solution:Shape Inference Errors
Problem: Dynamic shapes cause issues Solution: Use explicit dynamic shape constraints or static shapes:Memory Issues During Export
Problem: Large model causes OOM during export Solution:Model-Specific Migration Guides
Vision Models (ResNet, EfficientNet, MobileNet)
Object Detection Models
Text Models (BERT, GPT)
Using Migrated Models in React Native
Once you have your.pte file:
Best Practices
- Test Before Migrating: Ensure your PyTorch model works correctly
- Use Representative Inputs: Example inputs should match real usage
- Validate Outputs: Compare exported model with original
- Start Simple: Test basic export before adding optimizations
- Quantize for Production: Use quantization to reduce size and improve speed
- Check Operator Support: Verify all ops are supported before export
- Document Your Process: Keep export scripts for reproducibility
- Version Control Models: Track model versions and export configs
Next Steps
- Learn about Performance Optimization
- Review Custom Models guide
- Check Debugging for troubleshooting
- See ExecuTorch Export Tutorial