Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
nni
Commits
27e123df
Unverified
Commit
27e123df
authored
Jun 22, 2021
by
lin bin
Committed by
GitHub
Jun 22, 2021
Browse files
fix data device type bug (#3856)
parent
009722a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
0 deletions
+6
-0
docs/en_US/Compression/QuantizationSpeedup.rst
docs/en_US/Compression/QuantizationSpeedup.rst
+1
-0
nni/compression/pytorch/quantization_speedup/integrated_tensorrt.py
...ssion/pytorch/quantization_speedup/integrated_tensorrt.py
+5
-0
No files found.
docs/en_US/Compression/QuantizationSpeedup.rst
View file @
27e123df
...
...
@@ -39,6 +39,7 @@ After getting mixed precision engine, users can do inference with input data.
Note
*
Recommend
using
"cpu"
(
host
)
as
data
device
(
for
both
inference
data
and
calibration
data
)
since
data
should
be
on
host
initially
and
it
will
be
transposed
to
device
before
inference
.
If
data
type
is
not
"cpu"
(
host
),
this
tool
will
transpose
it
to
"cpu"
which
may
increases
unnecessary
overhead
.
*
User
can
also
do
post
-
training
quantization
leveraging
TensorRT
directly
(
need
to
provide
calibration
dataset
).
*
Not
all
op
types
are
supported
right
now
.
At
present
,
NNI
supports
Conv
,
Linear
,
Relu
and
MaxPool
.
More
op
types
will
be
supported
in
the
following
release
.
...
...
nni/compression/pytorch/quantization_speedup/integrated_tensorrt.py
View file @
27e123df
...
...
@@ -290,6 +290,9 @@ class ModelSpeedupTensorRT(BaseModelSpeedup):
calib_data_set
.
append
(
data
)
calib_data
=
np
.
concatenate
(
calib_data_set
)
elif
type
(
self
.
calib_data_loader
)
==
torch
.
Tensor
:
# trt need numpy as calibration data, only cpu data can convert to numpy directly
if
self
.
calib_data_loader
.
device
!=
torch
.
device
(
"cpu"
):
self
.
calib_data_loader
=
self
.
calib_data_loader
.
to
(
"cpu"
)
calib_data
=
self
.
calib_data_loader
.
numpy
()
else
:
raise
ValueError
(
"Not support calibration datatype"
)
...
...
@@ -326,6 +329,8 @@ class ModelSpeedupTensorRT(BaseModelSpeedup):
Model input tensor
"""
# convert pytorch tensor to numpy darray
if
test_data
.
device
!=
torch
.
device
(
"cpu"
):
test_data
=
test_data
.
to
(
"cpu"
)
test_data
=
test_data
.
numpy
()
# Numpy dtype should be float32
assert
test_data
.
dtype
==
np
.
float32
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment