/usr/local/lib64/python3.6/site-packages/torch/utils/__pycache__
NameSizeModeActions
bundled_inputs.cpython-36.pyc169270644editdlrm
checkpoint.cpython-36.pyc103970644editdlrm
collect_env.cpython-36.pyc133170644editdlrm
cpp_extension.cpython-36.pyc595840644editdlrm
dlpack.cpython-36.pyc18940644editdlrm
file_baton.cpython-36.pyc18240644editdlrm
hooks.cpython-36.pyc72570644editdlrm
mkldnn.cpython-36.pyc67220644editdlrm
mobile_optimizer.cpython-36.pyc47480644editdlrm
model_zoo.cpython-36.pyc2310644editdlrm
show_pickle.cpython-36.pyc48280644editdlrm
throughput_benchmark.cpython-36.pyc67300644editdlrm
_cpp_extension_versioner.cpython-36.pyc17680644editdlrm
_crash_handler.cpython-36.pyc10050644editdlrm
_python_dispatch.cpython-36.pyc7800644editdlrm
_pytree.cpython-36.pyc67470644editdlrm
__init__.cpython-36.pyc7300644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/utils/__pycache__/checkpoint.cpython-36.pyc (10397B)
3 Eg/@sddlZddlZddlmZmZmZmZeedfeejdfdddZeeddddZ eee eejfd d d Z dd d d Z Gdddej jZddZddZdS)N)AnyIterableListTuple.)inputsreturncCsjt|trVg}x>|D]6}t|tjs0|j|q|j}|j|_|j|qWt|Stdt|j dS)Nz@Only tuple of tensors is supported. Got Unsupported input type: ) isinstancetupletorchTensorappenddetach requires_grad RuntimeErrortype__name__)routinpxrB/usr/local/lib64/python3.6/site-packages/torch/utils/checkpoint.pydetach_variables    rcCs tdd|DstjddS)Ncss |]}t|tjr|jVqdS)N)rr r r).0rrrr sz*check_backward_validity..zBNone of the inputs have requires_grad=True. Gradients will be None)anywarningswarn)rrrrcheck_backward_validitysr)rc GsXttdd|D}g}x4|D],}tjj||jtjjWdQRXq W||fS)Ncss(|] }t|tjr|jr|jVqdS)N)rr r Zis_cudaZ get_device)rargrrrr&sz$get_device_states..)listsetr cudadevicer get_rng_state)argsfwd_gpu_devicesfwd_gpu_statesr"rrrget_device_states#s  r'c Cs@x:t||D],\}}tjj|tjj|WdQRXq WdS)N)zipr r!r" set_rng_state)devicesZstatesr"staterrrset_device_states1sr,c@s$eZdZeddZeddZdS)CheckpointFunctionc Gst|||_||_tj|_|rPtj|_d|_tj j rPd|_t |\|_ |_ g|_g|_g}xNt|D]B\}}tj|r|j||jj||jjdqj|jj|qjW|j|tj||}WdQRX|S)NFT)r run_functionpreserve_rng_stater Zis_autocast_enabledhad_autocast_in_fwdr# fwd_cpu_statehad_cuda_in_fwdr! _initializedr'r%r&rtensor_indices enumerate is_tensorr Zsave_for_backwardZno_grad)ctxr.r/r$Z tensor_inputsiroutputsrrrforward9s.       zCheckpointFunction.forwardc Gstjjstdt|j}|j}|j}x t|D]\}}||||<q2Wg}|j r`|j r`|j }tj j ||j dr|j rtj|j|j rt|j |jtt|}tj,tjjj|j|j|} WdQRXWdQRXWdQRXt| tjr| f} g} g} xNtt| D]>}tj| |r| |jr| j | || j ||qWt| dkrjtdtjj!| | tdd|D} d| S)NzCheckpointing is not compatible with .grad() or when an `inputs` parameter is passed to .backward(). Please use .backward() and do not pass its `inputs` argument.)r*enabledrzInone of output has requires_grad=True, this checkpoint() is not necessarycss$|]}t|tjr|jndVqdS)N)rr r Zgrad)rrrrrrsz.CheckpointFunction.backward..)NN)"r autogradZ_is_checkpoint_validrrrr4Z saved_tensorsr5r/r2r%randomZfork_rngr)r1r,r&rr Z enable_gradr!ampZautocastr0r.rr rangelenr6rr backward) r7r$rr4Ztensorsr8idxZ rng_devicesZdetached_inputsr9Zoutputs_with_gradZargs_with_gradZgradsrrrrA]sD     (  zCheckpointFunction.backwardN)r __module__ __qualname__ staticmethodr:rArrrrr-7s $r-cOs>|jdd}|r,tddjdd|Dtj||f|S)a* Checkpoint a model or part of the model Checkpointing works by trading compute for memory. Rather than storing all intermediate activations of the entire computation graph for computing backward, the checkpointed part does **not** save intermediate activations, and instead recomputes them in backward pass. It can be applied on any part of a model. Specifically, in the forward pass, :attr:`function` will run in :func:`torch.no_grad` manner, i.e., not storing the intermediate activations. Instead, the forward pass saves the inputs tuple and the :attr:`function` parameter. In the backwards pass, the saved inputs and :attr:`function` is retrieved, and the forward pass is computed on :attr:`function` again, now tracking the intermediate activations, and then the gradients are calculated using these activation values. The output of :attr:`function` can contain non-Tensor values and gradient recording is only performed for the Tensor values. Note that if the output consists of nested structures (ex: custom objects, lists, dicts etc.) consisting of Tensors, these Tensors nested in custom structures will not be considered as part of autograd. .. warning:: Checkpointing currently only supports :func:`torch.autograd.backward` and only if its `inputs` argument is not passed. :func:`torch.autograd.grad` is not supported. .. warning:: If :attr:`function` invocation during backward does anything different than the one during forward, e.g., due to some global variable, the checkpointed version won't be equivalent, and unfortunately it can't be detected. .. warning:: If checkpointed segment contains tensors detached from the computational graph by `detach()` or `torch.no_grad()`, the backward pass will raise an error. This is because `checkpoint` makes all the outputs require gradients which causes issues when a tensor is defined to have no gradient in the model. To circumvent this, detach the tensors outside of the `checkpoint` function. .. warning:: At least one of the inputs needs to have :code:`requires_grad=True` if grads are needed for model inputs, otherwise the checkpointed part of the model won't have gradients. At least one of the outputs needs to have :code:`requires_grad=True` as well. Args: function: describes what to run in the forward pass of the model or part of the model. It should also know how to handle the inputs passed as the tuple. For example, in LSTM, if user passes ``(activation, hidden)``, :attr:`function` should correctly use the first input as ``activation`` and the second input as ``hidden`` preserve_rng_state(bool, optional, default=True): Omit stashing and restoring the RNG state during each checkpoint. args: tuple containing inputs to the :attr:`function` Returns: Output of running :attr:`function` on :attr:`*args` r/TzUnexpected keyword arguments: ,css|] }|VqdS)Nr)rrrrrrszcheckpoint..)pop ValueErrorjoinr-apply)functionr$kwargspreserverrr checkpoints> rNc Ks|jdd}|r,tddjdd|Ddd}t|tjjrNt|j}t ||}d }x>t d ||d |D]&}||d }t ||||||d }qtW||d t |d ||S) aA helper function for checkpointing sequential models. Sequential models execute a list of modules/functions in order (sequentially). Therefore, we can divide such a model in various segments and checkpoint each segment. All segments except the last will run in :func:`torch.no_grad` manner, i.e., not storing the intermediate activations. The inputs of each checkpointed segment will be saved for re-running the segment in the backward pass. See :func:`~torch.utils.checkpoint.checkpoint` on how checkpointing works. .. warning:: Checkpointing currently only supports :func:`torch.autograd.backward` and only if its `inputs` argument is not passed. :func:`torch.autograd.grad` is not supported. .. warning: At least one of the inputs needs to have :code:`requires_grad=True` if grads are needed for model inputs, otherwise the checkpointed part of the model won't have gradients. .. warning: Since PyTorch 1.4, it allows only one Tensor as the input and intermediate outputs, just like :class:`torch.nn.Sequential`. Args: functions: A :class:`torch.nn.Sequential` or the list of modules or functions (comprising the model) to run sequentially. segments: Number of chunks to create in the model input: A Tensor that is input to :attr:`functions` preserve_rng_state(bool, optional, default=True): Omit stashing and restoring the RNG state during each checkpoint. Returns: Output of running :attr:`functions` sequentially on :attr:`*inputs` Example: >>> model = nn.Sequential(...) >>> input_var = checkpoint_sequential(model, chunks, input_var) r/TzUnexpected keyword arguments: rFcss|] }|VqdS)Nr)rrrrrrsz(checkpoint_sequential..csfdd}|S)Ncs(x"tdD]}||}qW|S)N)r?)inputj)end functionsstartrrr:sz.run_function..forwardr)rTrRrSr:r)rRrSrTrr.sz+checkpoint_sequential..run_functionrOr)r/) rGrHrIrr nnZ Sequentialrchildrenr@r?rN) rSsegmentsrPrLrMr.Z segment_sizerRrTrrrcheckpoint_sequentials*     rY)r rtypingrrrrr rrintr'r,r<ZFunctionr-rNrYrrrrs" ZE