Repository: microsoft/onnxruntime
File: onnxruntime/core/providers/qnn/builder/opbuilder/rms_norm_op_builder.cc (C++)

Code before:
    TensorInfo scale_info = {};
    ORT_RETURN_IF_ERROR(qnn_model_wrapper.GetTensorInfo(inputs[SCALE_IDX], scale_info));

    std::vector<uint32_t> beta_shape = scale_info.shape;

    // Match beta datatype to scale for float types, use UFIXED_POINT_8 for INT types
    Qnn_DataType_t beta_data_type = QNN_DATATYPE_UFIXED_POINT_8;
    if (scale_info.qnn_data_type == QNN_DATATYPE_FLOAT_32 ||
        scale_info.qnn_data_type == QNN_DATATYPE_FLOAT_16) {
      beta_data_type = scale_info.qnn_data_type;
    }

    // Use appropriate quantization parameters for zero values
    QnnQuantParamsWrapper beta_quant_param;
    if (scale_info.quant_param.IsQuantized()) {
      float quant_scale = 1.0f;
      int32_t zero_point = 0;
      beta_quant_param = QnnQuantParamsWrapper(quant_scale, zero_point);
    }

    size_t beta_num_elements = 1;
    for (uint32_t dim : beta_shape) {
      beta_num_elements *= dim;
    }
    const size_t element_size = utils::GetElementSizeByType(beta_data_type);
    std::vector<uint8_t> beta_data(beta_num_elements * element_size, 0);

    const std::string beta_tensor_name = node_unit.Name() + "_beta_dummy";
    QnnTensorWrapper beta_tensor_wrapper(beta_tensor_name,
                                         QNN_TENSOR_TYPE_STATIC,
                                         beta_data_type,
                                         std::move(beta_quant_param),
                                         std::move(beta_shape),
                                         std::move(beta_data));

    ORT_RETURN_IF_NOT(qnn_model_wrapper.AddTensorWrapper(std::move(beta_tensor_wrapper)),
                      "Failed to add dummy beta tensor for QNN RMSNorm node.");
    input_names.push_back(beta_tensor_name);
  }

  return Status::OK();
}

Status RMSNormOpBuilder::ProcessAttributesAndOutputs(QnnModelWrapper& qnn_model_wrapper,
                                                     const NodeUnit& node_unit,
                                                     std::vector<std::string>&& input_names,
                                                     const logging::Logger& logger,
                                                     bool do_op_validation) const {
  NodeAttrHelper node_helper(node_unit);
  std::vector<std::string> param_tensor_names;


Review comment (refactor):
nit: can use the helper which uses SafeInt to compute the shape size
```suggestion
    const size_t beta_size_in_bytes = utils::GetQnnTensorDataSizeInBytes(beta_shape, beta_data_type);
    std::vector<uint8_t> beta_data(beta_size_in_bytes, 0);
```

Code after:
    std::vector<uint32_t> beta_shape = scale_info.shape;

    // Match beta datatype to scale for float types, use UFIXED_POINT_8 for INT types
    Qnn_DataType_t beta_data_type = QNN_DATATYPE_UFIXED_POINT_8;
    if (scale_info.qnn_data_type == QNN_DATATYPE_FLOAT_32 ||
        scale_info.qnn_data_type == QNN_DATATYPE_FLOAT_16) {
      beta_data_type = scale_info.qnn_data_type;
    }

    // Use appropriate quantization parameters for zero values
    QnnQuantParamsWrapper beta_quant_param;
    if (scale_info.quant_param.IsQuantized()) {
      float quant_scale = 1.0f;
      int32_t zero_point = 0;
      beta_quant_param = QnnQuantParamsWrapper(quant_scale, zero_point);
    }

    const size_t beta_size_in_bytes = utils::GetQnnTensorDataSizeInBytes(beta_shape, beta_data_type);
    std::vector<uint8_t> beta_data(beta_size_in_bytes, 0);
    const std::string beta_tensor_name = node_unit.Name() + "_beta_dummy";
    QnnTensorWrapper beta_tensor_wrapper(beta_tensor_name,
                                         QNN_TENSOR_TYPE_STATIC,
                                         beta_data_type,
                                         std::move(beta_quant_param),
                                         std::move(beta_shape),
                                         std::move(beta_data));

    ORT_RETURN_IF_NOT(qnn_model_wrapper.AddTensorWrapper(std::move(beta_tensor_wrapper)),
                      "Failed to add dummy beta tensor for QNN RMSNorm node.");
    input_names.push_back(beta_tensor_name);
  }

  return Status::OK();
}

Status RMSNormOpBuilder::ProcessAttributesAndOutputs(QnnModelWrapper& qnn_model_wrapper,
                                                     const NodeUnit& node_unit,
                                                     std::vector<std::string>&& input_names,
                                                     const logging::Logger& logger,
                                                     bool do_op_validation) const {
  NodeAttrHelper node_helper(node_unit);
  std::vector<std::string> param_tensor_names;

  // Process epsilon attribute
  const float epsilon = node_helper.Get("epsilon", 1e-05f);
  Qnn_Scalar_t epsilon_param = QNN_SCALAR_INIT;
  epsilon_param.dataType = QNN_DATATYPE_FLOAT_32;
  epsilon_param.floatValue = epsilon;
  QnnParamWrapper epsilon_param_wrapper(node_unit.Index(),
                                        node_unit.Name(),
                                        QNN_OP_RMS_NORM_PARAM_EPSILON,