/usr/local/lib64/python3.6/site-packages/torch/utils/data/__pycache__
NameSizeModeActions
backward_compatibility.cpython-36.pyc4740644editdlrm
dataloader.cpython-36.pyc241450644editdlrm
dataloader_experimental.cpython-36.pyc42840644editdlrm
dataset.cpython-36.pyc170510644editdlrm
distributed.cpython-36.pyc48510644editdlrm
graph.cpython-36.pyc12660644editdlrm
sampler.cpython-36.pyc90120644editdlrm
sharding.cpython-36.pyc10110644editdlrm
_decorator.cpython-36.pyc60310644editdlrm
_typing.cpython-36.pyc98520644editdlrm
__init__.cpython-36.pyc14770644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/utils/data/__pycache__/dataset.cpython-36.pyc (17051B)
3 Eg:@svddlZddlZddlZddlmZmZmZmZmZm Z m Z m Z m Z m Z ddlmZmZddlmZddlmZddlmZmZe dd d Ze d Zd d ddgZGdddeeeZGdddeeZGdddeeedZGdddeZGdddee edfZ GdddeeZ!GdddeZ"Gd d!d!eeZ#efeee e$e ee e#ed"d#d$Z%dS)%N) CallableDictGenericIterableIteratorListOptionalSequenceTupleTypeVar)default_generatorrandperm) _accumulate) _DataPipeMeta) GeneratorTensorT_coT) covariantTbatchgroupbyZ_dataframes_as_tuplestrace_as_dataframecsDeZdZfddZd ddZeedfdd Zd d ZZ S) DataChunkcstj|||_dS)N)super__init__items)selfr) __class__D/usr/local/lib64/python3.6/site-packages/torch/utils/data/dataset.pyr"s zDataChunk.__init__cCs(|ddjddt|Dd}|S)N[z, css|]}t|VqdS)N)str).0irrr 'sz#DataChunk.as_str..])joiniter)rindentresrrr as_str&s$zDataChunk.as_str)returnc#sxtjD] }|Vq WdS)N)r__iter__)rr%)rrr r.*szDataChunk.__iter__ccsx|jD] }|VqWdS)N)r)rr%rrr raw_iterator.s zDataChunk.raw_iterator)r!) __name__ __module__ __qualname__rr,rrr.r/ __classcell__rr)rr r!s  rc@sbeZdZUdZiZeeefedddZ ddddd Z d d Z e d d Z e dddZdS)DatasetaAn abstract class representing a :class:`Dataset`. All datasets that represent a map from keys to data samples should subclass it. All subclasses should overwrite :meth:`__getitem__`, supporting fetching a data sample for a given key. Subclasses could also optionally overwrite :meth:`__len__`, which is expected to return the size of the dataset by many :class:`~torch.utils.data.Sampler` implementations and the default options of :class:`~torch.utils.data.DataLoader`. .. note:: :class:`~torch.utils.data.DataLoader` by default constructs a index sampler that yields integral indices. To make it work with a map-style dataset with non-integral indices/keys, a custom sampler must be provided. )r-cCstdS)N)NotImplementedError)rindexrrr __getitem__DszDataset.__getitem__z Dataset[T_co]zConcatDataset[T_co])otherr-cCs t||gS)N) ConcatDataset)rr8rrr __add__GszDataset.__add__cCs(|tjkr tjtj||}|StdS)N)r4 functions functoolspartialAttributeError)rattribute_namefunctionrrr __getattr__Ns zDataset.__getattr__cCs||j|<dS)N)r;)cls function_namer@rrr register_functionUszDataset.register_functionFcs@|jkrtdjfdd}tj|||}||j<dS)Nz>Unable to add DataPipe function name {} as it is already takencs<||f||}t|tr8|s(t|tr8tkr8|j}|S)N) isinstancer4DFIterDataPipeUNTRACABLE_DATAFRAME_PIPESr)rBenable_df_api_tracingZ source_dpargskwargsZ result_pipe)rCrr class_function^s  z=Dataset.register_datapipe_as_function..class_function)r; Exceptionformatr<r=)rBrCZcls_to_registerrHrKr@r)rCr register_datapipe_as_functionYs   z%Dataset.register_datapipe_as_functionN)F)r0r1r2__doc__r;rr#rrr7r:rA classmethodrDrNrrrr r43s  r4csveZdZUdZiZeeefdZe ee e dddZ e e dddZd d Zfd d Zed dZZS)IterableDatasetaAn iterable Dataset. All datasets that represent an iterable of data samples should subclass it. Such form of datasets is particularly useful when data come from a stream. All subclasses should overwrite :meth:`__iter__`, which would return an iterator of samples in this dataset. When a subclass is used with :class:`~torch.utils.data.DataLoader`, each item in the dataset will be yielded from the :class:`~torch.utils.data.DataLoader` iterator. When :attr:`num_workers > 0`, each worker process will have a different copy of the dataset object, so it is often desired to configure each copy independently to avoid having duplicate data returned from the workers. :func:`~torch.utils.data.get_worker_info`, when called in a worker process, returns information about the worker. It can be used in either the dataset's :meth:`__iter__` method or the :class:`~torch.utils.data.DataLoader` 's :attr:`worker_init_fn` option to modify each copy's behavior. Example 1: splitting workload across all workers in :meth:`__iter__`:: >>> class MyIterableDataset(torch.utils.data.IterableDataset): ... def __init__(self, start, end): ... super(MyIterableDataset).__init__() ... assert end > start, "this example code only works with end >= start" ... self.start = start ... self.end = end ... ... def __iter__(self): ... worker_info = torch.utils.data.get_worker_info() ... if worker_info is None: # single-process data loading, return the full iterator ... iter_start = self.start ... iter_end = self.end ... else: # in a worker process ... # split workload ... per_worker = int(math.ceil((self.end - self.start) / float(worker_info.num_workers))) ... worker_id = worker_info.id ... iter_start = self.start + worker_id * per_worker ... iter_end = min(iter_start + per_worker, self.end) ... return iter(range(iter_start, iter_end)) ... >>> # should give same set of data as range(3, 7), i.e., [3, 4, 5, 6]. >>> ds = MyIterableDataset(start=3, end=7) >>> # Single-process loading >>> print(list(torch.utils.data.DataLoader(ds, num_workers=0))) [3, 4, 5, 6] >>> # Mult-process loading with two worker processes >>> # Worker 0 fetched [3, 4]. Worker 1 fetched [5, 6]. >>> print(list(torch.utils.data.DataLoader(ds, num_workers=2))) [3, 5, 4, 6] >>> # With even more workers >>> print(list(torch.utils.data.DataLoader(ds, num_workers=20))) [3, 4, 5, 6] Example 2: splitting workload across all workers using :attr:`worker_init_fn`:: >>> class MyIterableDataset(torch.utils.data.IterableDataset): ... def __init__(self, start, end): ... super(MyIterableDataset).__init__() ... assert end > start, "this example code only works with end >= start" ... self.start = start ... self.end = end ... ... def __iter__(self): ... return iter(range(self.start, self.end)) ... >>> # should give same set of data as range(3, 7), i.e., [3, 4, 5, 6]. >>> ds = MyIterableDataset(start=3, end=7) >>> # Single-process loading >>> print(list(torch.utils.data.DataLoader(ds, num_workers=0))) [3, 4, 5, 6] >>> >>> # Directly doing multi-process loading yields duplicate data >>> print(list(torch.utils.data.DataLoader(ds, num_workers=2))) [3, 3, 4, 4, 5, 5, 6, 6] >>> # Define a `worker_init_fn` that configures each dataset copy differently >>> def worker_init_fn(worker_id): ... worker_info = torch.utils.data.get_worker_info() ... dataset = worker_info.dataset # the dataset copy in this worker process ... overall_start = dataset.start ... overall_end = dataset.end ... # configure the dataset to only process the split workload ... per_worker = int(math.ceil((overall_end - overall_start) / float(worker_info.num_workers))) ... worker_id = worker_info.id ... dataset.start = overall_start + worker_id * per_worker ... dataset.end = min(dataset.start + per_worker, overall_end) ... >>> # Mult-process loading with the custom `worker_init_fn` >>> # Worker 0 fetched [3, 4]. Worker 1 fetched [5, 6]. >>> print(list(torch.utils.data.DataLoader(ds, num_workers=2, worker_init_fn=worker_init_fn))) [3, 5, 4, 6] >>> # With even more workers >>> print(list(torch.utils.data.DataLoader(ds, num_workers=20, worker_init_fn=worker_init_fn))) [3, 4, 5, 6] N)r-cCstdS)N)r5)rrrr r.szIterableDataset.__iter__)r8cCs t||gS)N) ChainDataset)rr8rrr r:szIterableDataset.__add__cCs(|tjkr tjtj||}|StdS)N)rQr;r<r=r>)rr?r@rrr rAs zIterableDataset.__getattr__c s8tjdk r*y tj|Stk r(YnXtj||S)N)rQreduce_ex_hookr5r __reduce_ex__)rrIrJ)rrr rTs   zIterableDataset.__reduce_ex__cCs$tjdk r|dk rtd|t_dS)Nz+Attempt to override existing reduce_ex_hook)rQrSrL)rBZhook_fnrrr set_reduce_ex_hooksz"IterableDataset.set_reduce_ex_hook)r0r1r2rOr;rr#rrSrrrr.r4r:rArTrPrUr3rr)rr rQks e  rQ) metaclassc@seZdZddZdS)rFcCsdS)NTr)rrrr _is_dfpipeszDFIterDataPipe._is_dfpipeN)r0r1r2rWrrrr rFsrFc@s>eZdZUdZeedfeddddZddZd d Z dS) TensorDatasetzDataset wrapping tensors. Each sample will be retrieved by indexing tensors along the first dimension. Args: *tensors (Tensor): tensors that have the same size of the first dimension. .N)tensorsr-cs(tfddDstd|_dS)Nc3s&|]}djd|jdkVqdS)rN)size)r$tensor)rYrr r&sz)TensorDataset.__init__..zSize mismatch between tensors)allAssertionErrorrY)rrYr)rYr rszTensorDataset.__init__cstfdd|jDS)Nc3s|]}|VqdS)Nr)r$r[)r6rr r&sz,TensorDataset.__getitem__..)tuplerY)rr6r)r6r r7szTensorDataset.__getitem__cCs|jdjdS)Nr)rYrZ)rrrr __len__szTensorDataset.__len__) r0r1r2rOr rrYrr7r_rrrr rXs  rX.csjeZdZUdZeeeee e ddZ e eddfdd Z dd Zd d Zed d ZZS)r9zDataset as a concatenation of multiple datasets. This class is useful to assemble different existing datasets. Args: datasets (sequence): List of datasets to be concatenated cCs:gd}}x*|D]"}t|}|j||||7}qW|S)Nr)lenappend)sequencerselrrr cumsums    zConcatDataset.cumsumN)datasetsr-csdtt|jt||_t|jdks.tdx"|jD]}t|t s6tdq6W|j |j|_ dS)Nrz(datasets should not be an empty iterablez.ConcatDataset does not support IterableDataset) rr9rlistrhr`r]rErQrgcumulative_sizes)rrhd)rrr rs   zConcatDataset.__init__cCs |jdS)N)rj)rrrr r_'szConcatDataset.__len__cCsf|dkr*| t|krtdt||}tj|j|}|dkrF|}n||j|d}|j||S)Nrz8absolute value of index should not exceed dataset lengthrl)r` ValueErrorbisect bisect_rightrjrh)ridxZ dataset_idxZ sample_idxrrr r7*s zConcatDataset.__getitem__cCstjdtdd|jS)Nz:cummulative_sizes attribute is renamed to cumulative_sizes) stacklevel)warningswarnDeprecationWarningrj)rrrr cummulative_sizes6s zConcatDataset.cummulative_sizes)r0r1r2rOrr4rrhintrj staticmethodrgrrr_r7propertyrwr3rr)rr r9 s    r9cs<eZdZdZeeddfdd ZddZdd ZZ S) rRa_Dataset for chaining multiple :class:`IterableDataset` s. This class is useful to assemble different existing dataset streams. The chaining operation is done on-the-fly, so concatenating large-scale datasets with this class will be efficient. Args: datasets (iterable of IterableDataset): datasets to be chained together N)rhr-cstt|j||_dS)N)rrRrrh)rrh)rrr rGszChainDataset.__init__ccs:x4|jD]*}t|tstdx|D] }|Vq$WqWdS)Nz*ChainDataset only supports IterableDataset)rhrErQr])rrkxrrr r.Ks  zChainDataset.__iter__cCs6d}x,|jD]"}t|ts"td|t|7}q W|S)Nrz*ChainDataset only supports IterableDataset)rhrErQr]r`)rtotalrkrrr r_Qs  zChainDataset.__len__) r0r1r2rOrr4rr.r_r3rr)rr rR=s rRc@sLeZdZUdZeeee eeeeddddZ ddZ dd Z dS) Subsetz Subset of a dataset at specified indices. Args: dataset (Dataset): The whole Dataset indices (sequence): Indices in the whole set selected for subset N)datasetindicesr-cCs||_||_dS)N)r~r)rr~rrrr rdszSubset.__init__cs2t|tr"jfdd|DSjj|S)Ncsg|]}j|qSr)r)r$r%)rrr jsz&Subset.__getitem__..)rErir~r)rrqr)rr r7hs zSubset.__getitem__cCs t|jS)N)r`r)rrrr r_mszSubset.__len__) r0r1r2rOr4rr~r rxrrr7r_rrrr r}Ys r})r~lengths generatorr-csJt|tkrtdtt||djfddtt||DS)a Randomly split a dataset into non-overlapping new datasets of given lengths. Optionally fix the generator for reproducible results, e.g.: >>> random_split(range(10), [3, 7], generator=torch.Generator().manual_seed(42)) Args: dataset (Dataset): Dataset to be split lengths (sequence): lengths of splits to be produced generator (Generator): Generator used for the random permutation. zDSum of input lengths does not equal the length of the input dataset!)rcs&g|]\}}t|||qSr)r})r$offsetlength)r~rrr rsz random_split..)sumr`rnr tolistzipr)r~rrr)r~rr random_splitqsr)&ror<rttypingrrrrrrrr r r Ztorchr r Z torch._utilsrZtorch.utils.data._typingrr!rrrrrGrirr4rQrFrXr9rRr}rxrrrrr s.0   82