AgentSkillsCN

export

将 PyTorch 模型导出为 ExecuTorch 的 .pte 格式。当您需要转换模型、将其部署至边缘设备,或生成 .pte 文件时,可使用此技能。

SKILL.md
--- frontmatter
name: export
description: Export a PyTorch model to .pte format for ExecuTorch. Use when converting models, lowering to edge, or generating .pte files.

Export

Basic pattern

python
from executorch.exir import to_edge_transform_and_lower
from torch.export import export

exported = export(model.eval(), example_inputs)
edge = to_edge_transform_and_lower(exported)
with open("model.pte", "wb") as f:
    f.write(edge.to_executorch().buffer)

Model-specific scripts

ModelScript
Llamaexamples/models/llama/export_llama.py
Whisperexamples/models/whisper/
Parakeetexamples/models/parakeet/export_parakeet_tdt.py

Debugging

  • Draft export: export(model, inputs, strict=False)
  • tlparse: TORCH_LOGS="+dynamo,+export" python script.py 2>&1 | tlparse