Created
July 2, 2025 21:50
-
-
Save justinchuby/bc5b40213b0e2319eeb717b524726664 to your computer and use it in GitHub Desktop.
Cast verification
This file contains hidden or 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
"""Verify the cast values""" | |
import os | |
import onnx | |
import onnx_ir as ir | |
DIR = "onnx/backend/test/data/node/" | |
def verify_one_case(path: str): | |
test_name = os.path.basename(path) | |
input_path = os.path.join(path, "test_data_set_0", "input_0.pb") | |
output_path = os.path.join(path, "test_data_set_0", "output_0.pb") | |
input_tensor = ir.from_proto(onnx.load_tensor(input_path)) | |
output_tensor = ir.from_proto(onnx.load_tensor(output_path)) | |
print("Test", test_name) | |
print(" Input:", input_tensor) | |
print(" Input Numpy:", input_tensor.numpy()) | |
print() | |
print(" Input Bytes:", input_tensor.tobytes().hex(" ")) | |
print() | |
print(" Output:", output_tensor) | |
print(" Output Numpy:", output_tensor.numpy()) | |
print() | |
print(" Output Bytes:", output_tensor.tobytes().hex(" ")) | |
print() | |
print("--------------------") | |
def main(): | |
for file in sorted(os.listdir(DIR)): | |
if file.startswith("test_cast_") and "STRING" not in file: | |
path = os.path.join(DIR, file) | |
verify_one_case(path) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test test_cast_BFLOAT16_to_FLOAT
Input: TensorProtoTensor<BFLOAT16,[3,4]>(name='x')
Input Numpy: [[0.478516 0.480469 0.5 0.820312]
[0.470703 0.816406 0.210938 0.722656]
[nan inf inf -inf]]
[0.47070312 0.81640625 0.2109375 0.72265625]
[ nan inf inf -inf]]
0 80 7f 00 00 80 7f 00 00 80 ff
Test test_cast_DOUBLE_to_FLOAT
Input: TensorProtoTensor<DOUBLE,[3,4]>(name='x')
Input Numpy: [[0.47892547 0.48033667 0.49968487 0.81910545]
[0.47031248 0.816468 0.21087195 0.72290379]
[ nan inf inf -inf]]
de 3f 00 00 00 80 81 20 ea 3f 00 00 00 20 da fd ca 3f 00 00 00 20 07 22 e7 3f 00 00 00 00 00 00 f8 7f 00 00 00 00 00 00 f0 7f 00 00 00 00 00 00 f0 7f 00 00 00 00 00 00 f0 ff
Output: TensorProtoTensor<FLOAT,[3,4]>(name='x')
Output Numpy: [[0.47892547 0.48033667 0.49968487 0.81910545]
[0.47031248 0.816468 0.21087195 0.7229038 ]
[ nan inf inf -inf]]
0 80 7f 00 00 80 7f 00 00 80 ff
Test test_cast_DOUBLE_to_FLOAT16
Input: TensorProtoTensor<DOUBLE,[3,4]>(name='x')
Input Numpy: [[0.47892547 0.48033667 0.49968487 0.81910545]
[0.47031248 0.816468 0.21087195 0.72290379]
[ nan inf inf -inf]]
de 3f 00 00 00 80 81 20 ea 3f 00 00 00 20 da fd ca 3f 00 00 00 20 07 22 e7 3f 00 00 00 00 00 00 f8 7f 00 00 00 00 00 00 f0 7f 00 00 00 00 00 00 f0 7f 00 00 00 00 00 00 f0 ff
Output: TensorProtoTensor<FLOAT16,[3,4]>(name='x')
Output Numpy: [[0.479 0.4802 0.4998 0.8193]
[0.4702 0.8164 0.2108 0.723 ]
[ nan inf inf -inf]]
Test test_cast_FLOAT16_to_DOUBLE
Input: TensorProtoTensor<FLOAT16,[3,4]>(name='x')
Input Numpy: [[0.479 0.4802 0.4998 0.8193]
[0.4702 0.8164 0.2108 0.723 ]
[ nan inf inf -inf]]
[0.47021484 0.81640625 0.21081543 0.72314453]
[ nan inf inf -inf]]
8 de 3f 00 00 00 00 00 20 ea 3f 00 00 00 00 00 fc ca 3f 00 00 00 00 00 24 e7 3f 00 00 00 00 00 00 f8 7f 00 00 00 00 00 00 f0 7f 00 00 00 00 00 00 f0 7f 00 00 00 00 00 00 f0 ff
Test test_cast_FLOAT16_to_FLOAT
Input: TensorProtoTensor<FLOAT16,[3,4]>(name='x')
Input Numpy: [[0.479 0.4802 0.4998 0.8193]
[0.4702 0.8164 0.2108 0.723 ]
[ nan inf inf -inf]]
[0.47021484 0.81640625 0.21081543 0.72314453]
[ nan inf inf -inf]]
0 80 7f 00 00 80 7f 00 00 80 ff
Test test_cast_FLOAT16_to_FLOAT4E2M1
Input: TensorProtoTensor<FLOAT16,[3,5]>(name='x')
Input Numpy: [[ 4.80e-01 2.50e-01 1.05e+00 -3.50e+00 -8.00e+00]
[ 9.00e+00 inf 1.19e-07 nan inf]
[ inf -inf -4.00e+00 1.00e-02 -0.00e+00]]
[-6 4 0 0 0]
[-1 -6 -2 -6 0]]
Test test_cast_FLOAT16_to_FLOAT8E4M3FN
Input: TensorProtoTensor<FLOAT16,[3,5]>(name='x')
Input Numpy: [[ 4.790e-01 4.802e-01 4.998e-01 8.193e-01 4.702e-01]
[ 7.231e-01 inf 1.192e-07 nan inf]
[ inf -inf -1.192e-07 1.192e-07 -inf]]
[0.75 448 0 nan 448]
[448 -448 -0 0 -448]]
Test test_cast_FLOAT16_to_FLOAT8E4M3FNUZ
Input: TensorProtoTensor<FLOAT16,[3,5]>(name='x')
Input Numpy: [[ 4.790e-01 4.802e-01 4.998e-01 8.193e-01 4.702e-01]
[ 7.231e-01 inf 1.192e-07 nan inf]
[ inf -inf -1.192e-07 1.192e-07 -inf]]
[0.75 240 0 nan 240]
[240 -240 0 0 -240]]
Test test_cast_FLOAT16_to_FLOAT8E5M2
Input: TensorProtoTensor<FLOAT16,[3,5]>(name='x')
Input Numpy: [[ 4.790e-01 4.802e-01 4.998e-01 8.193e-01 4.702e-01]
[ 7.231e-01 inf 1.192e-07 nan inf]
[ inf -inf -1.192e-07 1.192e-07 -inf]]
[0.75 57344 0 nan 57344]
[57344 -57344 -0 0 -57344]]
Test test_cast_FLOAT16_to_FLOAT8E5M2FNUZ
Input: TensorProtoTensor<FLOAT16,[3,5]>(name='x')
Input Numpy: [[ 4.790e-01 4.802e-01 4.998e-01 8.193e-01 4.702e-01]
[ 7.231e-01 inf 1.192e-07 nan inf]
[ inf -inf -1.192e-07 1.192e-07 -inf]]
[0.75 57344 0 nan 57344]
[57344 -57344 0 0 -57344]]
Test test_cast_FLOAT16_to_INT4
Input: TensorProtoTensor<FLOAT16,[5,5]>(name='x')
Input Numpy: [[-9. -8. -7. -6. -5.]
[-4. -3. -2. -1. 0.]
[ 1. 2. 3. 4. 5.]
[ 6. 7. 8. 9. 10.]
[11. 12. 13. 14. 15.]]
00 49 80 49 00 4a 80 4a 00 4b 80 4b
Output: TensorProtoTensor<INT4,[5,5]>(name='x')
Output Numpy: [[7 0 -7 -1 -5]
[-1 -3 -1 -1 -1]
[1 0 3 0 5]
[0 7 0 -7 -1]
[-5 -1 -3 -1 -1]]
Test test_cast_FLOAT16_to_UINT4
Input: TensorProtoTensor<FLOAT16,[5,5]>(name='x')
Input Numpy: [[-9. -8. -7. -6. -5.]
[-4. -3. -2. -1. 0.]
[ 1. 2. 3. 4. 5.]
[ 6. 7. 8. 9. 10.]
[11. 12. 13. 14. 15.]]
00 49 80 49 00 4a 80 4a 00 4b 80 4b
Output: TensorProtoTensor<UINT4,[5,5]>(name='x')
Output Numpy: [[7 0 9 0 11]
[0 13 0 15 0]
[1 0 3 0 5]
[0 7 0 9 0]
[11 0 13 0 15]]
Test test_cast_FLOAT4E2M1_to_FLOAT
Input: TensorProtoTensor<FLOAT4E2M1,[3,5]>(name='x')
Input Numpy: [[0 0 -6 -6 -1]
[-6 4 0 0 0]
[-1 -6 -2 -6 0]]
[ 6. 6. 0. -0. 6. ]
[ 6. -6. -4. 0. -0. ]]
0 c0 40 00 00 c0 40 00 00 c0 c0 00 00 80 c0 00 00 00 00 00 00 00 80
Test test_cast_FLOAT4E2M1_to_FLOAT16
Input: TensorProtoTensor<FLOAT4E2M1,[3,5]>(name='x')
Input Numpy: [[0 0 -6 -6 -1]
[-6 4 0 0 0]
[-1 -6 -2 -6 0]]
[ 6. 6. 0. -0. 6. ]
[ 6. -6. -4. 0. -0. ]]
Test test_cast_FLOAT8E4M3FNUZ_to_FLOAT
Input: TensorProtoTensor<FLOAT8E4M3FNUZ,[3,5]>(name='x')
Input Numpy: [[0.46875 0.46875 0.5 0.8125 0.46875]
[0.75 240 0 nan 240]
[240 -240 0 0 -240]]
[ 0.75 240. 0. nan 240. ]
[ 240. -240. 0. 0. -240. ]]
0 70 43 00 00 70 43 00 00 70 c3 00 00 00 00 00 00 00 00 00 00 70 c3
Test test_cast_FLOAT8E4M3FNUZ_to_FLOAT16
Input: TensorProtoTensor<FLOAT8E4M3FNUZ,[3,5]>(name='x')
Input Numpy: [[0.46875 0.46875 0.5 0.8125 0.46875]
[0.75 240 0 nan 240]
[240 -240 0 0 -240]]
[ 0.75 240. 0. nan 240. ]
[ 240. -240. 0. 0. -240. ]]
Test test_cast_FLOAT8E4M3FN_to_FLOAT
Input: TensorProtoTensor<FLOAT8E4M3FN,[3,5]>(name='x')
Input Numpy: [[0.46875 0.46875 0.5 0.8125 0.46875]
[0.75 448 0 nan 448]
[448 -448 -0 0 -448]]
[ 0.75 448. 0. nan 448. ]
[ 448. -448. -0. 0. -448. ]]
0 e0 43 00 00 e0 43 00 00 e0 c3 00 00 00 80 00 00 00 00 00 00 e0 c3
Test test_cast_FLOAT8E4M3FN_to_FLOAT16
Input: TensorProtoTensor<FLOAT8E4M3FN,[3,5]>(name='x')
Input Numpy: [[0.46875 0.46875 0.5 0.8125 0.46875]
[0.75 448 0 nan 448]
[448 -448 -0 0 -448]]
[ 0.75 448. 0. nan 448. ]
[ 448. -448. -0. 0. -448. ]]
Test test_cast_FLOAT8E5M2FNUZ_to_FLOAT
Input: TensorProtoTensor<FLOAT8E5M2FNUZ,[3,5]>(name='x')
Input Numpy: [[0.5 0.5 0.5 0.875 0.5]
[0.75 57344 0 nan 57344]
[57344 -57344 0 0 -57344]]
[ 7.5000e-01 5.7344e+04 0.0000e+00 nan 5.7344e+04]
[ 5.7344e+04 -5.7344e+04 0.0000e+00 0.0000e+00 -5.7344e+04]]
0 60 47 00 00 60 47 00 00 60 c7 00 00 00 00 00 00 00 00 00 00 60 c7
Test test_cast_FLOAT8E5M2FNUZ_to_FLOAT16
Input: TensorProtoTensor<FLOAT8E5M2FNUZ,[3,5]>(name='x')
Input Numpy: [[0.5 0.5 0.5 0.875 0.5]
[0.75 57344 0 nan 57344]
[57344 -57344 0 0 -57344]]
[ 7.500e-01 5.734e+04 0.000e+00 nan 5.734e+04]
[ 5.734e+04 -5.734e+04 0.000e+00 0.000e+00 -5.734e+04]]
Test test_cast_FLOAT8E5M2_to_FLOAT
Input: TensorProtoTensor<FLOAT8E5M2,[3,5]>(name='x')
Input Numpy: [[0.5 0.5 0.5 0.875 0.5]
[0.75 57344 0 nan 57344]
[57344 -57344 -0 0 -57344]]
[ 7.5000e-01 5.7344e+04 0.0000e+00 nan 5.7344e+04]
[ 5.7344e+04 -5.7344e+04 -0.0000e+00 0.0000e+00 -5.7344e+04]]
0 60 47 00 00 60 47 00 00 60 c7 00 00 00 80 00 00 00 00 00 00 60 c7
Test test_cast_FLOAT8E5M2_to_FLOAT16
Input: TensorProtoTensor<FLOAT8E5M2,[3,5]>(name='x')
Input Numpy: [[0.5 0.5 0.5 0.875 0.5]
[0.75 57344 0 nan 57344]
[57344 -57344 -0 0 -57344]]
[ 7.500e-01 5.734e+04 0.000e+00 nan 5.734e+04]
[ 5.734e+04 -5.734e+04 -0.000e+00 0.000e+00 -5.734e+04]]
Test test_cast_FLOAT_to_BFLOAT16
Input: TensorProtoTensor<FLOAT,[3,4]>(name='x')
Input Numpy: [[0.47892547 0.48033667 0.49968487 0.81910545]
[0.47031248 0.816468 0.21087195 0.7229038 ]
[ nan inf inf -inf]]
80 7f 00 00 80 7f 00 00 80 ff
Output: TensorProtoTensor<BFLOAT16,[3,4]>(name='x')
Output Numpy: [[0.478516 0.480469 0.5 0.820312]
[0.470703 0.816406 0.210938 0.722656]
[nan inf inf -inf]]
Test test_cast_FLOAT_to_DOUBLE
Input: TensorProtoTensor<FLOAT,[3,4]>(name='x')
Input Numpy: [[0.47892547 0.48033667 0.49968487 0.81910545]
[0.47031248 0.816468 0.21087195 0.7229038 ]
[ nan inf inf -inf]]
80 7f 00 00 80 7f 00 00 80 ff
Output: TensorProtoTensor<DOUBLE,[3,4]>(name='x')
Output Numpy: [[0.47892547 0.48033667 0.49968487 0.81910545]
[0.47031248 0.816468 0.21087195 0.72290379]
[ nan inf inf -inf]]
9 de 3f 00 00 00 80 81 20 ea 3f 00 00 00 20 da fd ca 3f 00 00 00 20 07 22 e7 3f 00 00 00 00 00 00 f8 7f 00 00 00 00 00 00 f0 7f 00 00 00 00 00 00 f0 7f 00 00 00 00 00 00 f0 ff
Test test_cast_FLOAT_to_FLOAT16
Input: TensorProtoTensor<FLOAT,[3,4]>(name='x')
Input Numpy: [[0.47892547 0.48033667 0.49968487 0.81910545]
[0.47031248 0.816468 0.21087195 0.7229038 ]
[ nan inf inf -inf]]
80 7f 00 00 80 7f 00 00 80 ff
Output: TensorProtoTensor<FLOAT16,[3,4]>(name='x')
Output Numpy: [[0.479 0.4802 0.4998 0.8193]
[0.4702 0.8164 0.2108 0.723 ]
[ nan inf inf -inf]]
Test test_cast_FLOAT_to_FLOAT4E2M1
Input: TensorProtoTensor<FLOAT,[3,5]>(name='x')
Input Numpy: [[ 4.80e-01 2.50e-01 1.05e+00 -3.50e+00 -8.00e+00]
[ 9.00e+00 1.00e+06 1.00e-07 nan inf]
[ inf -inf -4.00e+00 1.00e-02 -0.00e+00]]
80 7f 00 00 80 7f 00 00 80 ff 00 00 80 c0 0a d7 23 3c 00 00 00 80
Output: TensorProtoTensor<FLOAT4E2M1,[3,5]>(name='x')
Output Numpy: [[0 0 -6 -6 -1]
[-6 4 0 0 0]
[-1 -6 -2 -6 0]]
Test test_cast_FLOAT_to_FLOAT8E4M3FN
Input: TensorProtoTensor<FLOAT,[3,5]>(name='x')
Input Numpy: [[ 4.7892547e-01 4.8033667e-01 4.9968487e-01 8.1910545e-01
4.7031248e-01]
[ 7.2290379e-01 1.0000000e+06 1.0000000e-07 nan
inf]
[ inf -inf -1.0000000e-07 1.0000000e-07
-1.0000000e+06]]
80 7f 00 00 80 7f 00 00 80 ff 95 bf d6 b3 95 bf d6 33 00 24 74 c9
Output: TensorProtoTensor<FLOAT8E4M3FN,[3,5]>(name='x')
Output Numpy: [[0.46875 0.46875 0.5 0.8125 0.46875]
[0.75 448 0 nan 448]
[448 -448 -0 0 -448]]
Test test_cast_FLOAT_to_FLOAT8E4M3FNUZ
Input: TensorProtoTensor<FLOAT,[3,5]>(name='x')
Input Numpy: [[ 4.7892547e-01 4.8033667e-01 4.9968487e-01 8.1910545e-01
4.7031248e-01]
[ 7.2290379e-01 1.0000000e+06 1.0000000e-07 nan
inf]
[ inf -inf -1.0000000e-07 1.0000000e-07
-1.0000000e+06]]
80 7f 00 00 80 7f 00 00 80 ff 95 bf d6 b3 95 bf d6 33 00 24 74 c9
Output: TensorProtoTensor<FLOAT8E4M3FNUZ,[3,5]>(name='x')
Output Numpy: [[0.46875 0.46875 0.5 0.8125 0.46875]
[0.75 240 0 nan 240]
[240 -240 0 0 -240]]
Test test_cast_FLOAT_to_FLOAT8E5M2
Input: TensorProtoTensor<FLOAT,[3,5]>(name='x')
Input Numpy: [[ 4.7892547e-01 4.8033667e-01 4.9968487e-01 8.1910545e-01
4.7031248e-01]
[ 7.2290379e-01 1.0000000e+06 1.0000000e-07 nan
inf]
[ inf -inf -1.0000000e-07 1.0000000e-07
-1.0000000e+06]]
80 7f 00 00 80 7f 00 00 80 ff 95 bf d6 b3 95 bf d6 33 00 24 74 c9
Output: TensorProtoTensor<FLOAT8E5M2,[3,5]>(name='x')
Output Numpy: [[0.5 0.5 0.5 0.875 0.5]
[0.75 57344 0 nan 57344]
[57344 -57344 -0 0 -57344]]
Test test_cast_FLOAT_to_FLOAT8E5M2FNUZ
Input: TensorProtoTensor<FLOAT,[3,5]>(name='x')
Input Numpy: [[ 4.7892547e-01 4.8033667e-01 4.9968487e-01 8.1910545e-01
4.7031248e-01]
[ 7.2290379e-01 1.0000000e+06 1.0000000e-07 nan
inf]
[ inf -inf -1.0000000e-07 1.0000000e-07
-1.0000000e+06]]
80 7f 00 00 80 7f 00 00 80 ff 95 bf d6 b3 95 bf d6 33 00 24 74 c9
Output: TensorProtoTensor<FLOAT8E5M2FNUZ,[3,5]>(name='x')
Output Numpy: [[0.5 0.5 0.5 0.875 0.5]
[0.75 57344 0 nan 57344]
[57344 -57344 0 0 -57344]]
Test test_cast_FLOAT_to_INT4
Input: TensorProtoTensor<FLOAT,[5,5]>(name='x')
Input Numpy: [[-9. -8. -7. -6. -5.]
[-4. -3. -2. -1. 0.]
[ 1. 2. 3. 4. 5.]
[ 6. 7. 8. 9. 10.]
[11. 12. 13. 14. 15.]]
00 00 00 00 80 3f 00 00 00 40 00 00 40 40 00 00 80 40 00 00 a0 40 00 00 c0 40 00 00 e0 40 00 00 00 41 00 00 10 41 00 00 20 41 00 00 30 41 00 00 40 41 00 00 50 41 00 00 60 41 00 00 70 41
Output: TensorProtoTensor<INT4,[5,5]>(name='x')
Output Numpy: [[7 0 -7 -1 -5]
[-1 -3 -1 -1 -1]
[1 0 3 0 5]
[0 7 0 -7 -1]
[-5 -1 -3 -1 -1]]
Test test_cast_FLOAT_to_UINT4
Input: TensorProtoTensor<FLOAT,[5,5]>(name='x')
Input Numpy: [[-9. -8. -7. -6. -5.]
[-4. -3. -2. -1. 0.]
[ 1. 2. 3. 4. 5.]
[ 6. 7. 8. 9. 10.]
[11. 12. 13. 14. 15.]]
00 00 00 00 80 3f 00 00 00 40 00 00 40 40 00 00 80 40 00 00 a0 40 00 00 c0 40 00 00 e0 40 00 00 00 41 00 00 10 41 00 00 20 41 00 00 30 41 00 00 40 41 00 00 50 41 00 00 60 41 00 00 70 41
Output: TensorProtoTensor<UINT4,[5,5]>(name='x')
Output Numpy: [[7 0 9 0 11]
[0 13 0 15 0]
[1 0 3 0 5]
[0 7 0 9 0]
[11 0 13 0 15]]
Test test_cast_INT4_to_FLOAT
Input: TensorProtoTensor<INT4,[5,5]>(name='x')
Input Numpy: [[7 0 -7 -1 -5]
[-1 -3 -1 -1 -1]
[1 0 3 0 5]
[0 7 0 -7 -1]
[-5 -1 -3 -1 -1]]
[-4. -3. -2. -1. 0.]
[ 1. 2. 3. 4. 5.]
[ 6. 7. -8. -7. -6.]
[-5. -4. -3. -2. -1.]]
0 00 00 00 00 80 3f 00 00 00 40 00 00 40 40 00 00 80 40 00 00 a0 40 00 00 c0 40 00 00 e0 40 00 00 00 c1 00 00 e0 c0 00 00 c0 c0 00 00 a0 c0 00 00 80 c0 00 00 40 c0 00 00 00 c0 00 00 80 bf
Test test_cast_INT4_to_FLOAT16
Input: TensorProtoTensor<INT4,[5,5]>(name='x')
Input Numpy: [[7 0 -7 -1 -5]
[-1 -3 -1 -1 -1]
[1 0 3 0 5]
[0 7 0 -7 -1]
[-5 -1 -3 -1 -1]]
[-4. -3. -2. -1. 0.]
[ 1. 2. 3. 4. 5.]
[ 6. 7. -8. -7. -6.]
[-5. -4. -3. -2. -1.]]
7 00 c6 00 c5 00 c4 00 c2 00 c0 00 bc
Test test_cast_INT4_to_INT8
Input: TensorProtoTensor<INT4,[5,5]>(name='x')
Input Numpy: [[7 0 -7 -1 -5]
[-1 -3 -1 -1 -1]
[1 0 3 0 5]
[0 7 0 -7 -1]
[-5 -1 -3 -1 -1]]
[-4 -3 -2 -1 0]
[ 1 2 3 4 5]
[ 6 7 -8 -7 -6]
[-5 -4 -3 -2 -1]]
Test test_cast_UINT4_to_FLOAT
Input: TensorProtoTensor<UINT4,[5,5]>(name='x')
Input Numpy: [[7 0 9 0 11]
[0 13 0 15 0]
[1 0 3 0 5]
[0 7 0 9 0]
[11 0 13 0 15]]
[12. 13. 14. 15. 0.]
[ 1. 2. 3. 4. 5.]
[ 6. 7. 8. 9. 10.]
[11. 12. 13. 14. 15.]]
0 00 00 00 00 80 3f 00 00 00 40 00 00 40 40 00 00 80 40 00 00 a0 40 00 00 c0 40 00 00 e0 40 00 00 00 41 00 00 10 41 00 00 20 41 00 00 30 41 00 00 40 41 00 00 50 41 00 00 60 41 00 00 70 41
Test test_cast_UINT4_to_FLOAT16
Input: TensorProtoTensor<UINT4,[5,5]>(name='x')
Input Numpy: [[7 0 9 0 11]
[0 13 0 15 0]
[1 0 3 0 5]
[0 7 0 9 0]
[11 0 13 0 15]]
[12. 13. 14. 15. 0.]
[ 1. 2. 3. 4. 5.]
[ 6. 7. 8. 9. 10.]
[11. 12. 13. 14. 15.]]
8 00 49 80 49 00 4a 80 4a 00 4b 80 4b
Test test_cast_UINT4_to_UINT8
Input: TensorProtoTensor<UINT4,[5,5]>(name='x')
Input Numpy: [[7 0 9 0 11]
[0 13 0 15 0]
[1 0 3 0 5]
[0 7 0 9 0]
[11 0 13 0 15]]
[12 13 14 15 0]
[ 1 2 3 4 5]
[ 6 7 8 9 10]
[11 12 13 14 15]]
Test test_cast_no_saturate_FLOAT16_to_FLOAT8E4M3FN
Input: TensorProtoTensor<FLOAT16,[3,5]>(name='x')
Input Numpy: [[ 4.790e-01 4.802e-01 4.998e-01 8.193e-01 4.702e-01]
[ 7.231e-01 inf 1.192e-07 nan inf]
[ inf -inf -1.192e-07 1.192e-07 -inf]]
[0.75 nan 0 nan nan]
[nan nan -0 0 nan]]
Test test_cast_no_saturate_FLOAT16_to_FLOAT8E4M3FNUZ
Input: TensorProtoTensor<FLOAT16,[3,5]>(name='x')
Input Numpy: [[ 4.790e-01 4.802e-01 4.998e-01 8.193e-01 4.702e-01]
[ 7.231e-01 inf 1.192e-07 nan inf]
[ inf -inf -1.192e-07 1.192e-07 -inf]]
[0.75 nan 0 nan nan]
[nan nan 0 0 nan]]
Test test_cast_no_saturate_FLOAT16_to_FLOAT8E5M2
Input: TensorProtoTensor<FLOAT16,[3,5]>(name='x')
Input Numpy: [[ 4.790e-01 4.802e-01 4.998e-01 8.193e-01 4.702e-01]
[ 7.231e-01 inf 1.192e-07 nan inf]
[ inf -inf -1.192e-07 1.192e-07 -inf]]
[0.75 inf 0 nan inf]
[inf -inf -0 0 -inf]]
Test test_cast_no_saturate_FLOAT16_to_FLOAT8E5M2FNUZ
Input: TensorProtoTensor<FLOAT16,[3,5]>(name='x')
Input Numpy: [[ 4.790e-01 4.802e-01 4.998e-01 8.193e-01 4.702e-01]
[ 7.231e-01 inf 1.192e-07 nan inf]
[ inf -inf -1.192e-07 1.192e-07 -inf]]
[0.75 nan 0 nan nan]
[nan nan 0 0 nan]]
Test test_cast_no_saturate_FLOAT_to_FLOAT8E4M3FN
Input: TensorProtoTensor<FLOAT,[3,5]>(name='x')
Input Numpy: [[ 4.7892547e-01 4.8033667e-01 4.9968487e-01 8.1910545e-01
4.7031248e-01]
[ 7.2290379e-01 1.0000000e+06 1.0000000e-07 nan
inf]
[ inf -inf -1.0000000e-07 1.0000000e-07
-1.0000000e+06]]
80 7f 00 00 80 7f 00 00 80 ff 95 bf d6 b3 95 bf d6 33 00 24 74 c9
Output: TensorProtoTensor<FLOAT8E4M3FN,[3,5]>(name='x')
Output Numpy: [[0.46875 0.46875 0.5 0.8125 0.46875]
[0.75 nan 0 nan nan]
[nan nan -0 0 nan]]
Test test_cast_no_saturate_FLOAT_to_FLOAT8E4M3FNUZ
Input: TensorProtoTensor<FLOAT,[3,5]>(name='x')
Input Numpy: [[ 4.7892547e-01 4.8033667e-01 4.9968487e-01 8.1910545e-01
4.7031248e-01]
[ 7.2290379e-01 1.0000000e+06 1.0000000e-07 nan
inf]
[ inf -inf -1.0000000e-07 1.0000000e-07
-1.0000000e+06]]
80 7f 00 00 80 7f 00 00 80 ff 95 bf d6 b3 95 bf d6 33 00 24 74 c9
Output: TensorProtoTensor<FLOAT8E4M3FNUZ,[3,5]>(name='x')
Output Numpy: [[0.46875 0.46875 0.5 0.8125 0.46875]
[0.75 nan 0 nan nan]
[nan nan 0 0 nan]]
Test test_cast_no_saturate_FLOAT_to_FLOAT8E5M2
Input: TensorProtoTensor<FLOAT,[3,5]>(name='x')
Input Numpy: [[ 4.7892547e-01 4.8033667e-01 4.9968487e-01 8.1910545e-01
4.7031248e-01]
[ 7.2290379e-01 1.0000000e+06 1.0000000e-07 nan
inf]
[ inf -inf -1.0000000e-07 1.0000000e-07
-1.0000000e+06]]
80 7f 00 00 80 7f 00 00 80 ff 95 bf d6 b3 95 bf d6 33 00 24 74 c9
Output: TensorProtoTensor<FLOAT8E5M2,[3,5]>(name='x')
Output Numpy: [[0.5 0.5 0.5 0.875 0.5]
[0.75 inf 0 nan inf]
[inf -inf -0 0 -inf]]
Test test_cast_no_saturate_FLOAT_to_FLOAT8E5M2FNUZ
Input: TensorProtoTensor<FLOAT,[3,5]>(name='x')
Input Numpy: [[ 4.7892547e-01 4.8033667e-01 4.9968487e-01 8.1910545e-01
4.7031248e-01]
[ 7.2290379e-01 1.0000000e+06 1.0000000e-07 nan
inf]
[ inf -inf -1.0000000e-07 1.0000000e-07
-1.0000000e+06]]
80 7f 00 00 80 7f 00 00 80 ff 95 bf d6 b3 95 bf d6 33 00 24 74 c9
Output: TensorProtoTensor<FLOAT8E5M2FNUZ,[3,5]>(name='x')
Output Numpy: [[0.5 0.5 0.5 0.875 0.5]
[0.75 nan 0 nan nan]
[nan nan 0 0 nan]]