Skip to content
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

Add support for exporting LLaMA to ONNX format #922

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions docs/source/exporters/onnx/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Supported architectures:
- LayoutLM-v3
- Levit
- LongT5
- Llama
- M2-M100
- Marian
- MBart
Expand Down
5 changes: 5 additions & 0 deletions optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ class OPTOnnxConfig(TextDecoderOnnxConfig):
NORMALIZED_CONFIG_CLASS = NormalizedTextConfig


class LlamaOnnxConfig(TextDecoderOnnxConfig):
DEFAULT_ONNX_OPSET = 13
NORMALIZED_CONFIG_CLASS = NormalizedTextConfig


class BloomDummyPastKeyValuesGenerator(DummyPastKeyValuesGenerator):
def generate(self, input_name: str, framework: str = "pt"):
past_key_shape = (
Expand Down
8 changes: 8 additions & 0 deletions optimum/exporters/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,14 @@ class TasksManager:
"sequence-classification",
onnx="OPTOnnxConfig",
),
"llama": supported_tasks_mapping(
"default",
"default-with-past",
"causal-lm",
"causal-lm-with-past",
"sequence-classification",
onnx="LlamaOnnxConfig",
),
"pegasus": supported_tasks_mapping(
"default",
"default-with-past",
Expand Down
4 changes: 3 additions & 1 deletion tests/exporters/exporters_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"mpnet": "hf-internal-testing/tiny-random-MPNetModel",
"mt5": "lewtun/tiny-random-mt5",
"nystromformer": "hf-internal-testing/tiny-random-NystromformerModel",
"opt": "hf-internal-testing/tiny-random-OPTModel",
"opt": "hf-internal-testing/tiny-random-llama",
"llama": "hf-internal-testing/tiny-random-OPTModel",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you inverted OPT and Llama here

# "owlvit": "google/owlvit-base-patch32",
"pegasus": "hf-internal-testing/tiny-random-PegasusModel",
"perceiver": {
Expand Down Expand Up @@ -163,6 +164,7 @@
"levit": "facebook/levit-128S",
"layoutlm": "microsoft/layoutlm-base-uncased",
"layoutlmv3": "microsoft/layoutlmv3-base",
"llama": "decapoda-research/llama-65b-hf",
"longt5": "hf-internal-testing/tiny-random-longt5", # Not using google/long-t5-local-base because it takes too much time for testing.
# "longformer": "allenai/longformer-base-4096",
"m2m-100": "hf-internal-testing/tiny-random-m2m_100", # Not using facebook/m2m100_418M because it takes too much time for testing.
Expand Down
1 change: 1 addition & 0 deletions tests/onnxruntime/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,7 @@ class ORTModelForCausalLMIntegrationTest(ORTModelTestMixin):
"gpt_neo",
"gpt_neox",
"gptj",
"llama",
]

FULL_GRID = {
Expand Down
1 change: 1 addition & 0 deletions tests/onnxruntime/utils_onnxruntime_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"layoutlm": "hf-internal-testing/tiny-random-LayoutLMModel",
"layoutlmv3": "hf-internal-testing/tiny-random-LayoutLMv3Model",
"longt5": "hf-internal-testing/tiny-random-LongT5Model",
"llama": "hf-internal-testing/tiny-random-llama",
"m2m_100": "hf-internal-testing/tiny-random-m2m_100",
"marian": "sshleifer/tiny-marian-en-de", # hf-internal-testing ones are broken
"mbart": "hf-internal-testing/tiny-random-mbart",
Expand Down