-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentity_export.py
44 lines (32 loc) · 1.02 KB
/
identity_export.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import torch
# --IN---
# query [bs, num_query, embed_dims] float32
#
# --OUT---
# query_out query.shape float32
class SCAFunction1(torch.autograd.Function):
@staticmethod
def forward(ctx, query):
return query
@staticmethod
def symbolic(
g,
query
):
return g.op("TRT::Identity_TRT", query)
sca_fun_1 = SCAFunction1.apply
class MSDA(torch.nn.Module):
def __init__(self):
super().__init__()
def forward(self, query):
return sca_fun_1(query)
bs = 1; num_query = 40000; embed_dims=256
query = torch.randn(bs, num_query, embed_dims)
model = MSDA().eval()
torch.onnx.export(model, (query),
'identity.onnx',
export_params=True,
keep_initializers_as_inputs=True,
do_constant_folding=True,
verbose=True,
opset_version=13)