/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__/hooks.cpython-36.pyc (7257B)
3 úEgÍã@slddlZddlmZddlZddlZddlZddlmZGdd„deƒZ dd„Z dd „Z Gd d „d eƒZ dS) éN)Ú OrderedDict)ÚAnyc@steZdZUdZedZeeddœdd„Zddœdd „Z d d „Z ddœd d „Z ddœdd„Z eeeddœdd„Z dS)ÚRemovableHandlez8A handle which provides the capability to remove a hook.rN)Ú hooks_dictÚreturncCs&tj|ƒ|_tj|_tjd7_dS)Né)ÚweakrefÚrefÚhooks_dict_refrÚnext_idÚid)Úselfr©rú=/usr/local/lib64/python3.6/site-packages/torch/utils/hooks.pyÚ__init__s zRemovableHandle.__init__)rcCs&|jƒ}|dk r"|j|kr"||j=dS)N)r r )r rrrrÚremoveszRemovableHandle.removecCs|jƒ|jfS)N)r r )r rrrÚ __getstate__szRemovableHandle.__getstate__cCsN|ddkrtjtƒƒ|_ntj|dƒ|_|d|_ttj|jdƒt_dS)Nrr)rr rr r Úmaxrr )r ÚstaterrrÚ __setstate__s   zRemovableHandle.__setstate__cCs|S)Nr)r rrrÚ __enter__%szRemovableHandle.__enter__)ÚtypeÚvalueÚtbrcCs |jƒdS)N)r)r rrrrrrÚ__exit__(szRemovableHandle.__exit__)Ú__name__Ú __module__Ú __qualname__Ú__doc__Úintr r rrrrrrrrrrrr s  rcCs d|_|S)z· Decorator which marks a function as an unserializable hook. This suppresses warnings that would otherwise arise if you attempt to serialize a tensor that has a hook. T)Ú__torch_unserializable__)ÚfrrrÚunserializable_hook,sr"cCsB|jr>x6|jD],}|j|}t|dƒstjdjt|ƒƒƒqWdS)Nr z«backward hook {} on tensor will not be serialized. If this is expected, you can decorate the function with @torch.utils.hooks.unserializable_hook to suppress this warning)Z_backward_hooksÚhasattrÚwarningsÚwarnÚformatÚrepr)ZtensorÚkÚhookrrrÚwarn_if_has_hooks6s    r*c@sHeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dS)Ú BackwardHooka§ A wrapper class to implement nn.Module backward hooks. It handles: - Ignoring non-Tensor inputs and replacing them by None before calling the user hook - Generating the proper Node to capture a set of Tensor's gradients - Linking the gradients captures for the outputs with the gradients captured for the input - Calling the user hook once both output and input gradients are available cCs.||_||_d|_d|_d|_d|_d|_dS)Nréÿÿÿÿr,)Ú user_hooksÚmoduleÚ grad_outputsÚ n_outputsÚoutput_tensors_indexÚn_inputsÚinput_tensors_index)r r.r-rrrrJszBackwardHook.__init__cCs2dg|}xt||ƒD]\}}|||<qWt|ƒS)N)ÚzipÚtuple)r ÚindicesÚvaluesÚsizeÚresÚidxÚvalrrrÚ_pack_with_noneTs  zBackwardHook._pack_with_nonecCs(g}x|D]}|j||ƒq Wt|ƒS)N)Úappendr5)r r6r7r9r:rrrÚ _unpack_none[s zBackwardHook._unpack_nonecs&tjˆƒ‡‡fdd„ƒ}|j|ƒdS)Ncsvˆjdkrtdƒ‚ˆjˆj|ˆjƒ}ˆˆj|ˆjƒ}|dkr@|St|ƒt|ƒkrhtdjt|ƒt|ƒƒƒ‚ˆjˆj|ƒS)Na(Module backward hook for grad_input is called before the grad_output one. This happens because the gradient in your nn.Module flows to the Module's input without passing through the Module's output. Make sure that the output depends on the input and that the loss is computed based on the output.zOBackward hook returned an invalid number of grad_input, got {}, but expected {}) r/Ú RuntimeErrorr<r3r2r.Úlenr&r>)Z grad_inputÚ_r9)r Ú user_hookrrr)cs z)BackwardHook._set_user_hook..hook)Ú functoolsÚwrapsÚ register_hook)r Úgrad_fnrBr)r)r rBrÚ_set_user_hookbszBackwardHook._set_user_hookc Csèg}g}d}x>t|ƒD]2\}}t|tjƒr|j|ƒ|j|ƒ||jO}qW|oVtjƒs`|dfStjjj j j |Ž}t |ƒdkr†t dƒ‚dd„|Dƒ} t | ƒdkr¨t dƒ‚|| dƒt|ƒ} xt||ƒD]\} } | | | <qÈWt| ƒ|fS)NFrzCCannot set Module backward hook for a Module with no input Tensors.cSs*g|]"}|jdk r|jjƒdkr|j‘qS)NZBackwardHookFunctionBackward)rFÚname)Ú.0Útrrrú Œsz2BackwardHook._apply_on_tensors..zaError while setting up backward hooks. Please open an issue with a code sample to reproduce this.)Ú enumerateÚ isinstanceÚtorchZTensorr=Ú requires_gradZis_grad_enabledÚnnÚmodulesZ _functionsZBackwardHookFunctionÚapplyr@r?Úlistr4r5) r ÚfnÚargsZ tensors_idxZtensorsrOÚiÚargZ new_tensorsZgrad_fnsÚarg_listr:r;rrrÚ_apply_on_tensorsxs*        zBackwardHook._apply_on_tensorscs0‡fdd„}ˆj||ƒ\}}t|ƒˆ_|ˆ_|S)Ncs xˆjD]}ˆj||ƒqWdS)N)r-rG)rFr))r rrrTšs z)BackwardHook.setup_input_hook..fn)rYr@r2r3)r rUrTr9Z input_idxr)r rÚsetup_input_hook™s   zBackwardHook.setup_input_hookcsT‡fdd„}d}t|tƒs$|f}d}ˆj||ƒ\}}t|ƒˆ_|ˆ_|sP|d}|S)Ncs‡fdd„}|j|ƒdS)Ncs€ˆjˆj|ˆjƒˆ_ˆjdkr|ˆjggˆjƒ}xLˆjD]B}|ˆj|ˆjƒ}|dk r6t|t ƒolt dd„|Dƒƒ r6t dƒ‚q6WdS)Ncss|]}|dkVqdS)Nr)rIÚelrrrú °szKBackwardHook.setup_output_hook..fn..hook..zoBackward hook for Modules where no input requires gradient should always return None or None for all gradients.) r<r1r0r/r3r2r-r.rMr5Úallr?)rAZ grad_outputZ grad_inputsrBr9)r rrr)¥s   &z8BackwardHook.setup_output_hook..fn..hook)rE)rFr))r rrrT¤s z*BackwardHook.setup_output_hook..fnTFr)rMr5rYr@r0r1)r rUrTZis_tupler9Z output_idxr)r rÚsetup_output_hook£s   zBackwardHook.setup_output_hookN) rrrrrr<r>rGrYrZr^rrrrr+@s ! r+) rNÚ collectionsrrr$rCÚtypingrÚobjectrr"r*r+rrrrÚs  #