[XLA] Make shape inference error messages for the While HLO more readable. Build the error lazily.
PiperOrigin-RevId: 168531083
This commit is contained in:
parent
d10374e458
commit
99423416a4
@ -1816,14 +1816,18 @@ ShapeInference::InferDegenerateDimensionBroadcastShape(
|
|||||||
body.parameters_size());
|
body.parameters_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
string shape_string = tensorflow::strings::Printf(
|
auto shape_string = [&]() {
|
||||||
"condition: %s; body: %s; init: %s", condition.ShortDebugString().c_str(),
|
return tensorflow::strings::Printf(
|
||||||
body.ShortDebugString().c_str(), init.ShortDebugString().c_str());
|
"condition: %s; body: %s; init: %s",
|
||||||
|
ShapeUtil::HumanString(condition).c_str(),
|
||||||
|
ShapeUtil::HumanString(body).c_str(),
|
||||||
|
ShapeUtil::HumanString(init).c_str());
|
||||||
|
};
|
||||||
|
|
||||||
// Check the shapes of computation parameters and return types.
|
// Check the shapes of computation parameters and return types.
|
||||||
if (!ShapeUtil::ShapeIs(condition.result(), PRED, {})) {
|
if (!ShapeUtil::ShapeIs(condition.result(), PRED, {})) {
|
||||||
return InvalidArgument("condition must return a boolean; got %s",
|
return InvalidArgument("condition must return a boolean; got %s",
|
||||||
shape_string.c_str());
|
shape_string().c_str());
|
||||||
}
|
}
|
||||||
if (!ShapeUtil::Compatible(body.result(), condition.parameters(0)) ||
|
if (!ShapeUtil::Compatible(body.result(), condition.parameters(0)) ||
|
||||||
!ShapeUtil::Compatible(body.result(), body.parameters(0)) ||
|
!ShapeUtil::Compatible(body.result(), body.parameters(0)) ||
|
||||||
@ -1831,7 +1835,7 @@ ShapeInference::InferDegenerateDimensionBroadcastShape(
|
|||||||
return InvalidArgument(
|
return InvalidArgument(
|
||||||
"the parameter of condition and body, the result of the body, and init "
|
"the parameter of condition and body, the result of the body, and init "
|
||||||
"must all have the same shape; got %s",
|
"must all have the same shape; got %s",
|
||||||
shape_string.c_str());
|
shape_string().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return init;
|
return init;
|
||||||
|
Loading…
Reference in New Issue
Block a user