Skip to content

Commit

Permalink
Don't fail in constant folding if we try to materialize a DT_VARIANT …
Browse files Browse the repository at this point in the history
…or DT_RESOURCE.

Addresses: #29525

PiperOrigin-RevId: 257703800
  • Loading branch information
tensorflower-gardener committed Jul 11, 2019
1 parent c7973b0 commit 2417464
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tensorflow/core/grappler/optimizers/constant_folding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,9 @@ Status CreateConstantTensorAttrValue(DataType type, double value,
SET_TENSOR_VAL_CASE(DT_QUINT8, int32, int);
SET_TENSOR_VAL_CASE(DT_BOOL, bool, bool);
default:
return errors::InvalidArgument("Unsupported type: ", type);
return errors::InvalidArgument(
"Unsupported type in CreateConstantTensorAttrValue: ",
DataTypeString(type));
}
return Status::OK();
}
Expand Down Expand Up @@ -1888,13 +1890,15 @@ Status ConstantFolding::ReplaceOperationWithConstant(
double value, const GraphProperties& properties,
const TensorShapeProto& shape, NodeDef* node, GraphDef* graph) {
const DataType dtype = GetDataTypeFromNodeOrProps(*node, properties);
if (dtype == DT_INVALID) {
AttrValue tensor_attr;
Status s = CreateConstantTensorAttrValue(dtype, value, shape, &tensor_attr);
if (!s.ok()) {
// Fail gracefully without mutating the graph.
VLOG(1) << "Failed to replace node " << node->name() << " of type "
<< DataTypeString(dtype) << " with constant tensor of value "
<< value;
return Status::OK();
}

AttrValue tensor_attr;
TF_RETURN_IF_ERROR(
CreateConstantTensorAttrValue(dtype, value, shape, &tensor_attr));
return ReplaceOperationWithConstantTensor(dtype, tensor_attr.mutable_tensor(),
node, graph);
}
Expand Down

0 comments on commit 2417464

Please sign in to comment.