/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__/dataloader.cpython-36.pyc (24145B)
3 Eg @s`UdZddlZddlZddlZddlZddlZddlmZmZm Z m Z m Z m Z m Z ddlZddlZddljZddlmZddlmZddlmZmZmZmZmZmZddlmZe d d d Ze d Zee gdfZ!ee egefZ"ej#j$Z$e"$ej%j&Z&Gd dde'Z(GdddeZ)Gddde eZ*Gddde'Z+Gddde+Z,Gddde+Z-dS)aDefinition of the DataLoader and associated iterators that subclass _BaseDataLoaderIter To support these two classes, in `./_utils` we define many utility methods and functions to be run in multiprocessing. E.g., the data loading worker loop is in `./_utils/worker.py`. N)AnyCallableTypeVarGenericSequenceListOptional)ExceptionWrapper)string_classes)IterableDatasetSamplerSequentialSampler RandomSampler BatchSamplerDataset)_utilsT_coT) covariantTc@s eZdZdZdZeddZdS) _DatasetKindrr cCs2|tjkrtjj||||Stjj||||SdS)N)rMaprfetchZ_MapDatasetFetcherZ_IterableDatasetFetcher)kinddatasetZauto_collation collate_fn drop_lastrG/usr/local/lib64/python3.6/site-packages/torch/utils/data/dataloader.pycreate_fetcher/s z_DatasetKind.create_fetcherN)__name__ __module__ __qualname__rIterable staticmethodrrrrrr+srcs(eZdZdZfddZddZZS)_InfiniteConstantSamplerzAnalogous to ``itertools.repeat(None, None)``. Used as sampler for :class:`~torch.utils.data.IterableDataset`. Args: data_source (Dataset): dataset to sample from cstt|jddS)N)superr%__init__)self) __class__rrr'?sz!_InfiniteConstantSampler.__init__ccsx dVqWdS)Nr)r(rrr__iter__Bsz!_InfiniteConstantSampler.__iter__)r r!r"__doc__r'r* __classcell__rr)r)rr%7s r%cseZdZUdZeeee e e  e  eeeeddZddddeeeee eeeeeeeee e eeeee d d d Zdd d dZeddZejddZfddZdd ddZeddZeddZ ed ddZ!ddZ"Z#S) DataLoadera Data loader. Combines a dataset and a sampler, and provides an iterable over the given dataset. The :class:`~torch.utils.data.DataLoader` supports both map-style and iterable-style datasets with single- or multi-process loading, customizing loading order and optional automatic batching (collation) and memory pinning. See :py:mod:`torch.utils.data` documentation page for more details. Args: dataset (Dataset): dataset from which to load the data. batch_size (int, optional): how many samples per batch to load (default: ``1``). shuffle (bool, optional): set to ``True`` to have the data reshuffled at every epoch (default: ``False``). sampler (Sampler or Iterable, optional): defines the strategy to draw samples from the dataset. Can be any ``Iterable`` with ``__len__`` implemented. If specified, :attr:`shuffle` must not be specified. batch_sampler (Sampler or Iterable, optional): like :attr:`sampler`, but returns a batch of indices at a time. Mutually exclusive with :attr:`batch_size`, :attr:`shuffle`, :attr:`sampler`, and :attr:`drop_last`. num_workers (int, optional): how many subprocesses to use for data loading. ``0`` means that the data will be loaded in the main process. (default: ``0``) collate_fn (callable, optional): merges a list of samples to form a mini-batch of Tensor(s). Used when using batched loading from a map-style dataset. pin_memory (bool, optional): If ``True``, the data loader will copy Tensors into CUDA pinned memory before returning them. If your data elements are a custom type, or your :attr:`collate_fn` returns a batch that is a custom type, see the example below. drop_last (bool, optional): set to ``True`` to drop the last incomplete batch, if the dataset size is not divisible by the batch size. If ``False`` and the size of dataset is not divisible by the batch size, then the last batch will be smaller. (default: ``False``) timeout (numeric, optional): if positive, the timeout value for collecting a batch from workers. Should always be non-negative. (default: ``0``) worker_init_fn (callable, optional): If not ``None``, this will be called on each worker subprocess with the worker id (an int in ``[0, num_workers - 1]``) as input, after seeding and before data loading. (default: ``None``) generator (torch.Generator, optional): If not ``None``, this RNG will be used by RandomSampler to generate random indexes and multiprocessing to generate `base_seed` for workers. (default: ``None``) prefetch_factor (int, optional, keyword-only arg): Number of samples loaded in advance by each worker. ``2`` means there will be a total of 2 * num_workers samples prefetched across all workers. (default: ``2``) persistent_workers (bool, optional): If ``True``, the data loader will not shutdown the worker processes after a dataset has been consumed once. This allows to maintain the workers `Dataset` instances alive. (default: ``False``) .. warning:: If the ``spawn`` start method is used, :attr:`worker_init_fn` cannot be an unpicklable object, e.g., a lambda function. See :ref:`multiprocessing-best-practices` on more details related to multiprocessing in PyTorch. .. warning:: ``len(dataloader)`` heuristic is based on the length of the sampler used. When :attr:`dataset` is an :class:`~torch.utils.data.IterableDataset`, it instead returns an estimate based on ``len(dataset) / batch_size``, with proper rounding depending on :attr:`drop_last`, regardless of multi-process loading configurations. This represents the best guess PyTorch can make because PyTorch trusts user :attr:`dataset` code in correctly handling multi-process loading to avoid duplicate data. However, if sharding results in multiple workers having incomplete last batches, this estimate can still be inaccurate, because (1) an otherwise complete batch can be broken into multiple ones and (2) more than one batch worth of samples can be dropped when :attr:`drop_last` is set. Unfortunately, PyTorch can not detect such cases in general. See `Dataset Types`_ for more details on these two types of datasets and how :class:`~torch.utils.data.IterableDataset` interacts with `Multi-process data loading`_. .. warning:: See :ref:`reproducibility`, and :ref:`dataloader-workers-random-seed`, and :ref:`data-loading-randomness` notes for random seed related questions. _BaseDataLoaderIterFr Nr)prefetch_factorpersistent_workers) r batch_sizeshufflesampler batch_sampler num_workersr pin_memoryrtimeoutworker_init_fnr0r1cCs0tjjd|dkrtd| dkr,td|dkrD|dkrDtd|dksPt|rd|dkrdtd||_||_||_||_| |_ | |_ | |_ t |t rtj|_|dk rtd j|q|dk rtd j|q|dk rtd j|ntj|_|dk o|rtd |dk rB|d ks0|s0|dk s0| r8tdd}d} n|dkrZ| rZtd|dkr|jtjkrzt}n|rt|| d}nt|}|dk r|dkrt||| }||_| |_||_||_| |_|dkr|jrtjj}ntjj }||_!||_"d|_#d|_$d|_%|j&tj'ddddS)Nzpython.data_loaderrzXnum_workers option should be non-negative; use num_workers=0 to disable multiprocessing.z%timeout option should be non-negativer/zpprefetch_factor option could only be specified in multiprocessing.let num_workers > 0 to enable multiprocessing.z/persistent_workers option needs num_workers > 0FzXDataLoader with IterableDataset: expected unspecified shuffle option, but got shuffle={}zXDataLoader with IterableDataset: expected unspecified sampler option, but got sampler={}zdDataLoader with IterableDataset: expected unspecified batch_sampler option, but got batch_sampler={}z1sampler option is mutually exclusive with shuffler z[batch_sampler option is mutually exclusive with batch_size, shuffle, sampler, and drop_lastzVbatch_size=None option disables auto-batching and is mutually exclusive with drop_last) generatorTZ DataloaderenabledTrue)(torch_CZ_log_api_usage_once ValueErrorAssertionErrorrr6r0r7r8r9multiprocessing_context isinstancer rr# _dataset_kindformatrr%rrrr2rr4r5r:_auto_collationrcollatedefault_collateZdefault_convertrr1_DataLoader__initialized_IterableDataset_len_called _iteratorcheck_worker_number_rationalityZ set_vital)r(rr2r3r4r5r6rr7rr8r9rAr:r0r1rrrr's              zDataLoader.__init__)returncCs&|jdkrt|S|jt|SdS)Nr)r6_SingleProcessDataLoaderIterrK_MultiProcessingDataLoaderIter)r(rrr _get_iterator,s zDataLoader._get_iteratorcCs|jS)N)$_DataLoader__multiprocessing_context)r(rrrrA3sz"DataLoader.multiprocessing_contextcCs~|dk rt|jdkrdt|trFtj}||kr 0), but got num_workers={}) r6rBr multiprocessingget_all_start_methodsr?rD get_contextpython_multiprocessingcontext BaseContext TypeErrorrP)r(rAZvalid_start_methodsrrrrA7s      cs8|jr"|dkr"tdj||jjtt|j||dS) Nr2r5r4rrr1z6{} attribute should not be set after {} is initialized)r2r5r4rrr1)rHr?rDr)r r&r- __setattr__)r(attrval)r)rrrXPs zDataLoader.__setattr__cCsD|jr8|jdkr8|jdkr&|j|_n |jj||jS|jSdS)Nr)r1r6rJrO_reset)r(rrrr*Zs    zDataLoader.__iter__cCs |jdk S)N)r5)r(rrrrEiszDataLoader._auto_collationcCs|jr |jS|jSdS)N)rEr5r4)r(rrr_index_samplermszDataLoader._index_samplercCsd|jtjkrVt|j}|_|jdk rRddlm}|j rD||j}n|||j}|St|j SdS)Nr)ceil) rCrr#lenrrIr2mathr]rr\)r(lengthr]rrr__len__ys    zDataLoader.__len__c Csdd}|j s|jdkrdSd}d}ttdr\yttjd}d}Wntk rZYnX|dkrxtj}|dk rx|}|dkrtj|||j|dS|j|krtj|||j|dS)NcSs0|dk rdj||rdndnd}dj||}|S)Nz|Our suggested max number of worker in current system is {}{}, which is smaller than what this DataLoader is going to create.z% (`cpuset` is not taken into account)zUDataLoader is not able to compute a suggested max number of worker in current system.zThis DataLoader will create {} worker processes in total. {} Please be aware that excessive worker creation might get DataLoader running slow or even freeze, lower the worker number to avoid potential slowness/freeze if necessary.)rD)Znum_worker_suggestZnum_worker_createdcpuset_checkedZsuggested_max_worker_msgwarn_msgrrr_create_warning_msgs zGDataLoader.check_worker_number_rationality.._create_warning_msgrFsched_getaffinityT) r6hasattrosr^rf Exception cpu_countwarningswarn)r(reZmax_num_worker_suggestrcrjrrrrKs4  z*DataLoader.check_worker_number_rationality) r FNNrNFFrNNN)$r r!r"r+rrrrintr2r6boolr7rfloatr8r r4r0rJrHr _collate_fn_t_worker_init_fn_tr'rOpropertyrAsetterrXr*rEr\rarKr,rr)r)rr-Gs< OH    r-c@sleZdZeddddZddddZdd d Zd d Zd dZe dddZ e Z e dddZ ddZdS)r.N)loaderrLcCs|j|_|j|_|j|_|j|_|j|_|j|_|j|_ |j |_ |j oNt jj|_|j|_|j|_t|j|_t jft jdj|jdj|_|j|_d|_dj |j!j"|_#dS)N)Zdtype)r:rz!enumerate(DataLoader)#{}.__next__)$r_datasetrCrIrEr _drop_lastr\r6 _num_workersr0_prefetch_factorr7r=cudaZ is_available _pin_memoryr8_timeoutr _collate_fniter _sampler_iteremptyZint64Zrandom_r:item _base_seedr1_persistent_workers _num_yieldedrDr)r _profile_name)r(rtrrrr's   z_BaseDataLoaderIter.__init__)rLcCs|S)Nr)r(rrrr*sz_BaseDataLoaderIter.__iter__FcCst|j|_d|_|j|_dS)Nr)r}r\r~rrI)r(rt first_iterrrrr[s z_BaseDataLoaderIter._resetcCs t|jS)N)nextr~)r(rrr _next_indexsz_BaseDataLoaderIter._next_indexcCstdS)N)NotImplementedError)r(rrr _next_datasz_BaseDataLoaderIter._next_datac Cstjjj|j|jdkr$|j|j}|jd7_|j t j kr|j dk r|j|j krdj |j|j |j}|jdkr|d7}tj||SQRXdS)Nr zwLength of IterableDataset {} was reported to be {} (when accessing len(dataloader)), but {} samples have been fetched. rzFor multiprocessing data-loading, this could be caused by not properly configuring the IterableDataset replica at each worker. Please see https://pytorch.org/docs/stable/data.html#torch.utils.data.IterableDataset for examples.)r=ZautogradZprofilerZrecord_functionrr~r[rrrCrr#rIrDrurwrkrl)r(datardrrr__next__s      z_BaseDataLoaderIter.__next__cCs t|jS)N)r^r\)r(rrrrasz_BaseDataLoaderIter.__len__cCstd|jjdS)Nz{} cannot be pickled)rr)r )r(rrr __getstate__sz _BaseDataLoaderIter.__getstate__)F)r r!r"r-r'r*r[rrrrrrmrarrrrrr.s r.cs$eZdZfddZddZZS)rMcsNtt|j||jdkst|jdks,ttj|j|j |j |j |j |_ dS)Nr)r&rMr'r{r@rwrrrCrurEr|rv_dataset_fetcher)r(rt)r)rrr''s z%_SingleProcessDataLoaderIter.__init__cCs*|j}|jj|}|jr&tjj|}|S)N)rrrrzrr7)r(indexrrrrr/s   z'_SingleProcessDataLoaderIter._next_data)r r!r"r'rr,rr)r)rrM&s rMcsveZdZdZfddZdfdd ZejfddZd d Z d d Z d dZ ddZ dddZ ddZddZZS)rNzHIterates once over the DataLoader's dataset, as specified by the samplercstt|j||jdkst|jdks,t|jdkrsz:_MultiProcessingDataLoaderIter.__init__..)r)7r&rNr'rwr@rxrArQr9Z_worker_init_fn itertoolscyclerange_worker_queue_idx_cycleQueue_worker_result_queue_worker_pids_set _shutdownEvent_workers_done_event _index_queues_workerscancel_join_threadProcessrworkerZ _worker_looprCrurEr|rvrrdaemonstartappendrz threading_pin_memory_thread_done_eventqueue _data_queueThreadr7Z_pin_memory_loopr=ryZcurrent_device_pin_memory_threadsignal_handlingZ_set_worker_pidsidtupleZ_set_SIGCHLD_handlerr[)r(rtrAiZ index_queuerZpin_memory_thread)r)rrr'msX          " z'_MultiProcessingDataLoaderIter.__init__Fcstj||d|_d|_i|_d|_ddt|jD|_|sx(t|jD]}|j |j t j j qLW|j}x:|dkr|j\}}t|t j j rr|dkst|d8}qrWx t|j|jD] }|jqWdS)NrcSsg|]}dqS)Tr)rrrrr sz9_MultiProcessingDataLoaderIter._reset..r )r&r[ _send_idx _rcvd_idx _task_info_tasks_outstandingrrw_workers_statusrputrrZ_ResumeIteration _get_datarBr@rx_try_put_index)r(rtridxZresume_iteration_cntZ return_idxZ return_data_)r)rrr[s"    z%_MultiProcessingDataLoaderIter._resetc s2y|jj|d}d|fStk r,}zg}x>t|jD]0\}}|j|r:|j r:|j||j|q:Wt |dkrdj dd|D}t dj ||t |tjrd Sddlddl}yd } fd d t| D} Wn<tk r}z|j|jkrt d dWYdd}~XnXWYdd}~XnXdS)N)r8Trz, css|]}t|jVqdS)N)strr)rrrrrrsz?_MultiProcessingDataLoaderIter._try_get_data..z1DataLoader worker (pid(s) {}) exited unexpectedlyF csg|] }jqSr)NamedTemporaryFile)rr)tempfilerrrsz@_MultiProcessingDataLoaderIter._try_get_data..aToo many open files. Communication with the workers is no longer possible. Please increase the limit using `ulimit -n` in the shell or change the sharing strategy by calling `torch.multiprocessing.set_sharing_strategy('file_system')` at the beginning of your code)FN)rgetri enumeraterris_aliver_mark_worker_as_unavailabler^join RuntimeErrorrDrBrEmptyrerrnorOSErrorEMFILE) r(r8reZfailed_workers worker_idrZpids_strrZfds_limit_marginfsr)rr _try_get_datas2    z,_MultiProcessingDataLoaderIter._try_get_datacCs|jdkr4|j|j\}}|r"|Stdj|jnN|jrhxF|jjr\|j\}}|r<|SqP|j|j=|jd7_qW|jsh|jtt|j|jdkr|jj|jd}|j |S|j r|j dkst |j \}}|j d8_ |jtjkrt|tjjr|jrd|j|j<n |j|j|jq||jkr8|j||f7<q|j|=|j |SqWdS)Nrr/r F)rrrr^rr_shutdown_workers StopIterationpop _process_datarrr@rrCrr#rBrrZ_IterableDatasetStopIterationrrr)r(inforrrrrrrs8      z)_MultiProcessingDataLoaderIter._next_datac Cs|j|j|jksty |j}Wntk r6dSXx,t|jD]}t|j}|j |rDPqDWdS|j |j |j |f|f|j |j <|jd7_|j d7_ dS)Nr )rrxrwr@rrrrrrrrrr)r(rrZworker_queue_idxrrrrs   z-_MultiProcessingDataLoaderIter._try_put_indexcCs,|jd7_|jt|tr(|j|S)Nr )rrrBr reraise)r(rrrrrs  z,_MultiProcessingDataLoaderIter._process_datacCsL|j|s|jr|st|j|}|jdd|j|<|jj|ksHtdS)NF)rrr@rrris_set)r(rshutdownqrrrrs   z:_MultiProcessingDataLoaderIter._mark_worker_as_unavailablec Cs2tj}|dks|dkrdS|js.d|_zt|drh|jj|jjd|jj |jj |jj |j jx4t t|jD]"}|js|j|r|j|ddqWx|jD]}|j tjdqWx|jD]}|j |j qWWd|jrtjjt|d|_x"|jD]}|jr|jqWXdS)NTr)r)r8F)NN)rpython_exit_statusrrgrsetrrrrrcloserrr^rrrrMP_STATUS_CHECK_INTERVALrrrZ_remove_worker_pidsrr terminate)r(rrrrrrrrs6            z0_MultiProcessingDataLoaderIter._shutdown_workerscCs |jdS)N)r)r(rrr__del__/sz&_MultiProcessingDataLoaderIter.__del__)F)F)r r!r"r+r'r[rrrrrrrrrrr,rr)r)rrN7s7 E!1 ErN).r+rhrrrkrtypingrrrrrrrrQrTr=Ztorch.multiprocessingZ torch._utilsr Z torch._sixr rbr r rrrrrrrrmrqrprFrGrZget_worker_infoobjectrr%r-r.rMrNrrrrs8$         B