This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-1086] added sub and mul to ONNX->TensorRT conversion #15344
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
|
||
from mxnet.test_utils import assert_almost_equal | ||
import mxnet as mx | ||
import numpy as np | ||
import os | ||
|
||
def check_elementwise_random(op='sum', shape=(1, 3, 224, 224)): | ||
""" | ||
Check elementwise operators with vanilla/TensorRT executors with uniform random tensors | ||
""" | ||
a = mx.sym.Variable('a') | ||
b = mx.sym.Variable('b') | ||
if op == 'sum': | ||
sym = a + b | ||
elif op == 'sub': | ||
sym = a - b | ||
elif op == 'mul': | ||
sym = a * b | ||
|
||
a_data = mx.ndarray.random.uniform(shape=shape, ctx=mx.gpu()) | ||
b_data = mx.ndarray.random.uniform(shape=shape, ctx=mx.gpu()) | ||
|
||
executor = sym.simple_bind(ctx=mx.gpu(), a=shape, b=shape, | ||
grad_req='null', force_rebind=True) | ||
y = executor.forward(is_train=False, a=a_data, b=b_data) | ||
trt_sym = sym.get_backend_symbol('TensorRT') | ||
original_precision_value = mx.contrib.tensorrt.get_use_fp16() | ||
try: | ||
mx.contrib.tensorrt.set_use_fp16(True) | ||
executor = trt_sym.simple_bind(ctx=mx.gpu(), a=shape, b=shape, | ||
grad_req='null', force_rebind=True) | ||
y_trt = executor.forward(is_train=False, a=a_data, b=b_data) | ||
mx.contrib.tensorrt.set_use_fp16(False) | ||
executor = trt_sym.simple_bind(ctx=mx.gpu(), a=shape, b=shape, | ||
grad_req='null', force_rebind=True) | ||
y_trt_fp32 = executor.forward(is_train=False, a=a_data, b=b_data) | ||
assert_almost_equal(y[0].asnumpy(), y_trt[0].asnumpy(), 1e-1, 1e-2) | ||
assert_almost_equal(y[0].asnumpy(), y_trt_fp32[0].asnumpy(), 1e-4, 1e-4) | ||
finally: | ||
mx.contrib.tensorrt.set_use_fp16(original_precision_value) | ||
|
||
|
||
def test_elementwise(): | ||
for op in ['sum', 'sub', 'mul']: | ||
for shape in [(20, 25), (3, 4, 20), (1, 3, 20, 25), (10, 10, 100, 100)]: | ||
for itry in range(10): | ||
check_elementwise_random(op, shape) | ||
|
||
|
||
if __name__ == '__main__': | ||
import nose | ||
nose.runmodule() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with_seed missing