Icemist commented on a change in pull request #10239:
URL: https://github.com/apache/tvm/pull/10239#discussion_r808578462
##########
File path: tests/python/relay/test_pass_fake_quantization_to_integer.py
##########
@@ -627,3 +628,217 @@ def conv2d(expr, type_map): # pylint:
disable=unused-variable
# Catch a generic exception because the tvm FFI eats the python exception
type
with pytest.raises(Exception):
mod_int =
tvm.relay.transform.FakeQuantizationToInteger(hard_fail=True)(mod)
+
+
+def compare_expected_fq_to_int(expr, expected_expr, args,
allow_rounding_error=False):
+ mod = tvm.IRModule.from_expr(expr)
+ mod_def = tvm.relay.transform.InferType()(mod)
+ mod_int = tvm.relay.transform.FakeQuantizationToInteger(False)(mod_def)
+ mod_exp =
tvm.relay.transform.InferType()(tvm.IRModule.from_expr(expected_expr))
+ print("mod_def\n", mod_def, "\n")
+ print("mod_int\n", mod_int, "\n")
+ print("mod_exp\n", mod_exp, "\n")
+ assert not tvm.ir.structural_equal(mod, mod_int)
+ assert tvm.ir.structural_equal(mod_int, mod_exp)
+ result_def = (
+ relay.create_executor("vm", mod=mod_def, device=tvm.cpu(),
target="llvm")
+ .evaluate()(*args)
+ .numpy()
+ )
+ result_int = (
+ relay.create_executor("vm", mod=mod_int, device=tvm.cpu(),
target="llvm")
+ .evaluate()(*args)
+ .numpy()
+ )
+ result_exp = (
+ relay.create_executor("vm", mod=mod_exp, device=tvm.cpu(),
target="llvm")
+ .evaluate()(*args)
+ .numpy()
+ )
+ print("result_def\n", result_def)
+ print("result_int\n", result_int)
+ print("result_exp\n", result_exp)
+ if allow_rounding_error:
+ assert np.all(np.abs(result_def.astype("int32") -
result_int.astype("int32")) <= 1)
+ else:
+ assert np.array_equal(result_def, result_int)
+
+ assert np.array_equal(result_int, result_exp)
+
+
+def test_fq2i_optional_op_chaind_with_disabled_op():
Review comment:
I tried to explain the motivation by updating the titles and adding a
line of description to the tests.
##########
File path: tests/python/relay/test_pass_fake_quantization_to_integer.py
##########
@@ -627,3 +628,217 @@ def conv2d(expr, type_map): # pylint:
disable=unused-variable
# Catch a generic exception because the tvm FFI eats the python exception
type
with pytest.raises(Exception):
mod_int =
tvm.relay.transform.FakeQuantizationToInteger(hard_fail=True)(mod)
+
+
+def compare_expected_fq_to_int(expr, expected_expr, args,
allow_rounding_error=False):
+ mod = tvm.IRModule.from_expr(expr)
+ mod_def = tvm.relay.transform.InferType()(mod)
+ mod_int = tvm.relay.transform.FakeQuantizationToInteger(False)(mod_def)
+ mod_exp =
tvm.relay.transform.InferType()(tvm.IRModule.from_expr(expected_expr))
+ print("mod_def\n", mod_def, "\n")
+ print("mod_int\n", mod_int, "\n")
+ print("mod_exp\n", mod_exp, "\n")
+ assert not tvm.ir.structural_equal(mod, mod_int)
+ assert tvm.ir.structural_equal(mod_int, mod_exp)
+ result_def = (
+ relay.create_executor("vm", mod=mod_def, device=tvm.cpu(),
target="llvm")
+ .evaluate()(*args)
+ .numpy()
+ )
+ result_int = (
+ relay.create_executor("vm", mod=mod_int, device=tvm.cpu(),
target="llvm")
+ .evaluate()(*args)
+ .numpy()
+ )
+ result_exp = (
+ relay.create_executor("vm", mod=mod_exp, device=tvm.cpu(),
target="llvm")
+ .evaluate()(*args)
+ .numpy()
+ )
+ print("result_def\n", result_def)
+ print("result_int\n", result_int)
+ print("result_exp\n", result_exp)
+ if allow_rounding_error:
+ assert np.all(np.abs(result_def.astype("int32") -
result_int.astype("int32")) <= 1)
+ else:
+ assert np.array_equal(result_def, result_int)
+
+ assert np.array_equal(result_int, result_exp)
+
+
+def test_fq2i_optional_op_chaind_with_disabled_op():
Review comment:
Renamed the function in another way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]