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 Split QuickGelu Fusion #20344

Draft
wants to merge 193 commits into
base: main
Choose a base branch
from
Draft

Conversation

ajindal1
Copy link
Contributor

Description

Add Split QuickGelu Fusion

Motivation and Context

// Trying to find Split->QuickGelu->Mul Path
std::vector<const Node::EdgeEnd*> edges;
std::vector<graph_utils::EdgeEndToMatch> quickgelu_mul_path{
{0, 0, "QuickGelu", {1, 11, 13}, kOnnxDomain},
Copy link
Contributor

Choose a reason for hiding this comment

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

the activation can be other elementwise operator instead of QuickGelu, maybe we can add a todo here to support other operators.

"fused " + split_node.Name() + " and " + quickgelu_node.Name() + " and " + mul.Name() + " into SplitQuickGelu";

std::string op_type = "SplitQuickGelu";
Node& fused_node = graph.AddNode(graph.GenerateNodeName(op_type),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add transformer name into node's name to make future debugging easier to figure out which graph transformer generate the node.

@@ -0,0 +1,38 @@
import onnx

Check notice

Code scanning / CodeQL

Module is imported with 'import' and 'import from' Note test

Module 'onnx' is imported with both 'import' and 'import from'.
Module 'onnxruntime.test.onnx' is imported with both 'import' and 'import from'.
@@ -0,0 +1,50 @@
import torch

Check warning

Code scanning / lintrunner

BLACK-ISORT/format Warning test

Run lintrunner -a to apply this patch.
# inp = torch.randn((76, 54, 1368), device='cuda:0')
# out = temp(inp)

from onnxruntime.training.ortmodule import ORTModule

Check warning

Code scanning / lintrunner

RUFF/E402 Warning test

Module level import not at top of file.
See https://docs.astral.sh/ruff/rules/module-import-not-at-top-of-file
# out = temp(inp)

from onnxruntime.training.ortmodule import ORTModule
import time

Check warning

Code scanning / lintrunner

RUFF/E402 Warning test

Module level import not at top of file.
See https://docs.astral.sh/ruff/rules/module-import-not-at-top-of-file

def compare_torch_ort_perf(inp, num_steps=1000):
model2 = ORTModule(temp)
ort_temp_out = model2(inp)

Check warning

Code scanning / lintrunner

RUFF/F841 Warning test

Local variable ort\_temp\_out is assigned to but never used.
See https://docs.astral.sh/ruff/rules/unused-variable
print("Current input shape:", inp.shape)
torch.cuda.synchronize()
start = time.time()
for i in range(num_steps):

Check warning

Code scanning / lintrunner

RUFF/B007 Warning test

Loop control variable i not used within loop body.
See https://docs.astral.sh/ruff/rules/unused-loop-control-variable
print("Total time torch:", time.time() - start)
torch.cuda.synchronize()
start = time.time()
for i in range(num_steps):

Check warning

Code scanning / lintrunner

RUFF/B007 Warning test

Loop control variable i not used within loop body.
See https://docs.astral.sh/ruff/rules/unused-loop-control-variable

def compare_torch_ort_perf(inp, num_steps=1000):
model2 = ORTModule(temp)
ort_temp_out = model2(inp)

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable ort_temp_out is not used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants