tensorflow/compiler/mlir/tensorflow/transforms/tpu_sharding_identification_pass.cc
// Verify whether the given sharding can be applied to the given (tensor) type.
// (A bad sharding might mean failing tf.Split ops if the graph later executes
//  on CPU)
// If the sharding is incorrect, return failure. If it's good, or if we can't
// verify it, return success.
Verify whether the given sharding can be applied to the given (tensor) type.
(A bad sharding might mean failing tf.Split ops if the graph later executes
on CPU)
If the sharding is incorrect, return failure. If it's good, or if we can't
verify it, return success.
Verify whether the given sharding can be applied to the given ( tensor ) type . ( A bad sharding might mean failing tf . Split ops if the graph later executes on CPU ) If the sharding is incorrect return failure . If it ' s good or if we can ' t verify it return success .
LogicalResult VerifySharding(Type type, StringRef sharding_string) {
  xla::OpSharding sharding;
  if (!sharding.ParseFromString(sharding_string.str())) {
    return success();
  }
  if (sharding.type() != xla::OpSharding::OTHER) {
    return success();
  }
  if (RankedTensorType ranked_type = type.dyn_cast<RankedTensorType>()) {
    if (ranked_type.getRank() < sharding.tile_assignment_dimensions_size()) {
      return failure();
    }
  }
  return success();
}
LogicalResult VerifySharding ( Type type , StringRef sharding_string ) { xla :: OpSharding sharding ; if ( ! sharding . ParseFromString ( sharding_string . str ( ) ) ) { return success ( ) ; } if ( sharding . type ( ) != xla :: OpSharding :: OTHER ) { return success ( ) ; } if ( RankedTensorType ranked_type = type . dyn_cast < RankedTensorType > ( ) ) { if ( ranked_type . getRank ( ) < sharding . tile_assignment_dimensions_size ( ) ) { return failure ( ) ; } } return success ( ) ; }
Verify whether the given sharding can be applied to the given (tensor) type.
Verify whether the given sharding can be applied to the given ( tensor ) type .
// Some test cases use \01\02\03 as sharding, to test propagation. Treat // a non-proto sharding as valid, and don't verify further. // We currently only verify shardings that actually break a tensor apart.