-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export to ExecuTorch: Initial Integration
- Loading branch information
Guang Yang
committed
Dec 5, 2024
1 parent
7e8d857
commit 4385d25
Showing
18 changed files
with
1,042 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Defines the command line for the export with ExecuTorch.""" | ||
|
||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
from ...exporters import TasksManager | ||
from ..base import BaseOptimumCLICommand | ||
|
||
|
||
if TYPE_CHECKING: | ||
from argparse import ArgumentParser | ||
|
||
|
||
def parse_args_executorch(parser): | ||
required_group = parser.add_argument_group("Required arguments") | ||
required_group.add_argument( | ||
"-m", "--model", type=str, required=True, help="Model ID on huggingface.co or path on disk to load model from." | ||
) | ||
required_group.add_argument( | ||
"-o", | ||
"--output_dir", | ||
type=Path, | ||
help="Path indicating the directory where to store the generated ExecuTorch model.", | ||
) | ||
required_group.add_argument( | ||
"--task", | ||
type=str, | ||
default="text-generation", | ||
help=( | ||
"The task to export the model for. Available tasks depend on the model, but are among:" | ||
f" {str(TasksManager.get_all_tasks())}." | ||
), | ||
) | ||
required_group.add_argument( | ||
"--recipe", | ||
type=str, | ||
default="xnnpack", | ||
help='Pre-defined recipes for export to ExecuTorch. Defaults to "xnnpack".', | ||
) | ||
|
||
|
||
class ExecuTorchExportCommand(BaseOptimumCLICommand): | ||
@staticmethod | ||
def parse_args(parser: "ArgumentParser"): | ||
return parse_args_executorch(parser) | ||
|
||
def run(self): | ||
from ...exporters.executorch import main_export | ||
|
||
main_export( | ||
model_name_or_path=self.args.model, | ||
task=self.args.task, | ||
recipe=self.args.recipe, | ||
output_dir=self.args.output_dir, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from typing import TYPE_CHECKING | ||
from transformers.utils import _LazyModule | ||
|
||
|
||
_import_structure = { | ||
"modeling_executorch": [ | ||
"ExecuTorchModelForCausalLM", | ||
], | ||
} | ||
|
||
if TYPE_CHECKING: | ||
from .modeling_executorch import ExecuTorchModelForCausalLM | ||
else: | ||
import sys | ||
|
||
sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__) |
Oops, something went wrong.