[Mlir-commits] [mlir] Sub-channel quantized type implementation (PR #120172)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Dec 16 18:18:06 PST 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {darker}-->
:warning: Python code formatter, darker found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
darker --check --diff -r 72e8b9aeaa3f584f223bc59924812df69a09a48b...3a6a0a71f55a92ad597cbfb4ac596e6f50ee2405 mlir/test/python/dialects/quant.py
``````````
</details>
<details>
<summary>
View the diff from darker here.
</summary>
``````````diff
--- quant.py 2024-12-17 01:05:21.000000 +0000
+++ quant.py 2024-12-17 02:17:28.697132 +0000
@@ -18,11 +18,12 @@
i8 = IntegerType.get_signless(8)
any = Type.parse("!quant.any<i8<-8:7>:f32>")
uniform = Type.parse("!quant.uniform<i8<-8:7>:f32, 0.99872:127>")
per_axis = Type.parse("!quant.uniform<i8:f32:1, {2.0e+2,0.99872:120}>")
sub_channel = Type.parse(
- "!quant.uniform<i8:f32:{0:1,1:2}, {{2.0:10, 3.0:20}, {4.0:30, 5.0:40}}>")
+ "!quant.uniform<i8:f32:{0:1,1:2}, {{2.0:10, 3.0:20}, {4.0:30, 5.0:40}}>"
+ )
calibrated = Type.parse("!quant.calibrated<f32<-0.998:1.2321>>")
assert not quant.QuantizedType.isinstance(i8)
assert quant.QuantizedType.isinstance(any)
assert quant.QuantizedType.isinstance(uniform)
@@ -136,15 +137,16 @@
f32 = F32Type.get()
sub_channel = quant.UniformQuantizedSubChannelType.get(
quant.QuantizedType.FLAG_SIGNED,
i8,
f32,
- DenseElementsAttr.get(np.asarray(
- [2.0, 3.0, 4.0, 5.0], np.float32).reshape(2, 2)),
- DenseElementsAttr.get(np.asarray(
- [10, 20, 30, 40], np.int8).reshape(2, 2)),
- [0, 1], [1, 2],
+ DenseElementsAttr.get(
+ np.asarray([2.0, 3.0, 4.0, 5.0], np.float32).reshape(2, 2)
+ ),
+ DenseElementsAttr.get(np.asarray([10, 20, 30, 40], np.int8).reshape(2, 2)),
+ [0, 1],
+ [1, 2],
storage_type_min=quant.QuantizedType.default_minimum_for_integer(
is_signed=True, integral_width=8
),
storage_type_max=quant.QuantizedType.default_maximum_for_integer(
is_signed=True, integral_width=8
@@ -162,11 +164,12 @@
# CHECK: [30 40]]
print(f"zero-points: {np.asarray(sub_channel.zero_points)}")
# CHECK: !quant.uniform<i8:f32:{0:1,1:2}, {{\{}}{2.000000e+00:10, 3.000000e+00:20}, {4.000000e+00:30, 5.000000e+00:40}}>
print(sub_channel)
assert sub_channel == Type.parse(
- "!quant.uniform<i8:f32:{0:1,1:2},{{2.0:10, 3.0:20}, {4.0:30, 5.0:40}}>")
+ "!quant.uniform<i8:f32:{0:1,1:2},{{2.0:10, 3.0:20}, {4.0:30, 5.0:40}}>"
+ )
# CHECK-LABEL: TEST: test_calibrated_type
@run
def test_calibrated_type():
``````````
</details>
https://github.com/llvm/llvm-project/pull/120172
More information about the Mlir-commits
mailing list