-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
034f1e0
commit 37ee257
Showing
11 changed files
with
51 additions
and
279 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,30 @@ | ||
"""FFI exposing the Relay type inference and checking.""" | ||
from __future__ import absolute_import | ||
import topi | ||
from tvm._ffi.function import _init_api | ||
from ..op import op as _reg | ||
|
||
|
||
@_reg.register_compute("simulated_quantize") | ||
def simulated_quantize_compute(attrs, inputs, output_type, target): | ||
"""Compiler for simulated_quantize.""" | ||
assert len(inputs) == 5 | ||
assert attrs.sign | ||
assert attrs.rounding == "round" | ||
|
||
data, scale, bit, clip_min, clip_max = inputs | ||
|
||
# simulate rounding error | ||
scaled_data = topi.divide(data, scale) | ||
clipped_data = topi.maximum(topi.minimum(scaled_data, clip_max), clip_min) | ||
round_data = topi.round(clipped_data) | ||
|
||
# recover data | ||
rdata = topi.multiply(round_data, scale) | ||
return [rdata] | ||
|
||
|
||
_reg.register_schedule("simulated_quantize", _reg.schedule_injective) | ||
_reg.register_pattern("simulated_quantize", _reg.OpPattern.OPAQUE) | ||
|
||
_init_api("relay._quantize", __name__) |
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
Oops, something went wrong.