converting-pytorch-to-litert
Converts PyTorch models (e.g. ResNet, timm, HuggingFace transformers) directly to LiteRT (.tflite) flatbuffer format. Use when converting PyTorch models to TFLite, setting up export environments, or troubleshooting torch-to-litert conversion bugs. Don't use for ONNX exports or converting existing TensorFlow models.
适合你,如果需要在移动设备上部署 PyTorch 模型
npx oh-my-skill add google-ai-edge/litert-torch/converting-pytorch-to-litertcurl -fsSL https://oh-my-skill.com/install.sh | bash -s -- google-ai-edge/litert-torch/converting-pytorch-to-litertnpx oh-my-skill verify google-ai-edge/litert-torch/converting-pytorch-to-litert怎么用
商店整理自技能原文 · 版本 677fe70 · 表述以原文为准安装后,Claude 可以将 PyTorch 模型(如 ResNet、HuggingFace transformers)直接转换为 LiteRT (.tflite) 格式,跳过 ONNX 中间步骤。
当你要求将 PyTorch 模型转换为 TFLite 格式,或遇到转换错误时触发。
技能原文 SKILL.md
PyTorch to LiteRT Conversion Guide
ATTENTION ALL AGENTS: If you are tasked with converting a PyTorch model (e.g., ResNet or similar architectures) to a .tflite flatbuffer format in this repository, you must strictly follow these rules based on recent project findings:
1. Direct Conversion Only (No ONNX)
Bypass ONNX entirely. Do not attempt to export the model to ONNX or use onnx2tf. Convert directly from PyTorch to LiteRT.
2. Use litert-torch
Use the litert-torch library for the direct PyTorch to TFLite conversion. Note that ai-edge-torch is deprecated and has been officially renamed to litert-torch.
3. Strict Python Environment Rules
- Do NOT use Python 3.14. It currently has compatibility issues with typing in
torchao(AttributeError: 'typing.Union' object has no attribute '__module__'). - Use Python 3.11 (e.g.,
python3.11) as it is highly recommended for stability and avoids the aforementioned type hint bugs.
4. Dependencies
Before running any conversion script, ensure the following are installed in your python3.11 environment:
python3.11 -m pip install torch transformers timm litert-torch ai-edge-litert litert-cli-nightly