forked from NVIDIA/Deep-Learning-Accelerator-SW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Neg.py
49 lines (39 loc) · 1.5 KB
/
Neg.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
44
45
46
47
48
49
#
# SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: MIT
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.
#
"""Reconstruction of a Neg op."""
from logging import info
import numpy as np
import onnx_graphsurgeon as gs
from common.Operator import Operator
class Neg(Operator):
def generate(self, input_shapes, **kwargs):
# modify here
graph = super().generate(input_shapes, **kwargs)
return graph
@classmethod
def reconstruct(cls, node, graph):
if cls.qualifies_for_reconstruction(node):
info(f'Reconstructing {node.op} node "{node.name}"...')
node.op = 'Mul'
node.attrs.clear()
mul_shape = (1, )
mul_vals = np.zeros(mul_shape, dtype=np.float32)
mul_vals.fill(-1.0)
mul_constant = gs.Constant(name=f'{node.name}_tmp0', values=mul_vals)
node.inputs.append(mul_constant)
def test(self, input_shapes=[(1, 2, 3, 4)], **kwargs):
return super().test(input_shapes, **kwargs)
def main():
op = Neg()
op.test()
if __name__ == '__main__':
main()