-
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 6, 2024
1 parent
7e8d857
commit e561925
Showing
22 changed files
with
1,170 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: ExecuTorch Runtime / Python - Test | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ['3.10', '3.11', '3.12'] | ||
os: [ubuntu-20.04, macos-15] | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies for ExecuTorch | ||
run: | | ||
pip install .[tests,exporters-executorch] | ||
python -c "import executorch; print(executorch.__version__)" | ||
python -c "import torch; print(torch.__version__)" | ||
python -c "import transformers; print(transformers.__version__)" | ||
- name: Run tests | ||
working-directory: tests | ||
run: | | ||
pytest tests/executorch/test_*.py -s -vvvv --durations=0 |
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,37 @@ | ||
name: Exporters ExecuTorch / Python - Test | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ['3.10', '3.11', '3.12'] | ||
os: [ubuntu-20.04, macos-15] | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies for ExecuTorch | ||
run: | | ||
pip install .[tests,exporters-executorch] | ||
python -c "import executorch; print(executorch.__version__)" | ||
python -c "import torch; print(torch.__version__)" | ||
python -c "import transformers; print(transformers.__version__)" | ||
- name: Run tests | ||
working-directory: tests | ||
run: | | ||
pytest tests/exporters/executorch/test_*.py -s -vvvv --durations=0 |
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.