= Motivation It's useful to expose the tvm::reinterpret functionality to Relay/TOPI users, as this allows them to build (fused) operators leveraging the bitwise reinterpretation of an operator. An example is approximate transcendental functions, which can be implemented similar to: ```.py def C(x): return relay.expr.const(x, "float32") def approx_exp(x): x = relay.minimum(relay.maximum(x, C(-88.0)), C(88.0)) x = C(127.0) + x * C(1.44269504) xf = relay.floor(x) i = relay.cast(xf, "int32") x = x - xf Y = C(0.99992522) + x * (C(0.69583354) + x * (C(0.22606716) + x * C(0.078024523))) exponent = relay.left_shift(i, relay.expr.const(23, "int32")) exponent = relay.reinterpret(exponent, "float32") return exponent * Y def approx_sigmoid(x): # <2.0e-5 absolute error over [-5, 5] y = approx_exp(x) return y / (y + C(1.0)) def approx_tanh(x): # <4.0e-5 absolute error over [-5, 5] x = x * C(2.0) y = approx_exp(x) return (y - C(1.0)) / (y + C(1.0)) ``` See unit tests for implementations of these approximate transendentals.
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
backend | Loading commit data... | |
frontend | Loading commit data... | |
grammar | Loading commit data... | |
op | Loading commit data... | |
quantize | Loading commit data... | |
testing | Loading commit data... | |
__init__.py | Loading commit data... | |
_analysis.py | Loading commit data... | |
_base.py | Loading commit data... | |
_build_module.py | Loading commit data... | |
_expr.py | Loading commit data... | |
_make.py | Loading commit data... | |
_module.py | Loading commit data... | |
_module.pyi | Loading commit data... | |
_parser.py | Loading commit data... | |
_transform.py | Loading commit data... | |
adt.py | Loading commit data... | |
analysis.py | Loading commit data... | |
annotation.py | Loading commit data... | |
base.py | Loading commit data... | |
build_module.py | Loading commit data... | |
contrib.py | Loading commit data... | |
debug.py | Loading commit data... | |
expr.py | Loading commit data... | |
expr.pyi | Loading commit data... | |
expr_functor.py | Loading commit data... | |
feature.py | Loading commit data... | |
image.py | Loading commit data... | |
loops.py | Loading commit data... | |
module.py | Loading commit data... | |
nn.py | Loading commit data... | |
param_dict.py | Loading commit data... | |
parser.py | Loading commit data... | |
prelude.py | Loading commit data... | |
prelude.rly | Loading commit data... | |
scope_builder.py | Loading commit data... | |
transform.py | Loading commit data... | |
transform.pyi | Loading commit data... | |
ty.py | Loading commit data... | |
ty.pyi | Loading commit data... | |
vision.py | Loading commit data... |