code: def _convert_and_assert_per_example_weights_compatible(
      input_, per_example_weights, dtype):
    
    per_example_weights = tf.convert_to_tensor(
        per_example_weights, name='per_example_weights', dtype=dtype)
    if input_.get_shape().ndims:
      expected_length = input_.get_shape().dims[0]
      message = ('per_example_weights must have rank 1 and length %s, but was: %s'
                 % (expected_length, per_example_weights.get_shape()))
    else:
      expected_length = None
      message = ('per_example_weights must have rank 1 and length equal to the '
                 'first dimension of inputs (unknown), but was: %s'
                 % per_example_weights.get_shape())
  
    if per_example_weights.get_shape().ndims not in (1, None):
      raise ValueError(message)
  
    if not per_example_weights.get_shape().is_compatible_with((expected_length,)):
      raise ValueError(message)
  
    return per_example_weights
docs: Converts per_example_weights to a tensor and validates the shape.