Update T5 Onnx Export and Optimization - #23949
Conversation
435dae0 to
5ce3639
Compare
| def test_gpt_model( | ||
| args: argparse.Namespace, | ||
| sentences: list[str] | None = None, | ||
| is_greedy: bool = False, | ||
| ): |
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the problem, we need to add an explicit return statement at the end of the test_gpt_model function to ensure that it always returns a value explicitly. This will make it clear to other developers that the function can return None and that this is intentional.
- Add an explicit
return Nonestatement at the end of thetest_gpt_modelfunction. - This change should be made in the file
onnxruntime/python/tools/transformers/convert_generation.py.
| @@ -3297,2 +3297,3 @@ | ||
|
|
||
| return None | ||
| def test_t5_model(args: argparse.Namespace, sentences: list[str] | None = None): |
1b69e4f to
2df8206
Compare
|
Adding a note here to check that the changes to the encoder and decoder subgraphs for T5 do not affect Whisper. There are CI tests here that were added to ensure backwards compatibility with the |
|
Can we add T5 to the |
It is not needed. The T5 tests in test_generation.py is enabled in CI pipeline so there is end to end tests there. |
Description
Previously, the encoder onnx model adds extra initialization for decoder to generate kv cache from prompt. It is not necessary. Here we redesign onnx export for T5 model to output two separate models for encode and decoder.
Move Linear that generates cross features based on encoder_hidden_states to encoder onnx model. In this way, the encoder does not need output encoder_hidden_states, and only need output the features for cross attention used in decoder.
Major changes:
-[x] update t5 onnx export script
-[x] update convert_generation script
-[x] update beam search to support changes of inputs and outputs (detail can be found below).
-[x] add a tiny t5 model, and enable the generation test for T5 in Linux CI pipelines.
Example change in inputs and outputs for one layer model:
Encoder Inputs:
decoder_input_ids: int32 (B, 1)Encoder Outputs:
logits: (B, 1, vocab_size)encoder_hidden_states: (B, encode_sequence_length, encoder_hidden_size)present_key_self_0: (B, num_heads, 1, head_size)present_value_self_0: (B, num_heads, 1, head_size)Decoder Inputs:
encoder_input_ids: int32 (B, encode_sequence_length) (optional for old format; removed in new format)encoder_hidden_states: (B, encode_sequence_length, encoder_hidden_size) (optional for old format; removed in new format)Decoder Outputs:
Known issues:
Motivation and Context
Make the encoder onnx model simpler and more efficient in inference (no need to output encoder_hidden_states).