class_docstr: An object use to hold the sharding policy for a Tensor.
class_docstr_tok: ["An","object","use","to","hold","the","sharding","policy","for","a","Tensor","."]
docstr: Sets the number of shards for the current policy.
  
  If the policy has been frozen then number_of_shards must match the
  existing setting.
  
  Args:
    number_of_shards: The number of shards to use in the policy.
  
  Raises:
    ValueError: If the policy has been frozen and number_of_shards
      differs from the frozen value; or number_of_shards <= 0.
docstr_tok: ["Sets","the","number","of","shards","for","the","current","policy",".","If","the","policy","has","been","frozen","then","number_of_shards","must","match","the","existing","setting",".","Args",":","number_of_shards",":","The","number","of","shards","to","use","in","the","policy",".","Raises",":","ValueError",":","If","the","policy","has","been","frozen","and","number_of_shards","differs","from","the","frozen","value",";","or","number_of_shards","<","=","0","."]
code: def set_number_of_shards(self, number_of_shards):
      """Sets the number of shards for the current policy.
  
      If the policy has been frozen then number_of_shards must match the
      existing setting.
  
      Args:
        number_of_shards: The number of shards to use in the policy.
  
      Raises:
        ValueError: If the policy has been frozen and number_of_shards
          differs from the frozen value; or number_of_shards <= 0.
      """
      if self._frozen:
          if self._number_of_shards != number_of_shards:
              raise ValueError(
                  f"Can't set sharding policy to use {number_of_shards} shards since "
                  f"it has been frozen to use {self._number_of_shards}"
              )
      else:
          if number_of_shards > 0:
              self._number_of_shards = number_of_shards
          else:
              raise ValueError(
                  f"Can't set sharding policy to use {number_of_shards} shards; "
                  "value must be > 0"
              )
  
file_path: tensorflow-upstream/tensorflow/python/tpu/tpu_sharding.py
imports: from tensorflow.python.framework import tensor_shape
label_desc: Use image node_id 6 for calling the ShardingPolicy obj's underlying member method code with example usage: obj.set_number_of_shards(number_of_shards) without return types