parameters: (
        self, name, partitioner, shape=None, dtype=dtypes.float32,
        initializer=None, regularizer=None, reuse=None,
        trainable=True, collections=None, caching_device=None,
        validate_shape=True)
return_statement: return partitioned_var
docstring: Gets or creates a sharded variable list with these parameters.
  
      The `partitioner` must be a callable that accepts a fully defined
      `TensorShape` and returns a sequence of integers (the `partitions`).
      These integers describe how to partition the given sharded `Variable`
      along the given dimension.  That is, `partitions[1] = 3` means split
      the `Variable` into 3 shards along dimension 1.  Currently, sharding along
      only one axis is supported.
  
      If the list of variables with the given name (prefix) is already stored,
      we return the stored variables. Otherwise, we create a new one.
  
      Set `reuse` to `True` when you only want to reuse existing Variables.
      Set `reuse` to `False` when you only want to create new Variables.
      If `reuse` is `None` (the default), both new and existing variables are
      returned.
  
      If initializer is `None` (the default), the default initializer passed in
      the constructor is used. If that one is `None` too, we use a new
      `uniform_unit_scaling_initializer`. If initializer is a Tensor, we use
      it as a value and derive the shape from the initializer.
  
      If the initializer is a callable, then it will be called for each
      shard.  Otherwise the initializer should match the shape of the entire
      sharded Variable, and it will be sliced accordingly for each shard.
  
      Some useful partitioners are available.  See, e.g.,
      `variable_axis_size_partitioner` and `min_max_variable_partitioner`.
  
      Args:
        name: the name of the new or existing sharded variable.
        partitioner: Optional callable that accepts a fully defined `TensorShape`
          and `dtype` of the Variable to be created, and returns a list of
          partitions for each axis (currently only one axis can be partitioned).
        shape: shape of the new or existing sharded variable.
        dtype: type of the new or existing sharded variable
          (defaults to `DT_FLOAT`).
        initializer: initializer for the sharded variable.
        regularizer: a (Tensor -> Tensor or None) function; the result of
          applying it on a newly created variable will be added to the collection
          GraphKeys.REGULARIZATION_LOSSES and can be used for regularization.
        reuse: a Boolean or `None`. Controls reuse or creation of variables.
        trainable: If `True` also add the variable to the graph collection
          `GraphKeys.TRAINABLE_VARIABLES` (see tf.Variable).
        collections: List of graph collections keys to add the Variable to.
          Defaults to `[GraphKeys.VARIABLES]` (see tf.Variable).
        caching_device: Optional device string or function describing where the
          Variable should be cached for reading.  Defaults to the Variable's
          device.  If not `None`, caches on another device.  Typical use is to
          cache on the device where the Ops using the Variable reside, to
          deduplicate copying through `Switch` and other conditional statements.
        validate_shape: If False, allows the variable to be initialized with a
          value of unknown shape. If True, the default, the shape of initial_value
          must be known.
  
      Returns:
        A tuple `(shards, partitions)` where `shards` is the list of `Variable`
        shards and `partitions` is the output of the partitioner on the input
        shape.
  
      Raises:
        ValueError: when creating a new variable and shape is not declared,
          when reusing a variable and specifying a conflicting shape,
          when violating reuse during variable creation, or if an existing
          sharded variable exists for the given name but with different sharding.
docstring_summary: Gets or creates a sharded variable list with these parameters.
docstring_tokens: Gets or creates a sharded variable list with these parameters .
function: def _get_partitioned_variable(
        self, name, partitioner, shape=None, dtype=dtypes.float32,
        initializer=None, regularizer=None, reuse=None,
        trainable=True, collections=None, caching_device=None,
        validate_shape=True):
      """Gets or creates a sharded variable list with these parameters.
  
      The `partitioner` must be a callable that accepts a fully defined
      `TensorShape` and returns a sequence of integers (the `partitions`).
      These integers describe how to partition the given sharded `Variable`
      along the given dimension.  That is, `partitions[1] = 3` means split
      the `Variable` into 3 shards along dimension 1.  Currently, sharding along
      only one axis is supported.
  
      If the list of variables with the given name (prefix) is already stored,
      we return the stored variables. Otherwise, we create a new one.
  
      Set `reuse` to `True` when you only want to reuse existing Variables.
      Set `reuse` to `False` when you only want to create new Variables.
      If `reuse` is `None` (the default), both new and existing variables are
      returned.
  
      If initializer is `None` (the default), the default initializer passed in
      the constructor is used. If that one is `None` too, we use a new
      `uniform_unit_scaling_initializer`. If initializer is a Tensor, we use
      it as a value and derive the shape from the initializer.
  
      If the initializer is a callable, then it will be called for each
      shard.  Otherwise the initializer should match the shape of the entire
      sharded Variable, and it will be sliced accordingly for each shard.
  
      Some useful partitioners are available.  See, e.g.,
      `variable_axis_size_partitioner` and `min_max_variable_partitioner`.
  
      Args:
        name: the name of the new or existing sharded variable.
        partitioner: Optional callable that accepts a fully defined `TensorShape`
          and `dtype` of the Variable to be created, and returns a list of
          partitions for each axis (currently only one axis can be partitioned).
        shape: shape of the new or existing sharded variable.
        dtype: type of the new or existing sharded variable
          (defaults to `DT_FLOAT`).
        initializer: initializer for the sharded variable.
        regularizer: a (Tensor -> Tensor or None) function; the result of
          applying it on a newly created variable will be added to the collection
          GraphKeys.REGULARIZATION_LOSSES and can be used for regularization.
        reuse: a Boolean or `None`. Controls reuse or creation of variables.
        trainable: If `True` also add the variable to the graph collection
          `GraphKeys.TRAINABLE_VARIABLES` (see tf.Variable).
        collections: List of graph collections keys to add the Variable to.
          Defaults to `[GraphKeys.VARIABLES]` (see tf.Variable).
        caching_device: Optional device string or function describing where the
          Variable should be cached for reading.  Defaults to the Variable's
          device.  If not `None`, caches on another device.  Typical use is to
          cache on the device where the Ops using the Variable reside, to
          deduplicate copying through `Switch` and other conditional statements.
        validate_shape: If False, allows the variable to be initialized with a
          value of unknown shape. If True, the default, the shape of initial_value
          must be known.
  
      Returns:
        A tuple `(shards, partitions)` where `shards` is the list of `Variable`
        shards and `partitions` is the output of the partitioner on the input
        shape.
  
      Raises:
        ValueError: when creating a new variable and shape is not declared,
          when reusing a variable and specifying a conflicting shape,
          when violating reuse during variable creation, or if an existing
          sharded variable exists for the given name but with different sharding.
      """
  
      initializing_from_value = initializer is not None and isinstance(
          initializer, ops.Tensor)
      reuse_without_partition = reuse is True and partitioner is None
  
      if name in self._vars:
        raise ValueError(
            "A partitioner was provided, but an unpartitioned version of the "
            "variable was found: %s.  Perhaps a variable of the same name was "
            "already created without partitioning?" % name)
  
      shape = tensor_shape.as_shape(shape)
      if initializing_from_value:
        shape = shape.merge_with(initializer.get_shape())
  
      if not reuse_without_partition:
        if not shape.is_fully_defined():
          raise ValueError("Shape of a new partitioned variable (%s) must be "
                           "fully defined, but instead was %s." % (name, shape))
  
        if shape.ndims < 1:
          raise ValueError("A partitioned Variable must have rank at least 1, "
                           "shape: %s" % shape)
  
        partitions = partitioner(shape=shape, dtype=dtype)
  
        if not isinstance(partitions, collections_lib.Sequence):
          raise ValueError("Partitioner must return a sequence, but saw: %s"
                           % partitions)
  
        if len(partitions) != shape.ndims:
          raise ValueError(
              "Partitioner returned a partition list that does not match the "
              "Variable's rank: %s vs. %s" % (partitions, shape))
  
        if any([p < 1 for p in partitions]):
          raise ValueError(
              "Partitioner returned zero partitions for some axes: %s" %
              partitions)
  
      should_check = reuse is not None
  
      if name in self._partitioned_vars:
        if should_check and not reuse:
          raise ValueError(
              "Partitioned variable with name %s already exists. Did you mean to "
              "set reuse=True in VarScope?"
              % name)
  
        existing_var = self._partitioned_vars[name]
        if not shape.is_compatible_with(existing_var.get_shape()):
          raise ValueError(
              "Trying to reuse partitioned variable %s, but specified shape %s "
              "and found shape %s."
              % (name, shape, existing_var.get_shape()))
        if not dtype.is_compatible_with(existing_var.dtype):
          raise ValueError(
              "Trying to reuse partitioned variable %s, but specified dtype %s "
              "and found dtype %s."
              % (name, dtype.name, existing_var.dtype.name))
  
        # pylint: disable=protected-access
        if (not reuse_without_partition and
            existing_var._get_partitions() != partitions):
          raise ValueError(
              "Trying to reuse partitioned variable %s, but specified partitions "
              "%s and found partitions %s." %
              (name, partitions, existing_var._get_partitions()))
        # pylint: enable=protected-access
  
        return existing_var
  
      if should_check and reuse:
        raise ValueError("PartitionedVariable %s does not exist, or was not "
                         "created with tf.get_variable(). Did you mean to set "
                         "reuse=None in VarScope?" % name)
  
      slice_dim, slice_shape = _compute_slice_dim_and_shape(
          shape.as_list(), partitions)
  
      vs = []
      num_slices = partitions[slice_dim]
      num_slices_with_excess = shape[slice_dim].value % num_slices
  
      slice_offset = [0] * shape.ndims
  
      if "%s/part_0" % name in self._vars:
        if "%s/part_%d" % (name, num_slices - 1) not in self._vars:
          raise ValueError(
              "Partitioner returned a different partitioning than what was "
              "already found.  Partitioner returned %d shards, and shard "
              "%s/part_0 was found, but %s/part_%d was not."
              % (num_slices, name, name, num_slices - 1))
        if "%s/part_%d" % (name, num_slices) in self._vars:
          raise ValueError(
              "Partitioner returned a different partitioning than what was "
              "already found.  Partitioner returned %d shards, and shard "
              "%s/part_0 was found, but so was the extra shard %s/part_%d."
              % (num_slices, name, name, num_slices))
  
      for i in xrange(num_slices):
        var_shape = slice_shape[:]
        var_offset = slice_offset[:]
        if i < num_slices_with_excess:
          var_shape[slice_dim] += 1
        slice_offset[slice_dim] += var_shape[slice_dim]
  
        var_full_name = "%s/part_%d" % (name, i)
        with ops.op_scope([], var_full_name + "/PartitionedInitializer"):
          if initializer is None:
            init = init_ops.uniform_unit_scaling_initializer(
                full_shape=shape.as_list())
            init_shape = var_shape
          elif callable(initializer):
            init = initializer
            init_shape = var_shape
          elif isinstance(initializer, ops.Tensor):
            init = array_ops.slice(initializer, var_offset, var_shape)
            # Use the dtype of the given tensor.
            dtype = init.dtype.base_dtype
            init_shape = None
          else:
            init = ops.convert_to_tensor(initializer, dtype=dtype)
            init = array_ops.slice(init, var_offset, var_shape)
            init_shape = None
  
        with ops.name_scope(None):
          var = self._get_single_variable(
              name=var_full_name,
              shape=init_shape,
              dtype=dtype,
              initializer=init,
              regularizer=regularizer,
              reuse=reuse,
              trainable=trainable,
              collections=collections,
              caching_device=caching_device,
              validate_shape=validate_shape)
  
        # pylint: disable=protected-access
        var._set_save_slice_info(variables.Variable.SaveSliceInfo(
            name, shape.as_list(), var_offset, var_shape))
        vs.append(var)
        # pylint: enable=protected-access
  
        # pylint: disable=protected-access
      partitioned_var = variables._PartitionedVariable(name=name,
                                                       shape=shape,
                                                       dtype=dtype,
                                                       variable_list=vs,
                                                       partitions=partitions)
      # pylint: enable=protected-access
  
      self._partitioned_vars[name] = partitioned_var
      return partitioned_var
function_tokens: def _get_partitioned_variable ( self , name , partitioner , shape = None , dtype = dtypes . float32 , initializer = None , regularizer = None , reuse = None , trainable = True , collections = None , caching_device = None , validate_shape = True ) : initializing_from_value = initializer is not None and isinstance ( initializer , ops . Tensor ) reuse_without_partition = reuse is True and partitioner is None if name in self . _vars : raise ValueError ( "A partitioner was provided, but an unpartitioned version of the " "variable was found: %s.  Perhaps a variable of the same name was " "already created without partitioning?" % name ) shape = tensor_shape . as_shape ( shape ) if initializing_from_value : shape = shape . merge_with ( initializer . get_shape ( ) ) if not reuse_without_partition : if not shape . is_fully_defined ( ) : raise ValueError ( "Shape of a new partitioned variable (%s) must be " "fully defined, but instead was %s." % ( name , shape ) ) if shape . ndims < 1 : raise ValueError ( "A partitioned Variable must have rank at least 1, " "shape: %s" % shape ) partitions = partitioner ( shape = shape , dtype = dtype ) if not isinstance ( partitions , collections_lib . Sequence ) : raise ValueError ( "Partitioner must return a sequence, but saw: %s" % partitions ) if len ( partitions ) != shape . ndims : raise ValueError ( "Partitioner returned a partition list that does not match the " "Variable's rank: %s vs. %s" % ( partitions , shape ) ) if any ( [ p < 1 for p in partitions ] ) : raise ValueError ( "Partitioner returned zero partitions for some axes: %s" % partitions ) should_check = reuse is not None if name in self . _partitioned_vars : if should_check and not reuse : raise ValueError ( "Partitioned variable with name %s already exists. Did you mean to " "set reuse=True in VarScope?" % name ) existing_var = self . _partitioned_vars [ name ] if not shape . is_compatible_with ( existing_var . get_shape ( ) ) : raise ValueError ( "Trying to reuse partitioned variable %s, but specified shape %s " "and found shape %s." % ( name , shape , existing_var . get_shape ( ) ) ) if not dtype . is_compatible_with ( existing_var . dtype ) : raise ValueError ( "Trying to reuse partitioned variable %s, but specified dtype %s " "and found dtype %s." % ( name , dtype . name , existing_var . dtype . name ) ) # pylint: disable=protected-access if ( not reuse_without_partition and existing_var . _get_partitions ( ) != partitions ) : raise ValueError ( "Trying to reuse partitioned variable %s, but specified partitions " "%s and found partitions %s." % ( name , partitions , existing_var . _get_partitions ( ) ) ) # pylint: enable=protected-access return existing_var if should_check and reuse : raise ValueError ( "PartitionedVariable %s does not exist, or was not " "created with tf.get_variable(). Did you mean to set " "reuse=None in VarScope?" % name ) slice_dim , slice_shape = _compute_slice_dim_and_shape ( shape . as_list ( ) , partitions ) vs = [ ] num_slices = partitions [ slice_dim ] num_slices_with_excess = shape [ slice_dim ] . value % num_slices slice_offset = [ 0 ] * shape . ndims if "%s/part_0" % name in self . _vars : if "%s/part_%d" % ( name , num_slices - 1 ) not in self . _vars : raise ValueError ( "Partitioner returned a different partitioning than what was " "already found.  Partitioner returned %d shards, and shard " "%s/part_0 was found, but %s/part_%d was not." % ( num_slices , name , name , num_slices - 1 ) ) if "%s/part_%d" % ( name , num_slices ) in self . _vars : raise ValueError ( "Partitioner returned a different partitioning than what was " "already found.  Partitioner returned %d shards, and shard " "%s/part_0 was found, but so was the extra shard %s/part_%d." % ( num_slices , name , name , num_slices ) ) for i in xrange ( num_slices ) : var_shape = slice_shape [ : ] var_offset = slice_offset [ : ] if i < num_slices_with_excess : var_shape [ slice_dim ] += 1 slice_offset [ slice_dim ] += var_shape [ slice_dim ] var_full_name = "%s/part_%d" % ( name , i ) with ops . op_scope ( [ ] , var_full_name + "/PartitionedInitializer" ) : if initializer is None : init = init_ops . uniform_unit_scaling_initializer ( full_shape = shape . as_list ( ) ) init_shape = var_shape elif callable ( initializer ) : init = initializer init_shape = var_shape elif isinstance ( initializer , ops . Tensor ) : init = array_ops . slice ( initializer , var_offset , var_shape ) # Use the dtype of the given tensor. dtype = init . dtype . base_dtype init_shape = None else : init = ops . convert_to_tensor ( initializer , dtype = dtype ) init = array_ops . slice ( init , var_offset , var_shape ) init_shape = None with ops . name_scope ( None ) : var = self . _get_single_variable ( name = var_full_name , shape = init_shape , dtype = dtype , initializer = init , regularizer = regularizer , reuse = reuse , trainable = trainable , collections = collections , caching_device = caching_device , validate_shape = validate_shape ) # pylint: disable=protected-access var . _set_save_slice_info ( variables . Variable . SaveSliceInfo ( name , shape . as_list ( ) , var_offset , var_shape ) ) vs . append ( var ) # pylint: enable=protected-access # pylint: disable=protected-access partitioned_var = variables . _PartitionedVariable ( name = name , shape = shape , dtype = dtype , variable_list = vs , partitions = partitions ) # pylint: enable=protected-access self . _partitioned_vars [ name ] = partitioned_var return partitioned_var