gemini-code-assist[bot] commented on code in PR #20006:
URL: https://github.com/apache/tvm/pull/20006#discussion_r3584422302


##########
tests/python/relax/test_frontend_onnx.py:
##########
@@ -5148,64 +5193,97 @@ def create_composite_reduce_test_parameters_axes_attr():
     return output
 
 
[email protected]("func, dynamic, opset", 
create_reduce_test_parameters_axes_attr())
-def test_all_reduce_funcs_axes_attr(func, dynamic, opset):
-    def verify_reduce_func(func, data, axis, keepdims):
-        inshape = data.shape
-        outshape = np.sum(data, axis=axis, keepdims=keepdims == 1).shape
+def _verify_reduce_numerical(
+    func: str,
+    opset: int,
+    *,
+    axes_as_input: bool,
+    axes,
+    noop_with_empty_axes: bool = False,
+    dynamic: bool = False,
+    keepdims: bool = False,
+):
+    input_shape = [3, 3, 3]
+    node_inputs = ["x"]
+    initializers = []
+    node_attrs = {"keepdims": keepdims}
 
-        if axis:
-            node = onnx.helper.make_node(
-                func, inputs=["x"], outputs=["y"], axes=axis, keepdims=keepdims
+    if axes_as_input:
+        node_attrs["noop_with_empty_axes"] = noop_with_empty_axes
+        if axes is not None:
+            axes_np = np.asarray(axes, dtype=np.int64)
+            initializers.append(
+                helper.make_tensor(
+                    name="reduce_axes",
+                    data_type=TensorProto.INT64,
+                    dims=axes_np.shape,
+                    vals=axes_np,
+                )
             )
-        else:
-            node = onnx.helper.make_node(func, inputs=["x"], outputs=["y"], 
keepdims=keepdims)
-
-        if dynamic:
-            in_list = ["?" for _ in range(len(inshape))]
-            out_list = ["?" for _ in range(len(outshape))]
-        else:
-            in_list = list(inshape)
-            out_list = list(outshape)
-        graph = helper.make_graph(
-            [node],
-            "reduce_test",
-            inputs=[helper.make_tensor_value_info("x", TensorProto.FLOAT, 
in_list)],
-            outputs=[helper.make_tensor_value_info("y", TensorProto.FLOAT, 
out_list)],
-        )
+            node_inputs.append("reduce_axes")
+    elif axes:
+        node_attrs["axes"] = axes
 
-        model = helper.make_model(graph, producer_name="reduce_test")
-        inputs_dict = {"x": data}
-        # Reduction ops accumulate arithmetic errors, so we use a higher 
tolerance.
-        check_correctness(model, inputs_dict, opset=opset, rtol=1e-4, 
atol=1e-4)
+    if axes_as_input and noop_with_empty_axes and not axes:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   When `axes` is `None` (representing an omitted axes input), `not axes` 
evaluates to `True`. This incorrectly triggers the `noop_with_empty_axes` 
behavior and sets `output_shape = input_shape`, whereas an omitted `axes` input 
should trigger reduction over all dimensions. We should explicitly check that 
`axes` is not `None` and is empty.
   
   ```suggestion
       if axes_as_input and noop_with_empty_axes and axes is not None and 
len(axes) == 0:
   ```



##########
tests/python/relax/test_frontend_onnx.py:
##########
@@ -5233,8 +5311,19 @@ def expected_input_shape(shape):
         parser_vars["axes_shape"] = axes_shape
         params.append('        reduce_axes: R.Tensor(axes_shape, 
dtype="int64")')
 
+    basic_reduce_op = {
+        "ReduceMax": R.max,
+        "ReduceMean": R.mean,
+        "ReduceMin": R.min,
+        "ReduceProd": R.prod,
+        "ReduceSum": R.sum,
+    }.get(func)
+
     if noop_with_empty_axes and not axes:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   When `axes` is `None` (representing an omitted axes input), `not axes` 
evaluates to `True`. This incorrectly triggers the `noop_with_empty_axes` 
condition and generates a no-op body (`gv = x`), whereas an omitted `axes` 
input should trigger reduction over all dimensions. We should explicitly check 
that `axes` is not `None` and is empty.
   
   ```suggestion
       if noop_with_empty_axes and axes is not None and len(axes) == 0:
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to