
    AVh                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ ddlmZ ddlmZ dd
Zd Zd Zd Zy	)z5Input-pipeline utilities for Distribution strategies.    )
distribute)dataset_ops)AutoShardPolicy)traverse)op_def_registry)ops)dataNc                 d   t        | t        j                        r| j                  ||      S | j	                         j
                  j                  t        j                  k7  rN|d}t        | t        j                        rt        j                  | |||      S t        j                  | |||      S | S )aB  Shard the input pipeline by sharding the underlying list of files.

  Args:
    dataset: A `tf.data.Dataset` instance, typically the result of a bunch of
      dataset transformations.
    num_shards: A `tf.int64` scalar `tf.Tensor`, representing the number of
        shards operating in parallel. Same usage as in `tf.data.Dataset.shard`.
    index: A `tf.int64` scalar `tf.Tensor`, representing the worker index.
      Same usage as in `tf.data.Dataset.shard`.
    num_replicas_in_sync: An integer representing the total number of replicas
      across all workers. This is used in the rewrite when sharding by data.

  Returns:
    A modified `Dataset` obtained by updating the pipeline sharded by the
    files. The input dataset will be returned if we cannot automatically
    determine a good way to shard the input dataset.
     )
isinstancedistribute_typesDistributedDatasetInterface
auto_shardoptionsexperimental_distributeauto_shard_policyr   OFF
data_types	DatasetV1r   _AutoShardDatasetV1_AutoShardDataset)dataset
num_shardsindexnum_replicas_in_syncs       V/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/distribute/input_ops.pyauto_shard_datasetr      s    $ )EEFj%00oo//AA#'://0++GZ,@B B ))':u*>@ @ N    c                     t        j                  |       }t        | j                  j                  |      }|| j                  j                     j
                  d   }t        j                  || j                        S )z&Returns a cloned version of `dataset`.r   )	r   obtain_all_variant_tensor_ops_clone_helper_variant_tensoropoutputsr   _VariantDatasetelement_spec)r   variant_tensor_ops
remap_dictnew_variant_tensors       r   _clone_datasetr*   >   sh    ==gFW44779KL*!'"9"9"<"<=EEaH		$	$%79M9M	NNr   c                 \    | j                   xs t        j                  | j                        S N)op_defr   gettype)r#   s    r   _get_op_defr0   F   s     		2o))"''22r   c           
      v   i }| j                   D ]0  }|j                  }||v st        ||      }|j                  |       2 g }| j                   D ]^  }|j                  }||v r$||   j                  d   }|j                  |       7|j                  |j                  |j                            ` t        j                         }|j                  | j                  || j                  D 	cg c]  }	|	j                   c}	| j                  | j                  j                  t        |             }
|
|| <   |S c c}	w )a  Helper method that recursively clones `op_to_clone`.

  Args:
    op_to_clone: The op we want to clone.
    variant_tensor_ops: A list of ops that we have to clone along the way.

  Returns:
    A dictionary mapping old_ops to new_ops created. Includes op_to_clone
    as a key.
  r   )nameattrsr-   )inputsr#   r!   updater$   appendvalue_indexr   get_default_graph	create_opr/   dtyper2   node_defattrr0   )op_to_cloner'   r(   input_tensorinput_tensor_oprecursive_mapinputs_listremapped_inputgonew_ops              r   r!   r!   J   s9    *!(( 'l"ooO,,#O5GHm&	'
 +!(( Ll"ooO*$!/2::1=n(001I1IJKL 
!;;[%8%89AGG9  %%%  '& #*[	 :s   *D6r,   )__doc__'tensorflow.python.data.experimental.opsr   tensorflow.python.data.opsr   "tensorflow.python.data.ops.optionsr   tensorflow.python.data.utilr   tensorflow.python.frameworkr   r   tensorflow.python.typesr	   r   r   r   r*   r0   r!    r   r   <module>rN      s8    < > 2 > 0 7 + 6 BDO3!r   