Skip to content

Add FlattenAndUnpad Op - #17845

Merged
pengwa merged 3 commits into
mainfrom
yangu/flatten_and_unpad
Nov 9, 2023
Merged

Add FlattenAndUnpad Op#17845
pengwa merged 3 commits into
mainfrom
yangu/flatten_and_unpad

Conversation

@guyang3532

@guyang3532 guyang3532 commented Oct 9, 2023

Copy link
Copy Markdown
Contributor

Description

Add an op named FlattenAndUnpad.
This op implements functions:

  1. Flatten the first two dims of input tensor.
  2. Gather valid value from input tensor with index tensor,.

Motivation and Context

The grad op of PadAndUnflatten was GatherGrad which is inefficient in performance.
I implement this FlattenAndUnpad just to replace the GatherGrad as grad of PadAndUnflatten.
With this op, we also can simplify the "Reshape + ShrunkenGather" pattern to PadAndUnflatten in padding elimination optimizer, which will also improve performance.

@guyang3532
guyang3532 requested a review from pengwa October 9, 2023 11:16
Comment thread orttraining/orttraining/core/graph/gradient_builder.cc Outdated
Comment thread orttraining/orttraining/core/graph/gradient_builder.cc Outdated
@guyang3532
guyang3532 force-pushed the yangu/flatten_and_unpad branch 2 times, most recently from 89c157e to cbf9348 Compare October 10, 2023 12:20
@pengwa pengwa added the training issues related to ONNX Runtime training; typically submitted using template label Oct 11, 2023
@guyang3532
guyang3532 force-pushed the yangu/flatten_and_unpad branch from cbf9348 to 69db77a Compare October 11, 2023 06:26
@guyang3532
guyang3532 force-pushed the yangu/flatten_and_unpad branch from 69db77a to ec58f22 Compare October 12, 2023 07:25
@guyang3532
guyang3532 force-pushed the yangu/flatten_and_unpad branch from ec58f22 to 2003901 Compare October 12, 2023 07:41
@guyang3532
guyang3532 force-pushed the yangu/flatten_and_unpad branch from 2003901 to ba4fa1e Compare November 7, 2023 05:17
Comment thread orttraining/orttraining/core/graph/training_op_defs.cc Outdated
Comment thread orttraining/orttraining/core/graph/training_op_defs.cc Outdated
Comment thread orttraining/orttraining/test/training_ops/cuda/flatten_and_unpad_test.cc Outdated
Comment thread orttraining/orttraining/test/training_ops/cuda/flatten_and_unpad_test.cc Outdated
Comment thread orttraining/orttraining/training_ops/rocm/rocm_training_kernels.cc Outdated
Comment thread orttraining/orttraining/training_ops/cuda/tensor/flatten_and_unpad_impl.cu Outdated
Comment thread orttraining/orttraining/core/graph/gradient_builder.cc Outdated
@pengwa

pengwa commented Nov 7, 2023

Copy link
Copy Markdown
Contributor

Do you have perf improvement numbers to share in the PR description?

Comment thread orttraining/orttraining/training_ops/cuda/tensor/flatten_and_unpad_impl.cu Outdated
pengwa
pengwa previously approved these changes Nov 7, 2023
@pengwa
pengwa merged commit 4dc6369 into main Nov 9, 2023
@pengwa
pengwa deleted the yangu/flatten_and_unpad branch November 9, 2023 01:52
kleiti pushed a commit to kleiti/onnxruntime that referenced this pull request Mar 22, 2024
### Description
Add an op named `FlattenAndUnpad`.
This op implements functions:
1. Flatten the first two dims of input tensor.
2. Gather valid value from input tensor with index tensor,.


### Motivation and Context
The grad op of `PadAndUnflatten` was `GatherGrad` which is inefficient
in performance.
I implement this `FlattenAndUnpad` just to replace the `GatherGrad` as
grad of `PadAndUnflatten`.
With this op, we also can simplify the "Reshape + ShrunkenGather"
pattern to `PadAndUnflatten` in padding elimination optimizer, which
will also improve performance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

training issues related to ONNX Runtime training; typically submitted using template

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants