-
Notifications
You must be signed in to change notification settings - Fork 608
Introduce extension/llm/export_llm #11746
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
""" | ||
Export an LLM with ExecuTorch. Currently follows the following steps: | ||
1. Instantiate our custom PyTorch transformer definition from examples/llama/models/llama_transformer.py. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't mention implementation details in the docblock. If it's a public API, the docblock should contain description of the contract. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will move this information to a README |
||
2. Load weights into the model. | ||
3. Apply source transformations/TorchAO quantization. | ||
4. Export model to intermediate IRs. | ||
5. Graph transformations/PT2E quantization. | ||
6. Partition graph and delegate to backend(s). | ||
7. Export to final ExecuTorch .pte format. | ||
|
||
Example usage using full CLI arguments: | ||
python -m extension.llm.export.export_llm \ | ||
jackzhxng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
base.model_class="llama3" \ | ||
model.use_sdpa_with_kv_cache=True \ | ||
model.use_kv_cache=True \ | ||
debug.verbose=True \ | ||
backend.xnnpack.enabled=True \ | ||
backend.xnnpack.extended_ops=True \ | ||
quantization.qmode="8da4w" | ||
""" | ||
|
||
import hydra | ||
|
||
from executorch.examples.models.llama.config.llm_config import LlmConfig | ||
from executorch.examples.models.llama.export_llama_lib import export_llama | ||
from hydra.core.config_store import ConfigStore | ||
from omegaconf import OmegaConf | ||
|
||
cs = ConfigStore.instance() | ||
cs.store(name="llm_config", node=LlmConfig) | ||
|
||
|
||
@hydra.main(version_base=None, config_path=None, config_name="llm_config") | ||
def main(llm_config: LlmConfig) -> None: | ||
export_llama(OmegaConf.to_object(llm_config)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Uh oh!
There was an error while loading. Please reload this page.