|
| 1 | +"""Defines the command line for the export with ExecuTorch.""" |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | +from typing import TYPE_CHECKING |
| 5 | + |
| 6 | +from ...exporters import TasksManager |
| 7 | +from ..base import BaseOptimumCLICommand |
| 8 | + |
| 9 | + |
| 10 | +if TYPE_CHECKING: |
| 11 | + from argparse import ArgumentParser |
| 12 | + |
| 13 | + |
| 14 | +def parse_args_executorch(parser): |
| 15 | + required_group = parser.add_argument_group("Required arguments") |
| 16 | + required_group.add_argument( |
| 17 | + "-m", "--model", type=str, required=True, help="Model ID on huggingface.co or path on disk to load model from." |
| 18 | + ) |
| 19 | + required_group.add_argument( |
| 20 | + "-o", |
| 21 | + "--output_dir", |
| 22 | + type=Path, |
| 23 | + help="Path indicating the directory where to store the generated ExecuTorch model.", |
| 24 | + ) |
| 25 | + required_group.add_argument( |
| 26 | + "--task", |
| 27 | + type=str, |
| 28 | + default="text-generation", |
| 29 | + help=( |
| 30 | + "The task to export the model for. Available tasks depend on the model, but are among:" |
| 31 | + f" {str(TasksManager.get_all_tasks())}." |
| 32 | + ), |
| 33 | + ) |
| 34 | + required_group.add_argument( |
| 35 | + "--recipe", |
| 36 | + type=str, |
| 37 | + default="xnnpack", |
| 38 | + help='Pre-defined recipes for export to ExecuTorch. Defaults to "xnnpack".', |
| 39 | + ) |
| 40 | + |
| 41 | + |
| 42 | +class ExecuTorchExportCommand(BaseOptimumCLICommand): |
| 43 | + @staticmethod |
| 44 | + def parse_args(parser: "ArgumentParser"): |
| 45 | + return parse_args_executorch(parser) |
| 46 | + |
| 47 | + def run(self): |
| 48 | + from ...exporters.executorch import main_export |
| 49 | + |
| 50 | + main_export( |
| 51 | + model_name_or_path=self.args.model, |
| 52 | + task=self.args.task, |
| 53 | + recipe=self.args.recipe, |
| 54 | + output_dir=self.args.output_dir, |
| 55 | + ) |
0 commit comments