-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fp16 ops for onnxrt adaptor (#915)
Signed-off-by: Mengni Wang <[email protected]>
- Loading branch information
1 parent
9ecc9f5
commit 15d5518
Showing
13 changed files
with
356 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2021 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Normalization Operator.""" | ||
|
||
import onnx | ||
from neural_compressor.adaptor.ox_utils.operators.ops import op_registry, Operator, QOperator, qop_registry | ||
from neural_compressor.adaptor.ox_utils.util import attribute_to_kwarg, ms_domain | ||
|
||
@op_registry(op_types="BatchNormalization") | ||
class BatchNormalizationOperator(Operator): | ||
"""BatchNormalization Operator.""" | ||
|
||
def __init__(self, onnx_quantizer, onnx_node): | ||
"""Initialization.""" | ||
super(BatchNormalizationOperator, self).__init__(onnx_quantizer, onnx_node) | ||
|
||
def cast(self): | ||
"""Cast node.""" | ||
if self.dtype == 'bf16': | ||
self.quantizer.cast_inputs(self.node, self.dtype, [0]) | ||
else: | ||
self.quantizer.cast_inputs(self.node, self.dtype) | ||
self.quantizer.cast_outputs(self.node, self.dtype) | ||
|
||
@op_registry(op_types="LayerNormalization") | ||
class NormalizationOperator(Operator): | ||
"""Normalization Operator.""" | ||
|
||
def __init__(self, onnx_quantizer, onnx_node): | ||
"""Initialization.""" | ||
super(NormalizationOperator, self).__init__(onnx_quantizer, onnx_node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2021 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Reduce Operator.""" | ||
|
||
from neural_compressor.adaptor.ox_utils.operators.ops import op_registry, Operator | ||
|
||
@op_registry(op_types="ReduceMean, ReduceLogSum, ReduceLogSumExp, ReduceMax, " \ | ||
"ReduceL1, ReduceL2, ReduceProd, ReduceSum, ReduceSumSquare") | ||
class ReduceOperator(Operator): | ||
"""Reduce Operator.""" | ||
|
||
def __init__(self, onnx_quantizer, onnx_node): | ||
"""Initialization.""" | ||
super(ReduceOperator, self).__init__(onnx_quantizer, onnx_node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (c) 2021 Intel Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Unary operator.""" | ||
|
||
from neural_compressor.adaptor.ox_utils.operators.ops import op_registry, Operator | ||
|
||
@op_registry(op_types="Abs, Exp, Log, Round, Sqrt") | ||
class UnaryOperator(Operator): | ||
"""Unary operator.""" | ||
|
||
def __init__(self, onnx_quantizer, onnx_node): | ||
"""Initialization.""" | ||
super(UnaryOperator, self).__init__(onnx_quantizer, onnx_node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.