From a021cb1b6e2035cf0a0c6841307aecc48d38227b Mon Sep 17 00:00:00 2001 From: pengwa Date: Fri, 28 Jul 2023 12:41:22 +0800 Subject: [PATCH] Allow creating ConstantScalarNode for double type (#16797) ### Allow creating ConstantScalarNode for double type Allow create ConstantScalarNode for double type. Looks double type is not respected when creating constant. So fix it. ``` onnxruntime::python::addObjectMethodsForTraining(pybind11::module&, onnxruntime::python::ExecutionProviderRegistrationFn):: [ONNXRuntimeError] : 1 : FAIL : Type Error: Type parameter (T) of Optype (Sub) bound to different types (tensor(double) and tensor(float) in node (/_original_module/_original_model/gpt_neox/layers.0/input_layernorm/Pow_Grad/Sub_1). ``` --- orttraining/orttraining/core/graph/gradient_builder_base.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/orttraining/orttraining/core/graph/gradient_builder_base.h b/orttraining/orttraining/core/graph/gradient_builder_base.h index 67f32fe3ec..2d8a87f6d4 100644 --- a/orttraining/orttraining/core/graph/gradient_builder_base.h +++ b/orttraining/orttraining/core/graph/gradient_builder_base.h @@ -269,6 +269,10 @@ class GradientBuilderBase { return ConstantScalarNode(BFloat16(value), {1}, arg_name); } + if (elem_type == ONNX_NAMESPACE::TensorProto_DataType_DOUBLE) { + return ConstantScalarNode(double(value), {1}, arg_name); + } + #if !defined(DISABLE_FLOAT8_TYPES) if (elem_type == ONNX_NAMESPACE::TensorProto_DataType_FLOAT8E4M3FN) { @@ -289,6 +293,9 @@ class GradientBuilderBase { #endif + ORT_ENFORCE(elem_type == ONNX_NAMESPACE::TensorProto_DataType_FLOAT, + "Unsupported element type for constant node: ", elem_type); + return ConstantScalarNode(value, {1}, arg_name); }