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)::<lambda(onnxruntime::training::OrtModuleGraphBuilder*, const onnxruntime::training::TrainingGraphTransformerConfiguration&)> [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).
```
This commit is contained in:
pengwa 2023-07-28 12:41:22 +08:00 committed by GitHub
parent 634a3f2f28
commit a021cb1b6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}