@@ -3747,7 +3747,9 @@ for from_type, to_type in test_cases:
3747
3747
raise ValueError(
3748
3748
f"Conversion from {from_type} to {to_type} is not tested."
3749
3749
)
3750
- expected = vect_evaluate_float4e2m1_from_bits(subbyte.float32_to_float4e2m1_unpacked(np_fp32))
3750
+ expected = vect_evaluate_float4e2m1_from_bits(
3751
+ subbyte.float32_to_float4e2m1_unpacked(np_fp32)
3752
+ )
3751
3753
output = make_tensor(
3752
3754
"y", getattr(TensorProto, to_type), input_shape, expected.tolist()
3753
3755
)
@@ -20767,45 +20769,33 @@ expect(
20767
20769
20768
20770
20769
20771
<details>
20770
- <summary>e2m1 </summary>
20772
+ <summary>e4m3fn </summary>
20771
20773
20772
20774
```python
20773
20775
node = onnx.helper.make_node(
20774
20776
"QuantizeLinear",
20775
20777
inputs=["x", "y_scale", "y_zero_point"],
20776
20778
outputs=["y"],
20777
- axis=0,
20778
20779
)
20779
20780
20780
- x = np.array(
20781
- [
20782
- [0.0, 2.5, 4.8, 8.6],
20783
- [-30, -20, 6, 9],
20784
- [-0.0, -2.5, -4.8, -8.6],
20785
- ]
20786
- ).astype(np.float32)
20787
-
20788
- y_scale = np.asarray([2.0, 3.0, 4.0], dtype=np.float32)
20789
- y_zero_point = make_tensor(
20790
- "y_zero_point", TensorProto.FLOAT4E2M1, y_scale.shape, np.zeros_like(y_scale)
20791
- )
20792
- y = make_tensor(
20793
- "y", TensorProto.FLOAT4E2M1, x.shape, [0, 1, 2, 4, -6, -6, 2, 3, 0, -0.5, -1, -2]
20794
- )
20781
+ x = np.array([0.0, 1.0, 2.0, 100000.0, 200.0]).astype(np.float32)
20782
+ y_scale = np.float32(2)
20783
+ y_zero_point = make_tensor("y_zero_point", TensorProto.FLOAT8E4M3FN, [1], [0])
20784
+ y = make_tensor("y", TensorProto.FLOAT8E4M3FN, [5], [0, 0.5, 1, 448, 96])
20795
20785
20796
20786
expect(
20797
20787
node,
20798
20788
inputs=[x, y_scale, y_zero_point],
20799
20789
outputs=[y],
20800
- name="test_quantizelinear_float4e2m1 ",
20790
+ name="test_quantizelinear_e4m3fn ",
20801
20791
)
20802
20792
```
20803
20793
20804
20794
</details>
20805
20795
20806
20796
20807
20797
<details>
20808
- <summary>e4m3fn </summary>
20798
+ <summary>e5m2 </summary>
20809
20799
20810
20800
```python
20811
20801
node = onnx.helper.make_node(
@@ -20816,40 +20806,58 @@ node = onnx.helper.make_node(
20816
20806
20817
20807
x = np.array([0.0, 1.0, 2.0, 100000.0, 200.0]).astype(np.float32)
20818
20808
y_scale = np.float32(2)
20819
- y_zero_point = make_tensor("y_zero_point", TensorProto.FLOAT8E4M3FN , [1], [0])
20820
- y = make_tensor("y", TensorProto.FLOAT8E4M3FN , [5], [0, 0.5, 1, 448 , 96])
20809
+ y_zero_point = make_tensor("y_zero_point", TensorProto.FLOAT8E5M2 , [1], [0. 0])
20810
+ y = make_tensor("y", TensorProto.FLOAT8E5M2 , [5], [0, 0.5, 1, 49152 , 96])
20821
20811
20822
20812
expect(
20823
20813
node,
20824
20814
inputs=[x, y_scale, y_zero_point],
20825
20815
outputs=[y],
20826
- name="test_quantizelinear_e4m3fn ",
20816
+ name="test_quantizelinear_e5m2 ",
20827
20817
)
20828
20818
```
20829
20819
20830
20820
</details>
20831
20821
20832
20822
20833
20823
<details>
20834
- <summary>e5m2 </summary>
20824
+ <summary>float4e2m1 </summary>
20835
20825
20836
20826
```python
20837
20827
node = onnx.helper.make_node(
20838
20828
"QuantizeLinear",
20839
20829
inputs=["x", "y_scale", "y_zero_point"],
20840
20830
outputs=["y"],
20831
+ axis=0,
20841
20832
)
20842
20833
20843
- x = np.array([0.0, 1.0, 2.0, 100000.0, 200.0]).astype(np.float32)
20844
- y_scale = np.float32(2)
20845
- y_zero_point = make_tensor("y_zero_point", TensorProto.FLOAT8E5M2, [1], [0.0])
20846
- y = make_tensor("y", TensorProto.FLOAT8E5M2, [5], [0, 0.5, 1, 49152, 96])
20834
+ x = np.array(
20835
+ [
20836
+ [0.0, 2.5, 4.8, 8.6],
20837
+ [-30, -20, 6, 9],
20838
+ [-0.0, -2.5, -4.8, -8.6],
20839
+ ]
20840
+ ).astype(np.float32)
20841
+
20842
+ y_scale = np.asarray([2.0, 3.0, 4.0], dtype=np.float32)
20843
+ y_zero_point = make_tensor(
20844
+ "y_zero_point",
20845
+ TensorProto.FLOAT4E2M1,
20846
+ y_scale.shape,
20847
+ np.zeros_like(y_scale),
20848
+ )
20849
+ y = make_tensor(
20850
+ "y",
20851
+ TensorProto.FLOAT4E2M1,
20852
+ x.shape,
20853
+ [0, 1, 2, 4, -6, -6, 2, 3, 0, -0.5, -1, -2],
20854
+ )
20847
20855
20848
20856
expect(
20849
20857
node,
20850
20858
inputs=[x, y_scale, y_zero_point],
20851
20859
outputs=[y],
20852
- name="test_quantizelinear_e5m2 ",
20860
+ name="test_quantizelinear_float4e2m1 ",
20853
20861
)
20854
20862
```
20855
20863
0 commit comments