onnxruntime/onnxruntime/test/optimizer
rui-ren a67e692546
add GatherSliceToSplitFusion and Unittest (#19218)
### Multi Query Attention Optimization

in multi-query attention
```
batch_size, seq_length, three_times_hidden_size = fused_qkv.shape
fused_qkv = fused_qkv.view(batch_size, seq_length, self.num_heads + 2, self.head_dim)
return fused_qkv[..., :-2, :], fused_qkv[..., [-2], :], fused_qkv[..., [-1], :]
```
which can be optimized to 
```
batch_size, seq_length, three_times_hidden_size = fused_qkv.shape
fused_qkv = fused_qkv.view(batch_size, seq_length, self.num_heads + 2, self.head_dim)
(query, key, value) = fused_qkv.split([self.num_heads, 1, 1], dim=2)
return query, key, value
```

this optimization can be validated from nsight profiling and perf
benchmarking.
   
<img width="545" alt="image"
src="https://github.com/microsoft/onnxruntime/assets/15321482/cefcd061-4a01-4aaf-a008-8e265f7f63e9">

As such, This PR is to Optimize the `Gather/Gather/Slice` Ops to `Split`
Kernel.

### Optimization Target
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

As 2 `Gather` and 1 `Slice` Kernels are time consuming for backward
prop, it would be efficient to use 1 `Split` Kernel


###  Example

- Before Fusion
<img width="419" alt="image"
src="https://github.com/microsoft/onnxruntime/assets/15321482/17410319-57ea-4176-afd4-1efdcd3fdbae">
 
- After Fusion
<img width="424" alt="image"
src="https://github.com/microsoft/onnxruntime/assets/15321482/f1ee1582-96d4-45f4-8778-49d1f3fd370a">

### Perf Gain
After the optimization, there will have **~7%** perf gain. 

> The `Transpose` Kernel can be fused too, will update it in next PR.
However, after testing Transponse Ops fusion on Falcon model, there is
no perf gain. Will not create a new PR.

---------

Co-authored-by: ruiren <ruiren@microsoft.com>
2024-02-14 15:07:56 -08:00
..
runtime_optimization
avx2_weight_s8_to_u8_test.cc
compute_optimizer_test.cc fix axis of layernorm for UpstreamReshape (#18425) 2023-11-16 16:29:00 +08:00
conv_add_act_test.cc
cse_test.cc Make session configuration options available to kernels via OpKernelInfo (#18897) 2024-01-13 10:02:43 +10:00
dummy_graph_transformer.h
ensure_unique_dq_for_node_unit_test.cc Fix the duplicated QDQ attributes setup issue (#18039) 2024-01-10 18:36:33 -08:00
free_dimension_override_test.cc
graph_transform_test.cc add GatherSliceToSplitFusion and Unittest (#19218) 2024-02-14 15:07:56 -08:00
graph_transform_test_builder.cc add SAVE_TEST_GRAPH macro (#18696) 2023-12-05 07:46:08 -08:00
graph_transform_test_builder.h [QNN/CPU EP] Add 16-bit Quantize/Dequantize contrib ops (#17015) 2023-09-18 09:43:34 -07:00
graph_transform_test_fixture.h
graph_transform_test_layernorm.cc Layer norm fusion deepspeed stage3 changes (#17614) 2023-09-21 14:16:41 -07:00
graph_transform_utils_test.cc
initializer_test.cc [js] enable external data loading for ort-web (#19087) 2024-01-12 19:24:24 -08:00
layout_transformation_potentially_added_ops_test.cc
nchwc_optimizer_test.cc
nhwc_transformer_test.cc
optimizer_test.cc Make session configuration options available to kernels via OpKernelInfo (#18897) 2024-01-13 10:02:43 +10:00
qdq_test_utils.cc
qdq_test_utils.h Update transpose optimization to be more QDQ aware (#18444) 2023-11-23 08:27:47 +10:00
qdq_transformer_fastmath_test.cc [aarch64] Add Sbgemm kernel to accelerate fp32 tensor matmul with bfloat16 (#17031) 2024-01-22 14:43:06 -08:00
qdq_transformer_test.cc Fix unit tests failures in build with contrib ops disabled (#18659) 2023-12-01 09:41:25 -08:00
resnet50_fusion_test.cc
rule_based_graph_transformer_test.cc
test_optimizer_utils.cc
test_optimizer_utils.h
transpose_optimizer_test.cc Fix unit tests failures in build with contrib ops disabled (#18659) 2023-12-01 09:41:25 -08:00