q55180514 commented on code in PR #19590:
URL: https://github.com/apache/tvm/pull/19590#discussion_r3270940078


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -3787,6 +3787,41 @@ def _impl_v17(cls, bb, inputs, attr, params):
         return relax.Tuple([output, placeholder, placeholder])
 
 
+class RMSNormalization(OnnxOpConverter):
+    """Converts an onnx RMSNormalization node into an equivalent Relax 
expression."""
+
+    @classmethod
+    def _impl_v23(cls, bb, inputs, attr, params):
+        data = inputs[0]
+        scale = inputs[1]
+        axis = attr.get("axis", -1)
+        epsilon = attr.get("epsilon", 1e-05)
+        stash_type = attr.get("stash_type", 1)
+
+        # Determine normalization axes: from `axis` to the last dimension
+        ndim = len(data.struct_info.shape)
+        if axis < 0:
+            axis = ndim + axis
+        axes = list(range(axis, ndim))
+
+        # If stash_type requires float32 computation and input is not float32, 
cast
+        input_dtype = data.struct_info.dtype
+        if stash_type == 1 and input_dtype != "float32":
+            data_compute = relax.op.astype(data, "float32")
+            scale_compute = relax.op.astype(scale, "float32")
+        else:
+            data_compute = data
+            scale_compute = scale
+
+        output = relax.op.nn.rms_norm(data_compute, scale_compute, axes, 
epsilon)
+
+        # Cast back to original dtype if needed
+        if stash_type == 1 and input_dtype != "float32":
+            output = relax.op.astype(output, input_dtype)
+
+        return output

Review Comment:
   https://onnx.ai/onnx/operators/onnx__RMSNormalization.html .RMSNorm only 
have one ouput in onnx official spec.(Outputs:
   • Y (heterogeneous) - V: Output data tensor. Same shape as X)
   
   



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