-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export to ExecuTorch: Initial Integration #2090
Export to ExecuTorch: Initial Integration #2090
Conversation
4ad0b3d
to
328069d
Compare
Fixed the export path. Now |
6b38215
to
757f152
Compare
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments. I have to say it is really great work what you have done here since it is not easy to go from our main ONNX codebase and generalize!
Do you think we could also write little tests in the same spirit as what's done for ONNX, where we validate the exported model against a vanilla PyTorch model?
Thanks for the feedback @michaelbenayoun @echarlaix. I was on PTO last week right after the Hackathon. I will prioritize and continue to iterating this PR this week. |
I should definitely add tests and make sure it runs in CI, for both export cli and runtime. However, note that the generated contents from exported model may not be identical as the eager pytorch model due to specialization during export. We can goal on testing the functionality first in this PR, i.g. the ability to generate using the exported model, then guard on correctness later though some lm_eval or something similar. Tests are added.
Don't see any CI is running. @michaelbenayoun @echarlaix How can I make sure these tests are running in CI? |
757f152
to
28aae25
Compare
@michaelbenayoun @echarlaix Could you guide me where I should add documentations for the new backend ExecuTorch? |
28aae25
to
4385d25
Compare
Several new updates:
|
The CI must be triggered by a HF member, that is why it is not running. I just triggered it. |
58326c4
to
c36e2e2
Compare
|
I see
In ExecuTorch Runtime jobs. Trying to figure out if it's because previous tests is taking pretty much all SSD on the runner. I'm splitting the tests for each model into a separate test file, so each job will only run test for a single model, which is more scalable as we adding more recipes, optimizations, and tests for a model. cc: @michaelbenayoun |
Weird doc-build error but doesn't look relevant to this PR:
@michaelbenayoun safe to merge? |
python-version: ['3.10', '3.11', '3.12'] | ||
os: [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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc: @michaelbenayoun Compatible python versions and package installation.
What does this PR do?
This PR is the first initiative to create an e2e path for "Export to ExecuTorch".
In this very first revision, I'm focusing outline the skeleton of the integration work:
./setup.py
: Specify new dependency in order to "Export to ExecuTorch". In this case, it's adding a new pip packageexecutorch
(Beta version) and require the latest releasedtransformfers
(models from older versions may not work with ExecuTorch)Env setup
./optimum/commands/export/executorch.py
: To support running export with ExecuTorch backend via cli.Export AOT(Ahead-of-time)
./optimum/exporters/executorch/
: Main entry point to export via ExecuTorch.coverter.py
which defines the common workflow to export atransformers
model from 🤗 to ExecuTorch.CausalLM
w/ cache must be loaded withgeneration_config
and exported viatransformers.integrations.executorch
.Run with ExecuTorch model
optimum/executorchruntime/modeling_executorch.py
defines the python class that wrap the TransformersAutoModelForXXX
classes. We start withExecuTorchModelForCausalLM
in this file, which inherits the baseOptimizedModel
and overrides all abstract methods. This is where the ExecuTorch pybinding and the runtime gets integrated.Tests
Export AOT(Ahead-of-time)
Export to ExecuTorch via CLI:
optimum-cli export executorch --model "meta-llama/Llama-3.2-1B" --task "text-generation" --recipe "xnnpack" --output_dir="meta_llama3_2_1b"
It generates the ExecuTorch model to
meta_llama3_2_1b/model.pte
.Run with ExecuTorch model (
model.pte
)And we got:
"Hey, can you tell me any fun things to do in New York? I’m going to be there for a week and I’m not sure what to do. I’m a little bit of a history buff and I’m also a little bit of a foodie. I’m not sure if I should go to the museum or the zoo or the aquarium. I’m not sure if I should go to the theater or the opera or the ballet..."
Full new tests:
RUN_SLOW=1 pytest tests/executorch/*/test_*.py -s -v
Before submitting
Who can review?
@michaelbenayoun @echarlaix @mergennachin