From a08b07b4da22f9113dcb0ee50f73449e7b43d180 Mon Sep 17 00:00:00 2001 From: geohotstan <135171913+geohotstan@users.noreply.github.com> Date: Sun, 30 Mar 2025 15:21:51 +0800 Subject: [PATCH] Bump onnx==1.17.0 (#9618) * bump * remove resize tf_crop_and_resize --------- Co-authored-by: chenyu --- .github/workflows/test.yml | 2 +- extra/onnx.py | 10 ++++------ setup.py | 2 +- test/external/external_test_onnx_backend.py | 5 ++++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fe08050b7f..24d748eb07 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -483,7 +483,7 @@ jobs: with: key: dsp-minimal deps: testing_minimal - pydeps: "onnx==1.16.0 onnxruntime pillow" + pydeps: "onnx==1.17.0 onnxruntime pillow" llvm: "true" - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 diff --git a/extra/onnx.py b/extra/onnx.py index 726e9099c9..04ed474950 100644 --- a/extra/onnx.py +++ b/extra/onnx.py @@ -464,7 +464,7 @@ def get_onnx_ops(): elif mode in ["floor", "ceil"]: index = getattr(index, mode)() else: raise ValueError(f"invalid {nearest_mode=}") return index.cast(dtypes.int32).clip(0, input_dim-1) - def _apply_transformation(index: Tensor, input_dim, scale_dim, roi_dim, mode): + def _apply_transformation(index: Tensor, input_dim, scale_dim, mode): # TODO: needs more testing, not confident in this # NOTE: their reference implementation differ from the implementation in their reference docs # https://github.com/onnx/onnx/blob/main/onnx/reference/ops/op_resize.py @@ -475,8 +475,7 @@ def get_onnx_ops(): elif mode == "asymmetric": index = index / scale_dim elif mode == "pytorch_half_pixel": index = (index + 0.5) / scale_dim - 0.5 if output_dim != 1 else Tensor([-0.5]) elif mode == "half_pixel_symmetric": index = input_dim / 2 * (1 - int(output_dim) / output_dim) + (index + 0.5) / scale_dim - 0.5 - elif mode == "tf_crop_and_resize": index = roi_dim[0] * (input_dim - 1) + index * ((roi_dim[1] - roi_dim[0]) * (input_dim - 1) / (output_dim - 1)) - else: raise ValueError(f"invalid {coordinate_transformation_mode=}") + else: raise NotImplementedError(f"invalid {coordinate_transformation_mode=}") return index.clip(0, input_dim-1) scales, sizes = (None if scales is None else scales[2-(X.ndim-len(scales)):]), (None if sizes is None else sizes[2-(X.ndim-len(sizes)):]) @@ -494,13 +493,12 @@ def get_onnx_ops(): scales = [size / input_shape for size, input_shape in zip(sizes, input_shape)] else: sizes = [int(sc*sh) for sc, sh in zip(scales, input_shape)] - regions = [[st, ed] for st, ed in zip(roi, roi[len(roi)//2:])] if isinstance(roi, list) and roi else [[0.0, 0.0]] * (X.ndim-2) # NOTE: this transformation makes it so that we can't just call Tensor.interpolate # in Tensor.interpolate, we use indexes without any transformation indexes = [] - for shape, size, scale, region in zip(input_shape, sizes, scales, regions): - indexes.append(_apply_transformation(Tensor.arange(size), shape, scale, region, coordinate_transformation_mode)) + for shape, size, scale in zip(input_shape, sizes, scales): + indexes.append(_apply_transformation(Tensor.arange(size), shape, scale, coordinate_transformation_mode)) if mode == "nearest": indexes = [_apply_nearest_mode(index, shape, nearest_mode) for (index, shape) in zip(indexes, input_shape)] diff --git a/setup.py b/setup.py index 23dc67ec23..2b8c70bd63 100644 --- a/setup.py +++ b/setup.py @@ -52,7 +52,7 @@ setup(name='tinygrad', ], 'testing': testing_minimal + [ "pillow", - "onnx==1.16.0", + "onnx==1.17.0", "onnx2torch", "onnxruntime", "opencv-python", diff --git a/test/external/external_test_onnx_backend.py b/test/external/external_test_onnx_backend.py index 972d7a0bc8..1869536e58 100644 --- a/test/external/external_test_onnx_backend.py +++ b/test/external/external_test_onnx_backend.py @@ -166,9 +166,12 @@ backend_test.exclude('test_resize_upsample_sizes_cubic_*') # unsure how to imple backend_test.exclude('test_ai_onnx_ml_tree_ensemble_*') # https://github.com/onnx/onnx/blob/main/onnx/reference/ops/aionnxml/op_tree_ensemble.py#L121 # rest of the failing tests +backend_test.exclude('test_resize_tf_crop_and_resize_cpu') # tf_crop_and_resize not implemented +backend_test.exclude('test_resize_tf_crop_and_resize_axes_2_3_cpu') # tf_crop_and_resize not implemented +backend_test.exclude('test_resize_tf_crop_and_resize_axes_3_2_cpu') # tf_crop_and_resize not implemented +backend_test.exclude('test_resize_tf_crop_and_resize_extrapolation_value_cpu') # tf_crop_and_resize value not implemented backend_test.exclude('test_resize_downsample_scales_linear_antialias_cpu') # antialias not implemented backend_test.exclude('test_resize_downsample_sizes_linear_antialias_cpu') # antialias not implemented -backend_test.exclude('test_resize_tf_crop_and_resize_cpu') # unsure about fill value after clip backend_test.exclude('test_ai_onnx_ml_label_encoder_tensor_value_only_mapping_cpu') # bad data type string backend_test.exclude('test_ai_onnx_ml_label_encoder_tensor_mapping_cpu') # bad data type string backend_test.exclude('test_group_normalization_*') # numerical inaccuracy problem. Current Group Normalization OP fails test