L i-xddlmZddlmZddlZddlmZgdZGddejjZ Gdd eje Z Gd d Z d edefdZGdde e ZGddejjZGddeje ZGdde ejZy)) OrderedDict)AnyN)_disabled_torch_function_impl) ParameterUninitializedParameteris_lazyBufferUninitializedBufferUninitializedTensorMixinceZdZfdZxZS)_ParameterMetac|tur(t|tjrt |ddryt ||S)N _is_paramFT)r isinstancetorchTensorgetattrsuper__instancecheck__selfinstance __class__s X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/nn/parameter.pyrz _ParameterMeta.__instancecheck__s< 9 (ELL1g+u7w(22__name__ __module__ __qualname__r __classcell__rs@rr r  33rr c:eZdZdZddZdZfdZdZeZ xZ S)raA kind of Tensor that is to be considered a module parameter. Parameters are :class:`~torch.Tensor` subclasses, that have a very special property when used with :class:`Module` s - when they're assigned as Module attributes they are automatically added to the list of its parameters, and will appear e.g. in :meth:`~Module.parameters` iterator. Assigning a Tensor doesn't have such effect. This is because one might want to cache some temporary state, like last hidden state of the RNN, in the model. If there was no such class as :class:`Parameter`, these temporaries would get registered too. Args: data (Tensor): parameter tensor. requires_grad (bool, optional): if the parameter requires gradient. Note that the torch.no_grad() context does NOT affect the default behavior of Parameter creation--the Parameter will still have `requires_grad=True` in :class:`~no_grad` mode. See :ref:`locally-disable-grad-doc` for more details. Default: `True` c|tjd}t|tjust|tur!tjj |||S|j j|}t|t|ur8tdt|jdt|jdd|_ |S)Nrz.Creating a Parameter from an instance of type zN requires that detach() returns an instance of the same type, but return type z was found instead. To use the type as a Parameter, please correct the detach() semantics defined by its __torch_dispatch__() implementation.T) remptytyperr_make_subclassdetachrequires_grad_ RuntimeErrorrr)clsdata requires_gradts r__new__zParameter.__new__3s <;;q>D : %dy)@<<..sD-H H KKM ( ( 7 7$t* $@dATAT@UVQ(()*;;  rct||vr|t|St||jjtj |j }||t|<|S)N) memory_format)idr&r,clonerpreserve_formatr-rmemoresults r __deepcopy__zParameter.__deepcopy__Js` d8t 4> !T$Z e.C.CDdFXFXF$DDNMrc&dt|zS)NzParameter containing: )r__repr__)rrs rr:zParameter.__repr__Ts(57+;+===rc&tjj|}t}|s3tjj|j |j |ffStjj|j |j ||ffSN)r_utils_get_obj_stater_rebuild_parameterr,r-_rebuild_parameter_with_state)rprotostatehookss r __reduce_ex__zParameter.__reduce_ex__Ws| ++D1  //D..6  LL 6 6 YY**E5 9  r)NT) rrr__doc__r/r8r:rDr__torch_function__r r!s@rrrs$(.> 7rr) metaclassceZdZejj ejj ejjejjejjejjejjejjejjejjejjejj ejj"ejj$ejj&ejj(ej*gZddZedZdZdZdZedfd ZxZS) r c||jj}||jj}tj||||_|j |_y)aCreate a Parameter or Tensor with the same properties of the uninitialized one. Given a shape, it materializes a parameter in the same device and with the same `dtype` as the current one or the specified ones in the arguments. Args: shape : (tuple): the shape for the materialized tensor. device (:class:`torch.device`): the desired device of the parameters and buffers in this module. Optional. dtype (:class:`torch.dtype`): the desired floating point type of the floating point parameters and buffers in this module. Optional. Ndevicedtype)r,rKrLrr% cls_to_becomer)rshaperKrLs r materializez$UninitializedTensorMixin.materializesK >YY%%F =IIOOEKKfEB ++rctd)NaCan't access the shape of an uninitialized parameter or buffer. This error usually happens in `load_state_dict` when trying to load an uninitialized parameter into an initialized one. Call `forward` to initialize the parameters before accessing their attributes.r*rs rrNzUninitializedTensorMixin.shapes ]  rctd)NzCan't share memory on an uninitialized parameter or buffer. Call `forward` to initialize the parameters before calling `module.share_memory()`.rQrRs r share_memory_z&UninitializedTensorMixin.share_memory_s '  rc6d|jjdS)N<>)rrrRs rr:z!UninitializedTensorMixin.__repr__s4>>**+1--rc4|j|jffSr<)rr-)rrAs rrDz&UninitializedTensorMixin.__reduce_ex__s!3!3 566rc||jvs|jjdk(r|i}t|||||St d|d|jd)Nzmethod-wrapperz/Attempted to use an uninitialized parameter in zf. This error happens when you are using a `LazyModule` or explicitly manipulating `torch.nn.parameter.z` objects. When using LazyModules Call `forward` with a dummy batch to initialize the parameters before calling torch functions)_allowed_methodsrrrrF ValueError)r+functypesargskwargsrs rrFz+UninitializedTensorMixin.__torch_function__su 3'' '4>>+B+BFV+V~7-dE4H H=dVD;;><<.IJ J  r)NN)N) rrrrr__hash__sizecopy_ is_complexis_floating_pointhalffloatdoublecharshortintlongcudacputo get_device!_has_compatible_shallow_copy_typerZrOpropertyrNrTr:rD classmethodrFr r!s@rr r js     &&            //#(,*   .7    rr paramreturnc"t|tS)z Returns whether ``param`` is an ``UninitializedParameter`` or ``UninitializedBuffer``. Args: param (Any): the input to check. )rr )rts rrrs e5 66rc$eZdZdZeZdddZdZy)raA parameter that is not initialized. Uninitialized Parameters are a special case of :class:`torch.nn.Parameter` where the shape of the data is still unknown. Unlike a :class:`torch.nn.Parameter`, uninitialized parameters hold no data and attempting to access some properties, like their shape, will throw a runtime error. The only operations that can be performed on a uninitialized parameter are changing its datatype, moving it to a different device and converting it to a regular :class:`torch.nn.Parameter`. The default device or dtype to use when the parameter is materialized can be set during construction using e.g. ``device='cuda'``. Ncx||d}tjdi|}tjj|||S)NrJr)rr%rr')r+r-rKrLfactory_kwargsr,s rr/zUninitializedParameter.__new__s6$*U;{{//||**3mDDrct||vr|t|St||j|jj|jj }||t|<|Sr<)r2r&r-r,rKrLr5s rr8z#UninitializedParameter.__deepcopy__sZ d8t 4> !T$Z 2 2DII4D4DdiiooVF#DDNMr)TNNruN)rrrrErrMr/r8r`rrrrs ME rrceZdZfdZxZS) _BufferMetac|tur(t|tjrt |ddryt ||S)N _is_bufferFT)r rrrrrrrs rrz_BufferMeta.__instancecheck__s; 6>(ELL1g,7w(22rrr!s@rr~r~r"rr~c"eZdZdZddddZeZy)r a,A kind of Tensor that should not be considered a model parameter. For example, BatchNorm's ``running_mean`` is not a parameter, but is part of the module's state. Buffers are :class:`~torch.Tensor` subclasses, that have a very special property when used with :class:`Module` s -- when they're assigned as Module attributes they are automatically added to the list of its buffers, and will appear e.g. in :meth:`~torch.nn.Module.buffers` iterator. Assigning a Tensor doesn't have such effect. One can still assign a Tensor as explicitly by using the :meth:`~torch.nn.Module.register_buffer` function. Args: data (Tensor): buffer tensor. persistent (bool, optional): whether the buffer is part of the module's :attr:`state_dict`. Default: ``True`` NT) persistentc|tjd}|jj|j}||_d|_|S)NrT)rr%r(r)r-rr)r+r,rr.s rr/zBuffer.__new__sC <;;q>D KKM ( ();); <!  rr<)rrrrEr/rrFr`rrr r s d7rr c6eZdZdZej Z d ddZy)r aA buffer that is not initialized. Uninitialized Buffer is a a special case of :class:`torch.Tensor` where the shape of the data is still unknown. Unlike a :class:`torch.Tensor`, uninitialized parameters hold no data and attempting to access some properties, like their shape, will throw a runtime error. The only operations that can be performed on a uninitialized parameter are changing its datatype, moving it to a different device and converting it to a regular :class:`torch.Tensor`. The default device or dtype to use when the buffer is materialized can be set during construction using e.g. ``device='cuda'``. Nc||d}tjdi|}tjj|||}||_d|_|S)NrJTry)rr%rr'rr)r+r-rKrLrrzr,rets rr/zUninitializedBuffer.__new__!sJ%+U;{{//ll))#t]C# r)FNNTr|)rrrrErrrMr/r`rrr r s& LLMGK rr ) collectionsrtypingrrtorch._Cr__all___C _TensorMetar rrr boolrrr~r r r`rrrs# 2 3UXX))3I7 I7XO O d737475yB3%((&&37U\\[7:2ELLr