/usr/local/lib64/python3.6/site-packages/torch/nn/modules/__pycache__
NameSizeModeActions
activation.cpython-36.pyc476350644editdlrm
adaptive.cpython-36.pyc97250644editdlrm
batchnorm.cpython-36.pyc310390644editdlrm
channelshuffle.cpython-36.pyc19010644editdlrm
container.cpython-36.pyc279700644editdlrm
conv.cpython-36.pyc577890644editdlrm
distance.cpython-36.pyc36840644editdlrm
dropout.cpython-36.pyc103100644editdlrm
flatten.cpython-36.pyc58130644editdlrm
fold.cpython-36.pyc128070644editdlrm
instancenorm.cpython-36.pyc188080644editdlrm
lazy.cpython-36.pyc116900644editdlrm
linear.cpython-36.pyc101880644editdlrm
loss.cpython-36.pyc914650644editdlrm
module.cpython-36.pyc665300644editdlrm
normalization.cpython-36.pyc113600644editdlrm
padding.cpython-36.pyc222170644editdlrm
pixelshuffle.cpython-36.pyc43980644editdlrm
pooling.cpython-36.pyc532030644editdlrm
rnn.cpython-36.pyc446530644editdlrm
sparse.cpython-36.pyc209560644editdlrm
transformer.cpython-36.pyc207370644editdlrm
upsampling.cpython-36.pyc107800644editdlrm
utils.cpython-36.pyc25280644editdlrm
_functions.cpython-36.pyc54410644editdlrm
__init__.cpython-36.pyc52360644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/nn/modules/__pycache__/lazy.cpython-36.pyc (11690B)
3 Eg-@sRddlZddlmZddlZddlZddlmZGdddeZGdddZdS) N)Protocol)is_lazyc@steZdZdZddZddZddZdd Zd d Ze d d Z e ddZ e ddZ e ddZ e ddZdS) _LazyProtocolzThis is to avoid errors with mypy checks for The attributes in a mixin: https://mypy.readthedocs.io/en/latest/more_types.html#mixin-classes cCsdS)N)selfhookrrA/usr/local/lib64/python3.6/site-packages/torch/nn/modules/lazy.py"_register_load_state_dict_pre_hooksz0_LazyProtocol._register_load_state_dict_pre_hookcCsdS)Nr)rrrrr register_forward_pre_hooksz'_LazyProtocol.register_forward_pre_hookcCsdS)Nr)r state_dictprefixlocal_metadatastrict missing_keysunexpected_keys error_msgsrrr _lazy_load_hooksz_LazyProtocol._lazy_load_hookcCsdS)Nr)rrrr _get_namesz_LazyProtocol._get_namecCsdS)Nr)rmoduleinputrrr _infer_parameterssz_LazyProtocol._infer_parameterscCsdS)Nr)rrrr _parameterssz_LazyProtocol._parameterscCsdS)Nr)rrrr _buffers#sz_LazyProtocol._bufferscCsdS)Nr)rrrr _non_persistent_buffers_set'sz)_LazyProtocol._non_persistent_buffers_setcCsdS)Nr)rrrr _load_hook+sz_LazyProtocol._load_hookcCsdS)Nr)rrrr _initialize_hook/sz_LazyProtocol._initialize_hookN)__name__ __module__ __qualname____doc__r r rrrpropertyrrrrrrrrr r s    rcs~eZdZdZdZedfdd ZedddZeddd Zedd d Z edd d Z edddZ edddZ Z S)LazyModuleMixina4A mixin for modules that lazily initialize parameters, also known as "lazy modules." .. warning: Lazy modules are an experimental new feature under active development, and their API is likely to change. Modules that lazily initialize parameters, or "lazy modules", derive the shapes of their parameters from the first input(s) to their forward method. Until that first forward they contain :class:`torch.nn.UninitializedParameter` s that should not be accessed or used, and afterward they contain regular :class:`torch.nn.Parameter` s. Lazy modules are convenient since they don't require computing some module arguments, like the :attr:`in_features` argument of a typical :class:`torch.nn.Linear`. After construction, networks with lazy modules should first be converted to the desired dtype and placed on the expected device. This is because lazy modules only perform shape inference so the usual dtype and device placement behavior applies. The lazy modules should then perform "dry runs" to initialize all the components in the module. These "dry runs" send inputs of the correct size, dtype, and device through the network and to each one of its lazy modules. After this the network can be used as usual. >>> class LazyMLP(torch.nn.Module): ... def __init__(self): ... super().__init__() ... self.fc1 = torch.nn.LazyLinear(10) ... self.relu1 = torch.nn.ReLU() ... self.fc2 = torch.nn.LazyLinear(1) ... self.relu2 = torch.nn.ReLU() ... ... def forward(self, input): ... x = self.relu1(self.fc1(input)) ... y = self.relu2(self.fc2(x)) ... return y >>> # constructs a network with lazy modules >>> lazy_mlp = LazyMLP() >>> # transforms the network's device and dtype >>> # NOTE: these transforms can and should be applied after construction and before any 'dry runs' >>> lazy_mlp = mlp.cuda().double() >>> lazy_mlp LazyMLP( (fc1): LazyLinear(in_features=0, out_features=10, bias=True) (relu1): ReLU() (fc2): LazyLinear(in_features=0, out_features=1, bias=True) (relu2): ReLU() ) >>> # performs a dry run to initialize the network's lazy modules >>> lazy_mlp(torch.ones(10,10).cuda()) >>> # after initialization, LazyLinear modules become regular Linear modules >>> lazy_mlp LazyMLP( (fc1): Linear(in_features=10, out_features=10, bias=True) (relu1): ReLU() (fc2): Linear(in_features=10, out_features=1, bias=True) (relu2): ReLU() ) >>> # attaches an optimizer, since parameters can now be used as usual >>> optim = torch.optim.SGD(mlp.parameters(), lr=0.01) A final caveat when using lazy modules is that the order of initialization of a network's parameters may change, since the lazy modules are always initialized after other modules. For example, if the LazyMLP class defined above had a :class:`torch.nn.LazyLinear` module first and then a regular :class:`torch.nn.Linear` second, the second module would be initialized on construction and the first module would be initialized during the first dry run. This can cause the parameters of a network using lazy modules to be initialized differently than the parameters of a network without lazy modules as the order of parameter initializations, which often depends on a stateful random number generator, is different. Check :doc:`/notes/randomness` for more details. Lazy modules can be serialized with a state dict like other modules. For example: >>> lazy_mlp = LazyMLP() >>> # The state dict shows the uninitialized parameters >>> lazy_mlp.state_dict() OrderedDict([('fc1.weight', Uninitialized parameter), ('fc1.bias', tensor([-1.8832e+25, 4.5636e-41, -1.8832e+25, 4.5636e-41, -6.1598e-30, 4.5637e-41, -1.8788e+22, 4.5636e-41, -2.0042e-31, 4.5637e-41])), ('fc2.weight', Uninitialized parameter), ('fc2.bias', tensor([0.0019]))]) Lazy modules can load regular :class:`torch.nn.Parameter` s (i.e. you can serialize/deserialize initialized LazyModules and they will remain initialized) >>> full_mlp = LazyMLP() >>> # Dry run to initialize another module >>> full_mlp.forward(torch.ones(10, 1)) >>> # Load an initialized state into a lazy module >>> lazy_mlp.load_state_dict(full_mlp.state_dict()) >>> # The state dict now holds valid values >>> lazy_mlp.state_dict() OrderedDict([('fc1.weight', tensor([[-0.3837], [ 0.0907], [ 0.6708], [-0.5223], [-0.9028], [ 0.2851], [-0.4537], [ 0.6813], [ 0.5766], [-0.8678]])), ('fc1.bias', tensor([-1.8832e+25, 4.5636e-41, -1.8832e+25, 4.5636e-41, -6.1598e-30, 4.5637e-41, -1.8788e+22, 4.5636e-41, -2.0042e-31, 4.5637e-41])), ('fc2.weight', tensor([[ 0.1320, 0.2938, 0.0679, 0.2793, 0.1088, -0.1795, -0.2301, 0.2807, 0.2479, 0.1091]])), ('fc2.bias', tensor([0.0019]))]) Note, however, that the loaded parameters will not be replaced when doing a "dry run" if they are initialized when the state is loaded. This prevents using initialized modules in different contexts. N)rcs8tj|||j|j|_|j|j|_tj ddS)NzwLazy modules are a new feature under heavy development so changes to the API or functionality can happen at any moment.) super__init__r rrr rrwarningswarn)rargskwargs) __class__rr r$szLazyModuleMixin.__init__cCsx>|jjD]0\}}|dk r t|p&|s0|j}||||<q WxH|jjD]:\}}|dk rL||jkrLt|pp|sz|j}||||<qLWdS)N)ritemsrdetachrr)r destinationr Z keep_varsnameparambufrrr _save_to_state_dicts  z#LazyModuleMixin._save_to_state_dictc Cszxttj|jj|jjD]X\}} ||} | |kr| dk r|| } t| rt| stj| j| j WdQRXqWdS)aload_state_dict pre-hook function for lazy buffers and parameters. The purpose of this hook is to adjust the current state and/or ``state_dict`` being loaded so that a module instance serialized in both un/initialized state can be deserialized onto both un/initialized module instance. See comment in ``torch.nn.Module._register_load_state_dict_pre_hook`` for the details of the hook specification. N) itertoolschainrr*rrtorchZno_gradZ materializeshape) rr r rrrrrr-r.keyZ input_paramrrr rs " zLazyModuleMixin._lazy_load_hookcOstdj|jjdS)zInitialize parameters according to the input batch properties. This adds an interface to isolate parameter initialization from the forward pass when doing parameter shape inference. z/initialize_parameters is not implemented for {}N)NotImplementedErrorformatr)r)rr'r(rrr initialize_parameterssz%LazyModuleMixin.initialize_parameterscCs:|jj}|jj}x tj||D]}t|r"dSq"WdS)zBCheck if a module has parameters that are not initialized TF)rvaluesrr1r2r)rparamsbuffersr.rrr has_uninitialized_paramss   z(LazyModuleMixin.has_uninitialized_paramscCsb|j||jr$tdj|j|jj|jjt|dt|d|j dk r^|j |_ dS)aInfers the size and initializes the parameters according to the provided input batch. Given a module that contains parameters that were declared inferrable using :class:`torch.nn.parameter.ParameterMode.Infer`, runs a forward pass in the complete module using the provided input to initialize all the parameters as needed. The module is set into evaluation mode before running the forward pass in order to avoid saving statistics or calculating gradients z(module {} has not been fully initializedrrN) r8r< RuntimeErrorr7rrremoverdelattr cls_to_becomer))rrrrrr rs      z!LazyModuleMixin._infer_parameterscCs tddS)NzModules with uninitialized parameters can't be used with `DataParallel`. Run a dummy forward pass to correctly initialize the modules)r=)rrrr _replicate_for_data_parallelsz,LazyModuleMixin._replicate_for_data_parallel)rrrr r@rr$r0rr8r<rrA __classcell__rr)r)r r"4ss r") r1Ztyping_extensionsrr%r3 parameterrrr"rrrr s   +