L i|ddlmZddlZddlmZmZddlmZm Z ddl m Z m Z m Z mZmZmZddlmZmZddlZddlmZddlmZd d lmZer dd lmZmZmZgd Zed eZ edZ!dZ"ede#GddeZ$GddeZ%GddeZ&GddeZ'GddeZ(GddeZ)y)) annotationsN)abc OrderedDict)chainislice)AnyOptionaloverload TYPE_CHECKINGTypeVarUnion) deprecatedSelf)_copy_to_script_wrapper) Parameter)Module)IterableIteratorMapping) Container Sequential ModuleList ModuleDict ParameterList ParameterDictT)bound_Vc|jd}t|dk(r|S|jd}|Dcgc] }|dz|z }}dj|}|dz|z}|Scc}w)N rr )splitlenpopjoin)s_ numSpacessfirstlines `/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/nn/modules/container.py _addindentr-#sm A 1v{ EE!HE./0d)c/T !0A0 ! A  qA H 1sA#zq`nn.Container` is deprecated. All of it's functionality is now implemented in `nn.Module`. Subclass that instead.)categoryc eZdZdfd ZxZS)rc vt||jD]\}}|j||yN)super__init__items add_module)selfkwargskeyvalue __class__s r,r3zContainer.__init__5s5  ,,. (JC OOC ' ()r7rreturnNone)__name__ __module__ __qualname__r3 __classcell__r:s@r,rr/s ((r;rceZdZUdZded<eddZeddZfdZddZeddZ dd Z dd Z edd Z dd Z d d Zd!dZd"dZd"dZd#dZed$fd Zed%dZdZd&dZd'dZd(dZxZS))raA sequential container. Modules will be added to it in the order they are passed in the constructor. Alternatively, an ``OrderedDict`` of modules can be passed in. The ``forward()`` method of ``Sequential`` accepts any input and forwards it to the first module it contains. It then "chains" outputs to inputs sequentially for each subsequent module, finally returning the output of the last module. The value a ``Sequential`` provides over manually calling a sequence of modules is that it allows treating the whole container as a single module, such that performing a transformation on the ``Sequential`` applies to each of the modules it stores (which are each a registered submodule of the ``Sequential``). What's the difference between a ``Sequential`` and a :class:`torch.nn.ModuleList`? A ``ModuleList`` is exactly what it sounds like--a list for storing ``Module`` s! On the other hand, the layers in a ``Sequential`` are connected in a cascading way. Example:: # Using Sequential to create a small model. When `model` is run, # input will first be passed to `Conv2d(1,20,5)`. The output of # `Conv2d(1,20,5)` will be used as the input to the first # `ReLU`; the output of the first `ReLU` will become the input # for `Conv2d(20,64,5)`. Finally, the output of # `Conv2d(20,64,5)` will be used as input to the second `ReLU` model = nn.Sequential( nn.Conv2d(1, 20, 5), nn.ReLU(), nn.Conv2d(20, 64, 5), nn.ReLU() ) # Using Sequential with OrderedDict. This is functionally the # same as the above code model = nn.Sequential( OrderedDict( [ ("conv1", nn.Conv2d(1, 20, 5)), ("relu1", nn.ReLU()), ("conv2", nn.Conv2d(20, 64, 5)), ("relu2", nn.ReLU()), ] ) ) dict[str, Module]_modulescyr1)r6argss r,r3zSequential.__init__l/2r;cyr1rG)r6args r,r3zSequential.__init__os?Br;ct|t|dk(rAt|dtr.|dj D]\}}|j ||yt|D] \}}|j t||"y)Nrr) r2r3r$ isinstancerr4r5 enumeratestr)r6rHr8moduleidxr:s r,r3zSequential.__init__rs|  t9>ja+>#Aw}} - VV, - ) 2 VC&1 2r;ct|}tj|}| |cxkr|ksntd|d||z}t t ||dS)z$Get the idx-th item of the iterator.index  is out of rangeN)r$operatorindex IndexErrornextr)r6iteratorrQsizes r,_get_item_by_idxzSequential._get_item_by_idx{sZ4ynnS!u"d"vcU*:;< < t F8S$/00r;ct|tr>|jtt |j j |S|j|j j|Sr1) rMslicer:rlistrEr4r[valuesr6rQs r, __getitem__zSequential.__getitem__sW c5 !>>+d4==3F3F3H.I#.N"OP P(()=)=)?E Er;cp|j|jj|}t|||Sr1)r[rEkeyssetattr)r6rQrPr8s r, __setitem__zSequential.__setitem__s0((););)=sCtS&))r;c t|tr8t|jj |D]}t ||n6|j |jj |}t ||tt|jDcgc] }t|}}ttt||jj|_ycc}wr1) rMr]r^rErcdelattrr[ranger$rOrzipr_)r6rQr8i str_indicess r, __delitem__zSequential.__delitem__s c5 !DMM..01#6 #c" #'' (:(:(t|}t|D]#\}}|j t ||z|%|St dt t|drs)rMrr$rNr5rOrurv)r6rwoffsetrjrPs r,__iadd__zSequential.__iadd__sq eZ (YF&u- 9 6AJ8 9K,,/U ,<+=ZI r;c0t|ts#tdt|dt||dkrt d|dt|t }d}t |D])}|D]"}|jt|||dz }$+|SNz#unsupported operand type(s) for *: z and rz#Non-positive multiplication factor z for r) rMint TypeErrorrvrurrhr5rO)r6rwcombinedr_rPs r,__mul__zSequential.__mul__s%%5d4j\tE{mT aZ5eWE$t*N "|HF5\ " F''F V<aKF  Or;c$|j|Sr1)rr6rws r,__rmul__zSequential.__rmul__s||E""r;c t|ts#tdt|dt||dkrt d|dt|t |}t |}t |dz D]K}t |D]6}|jt||z|jt|8||z }M|Sr) rMrrrvrur$rhr5rOrE)r6rw len_originalrrrjs r,__imul__zSequential.__imul__s%%5d4j\tE{mT aZ5eWE$t*N t9LYF519% '|,LAOOCF OT]]3q65JKL,& 'Kr;cnt|}|Dcgc]}|jr|}}|Scc}wr1r2__dir__isdigitr6rcr8r:s r,rzSequential.__dir__4w #93;;=99 :22cHt|jjSr1iterrEr_ros r,__iter__zSequential.__iter__DMM((*++r;c$|D] }||} |S)z( Runs the forward pass. rG)r6inputrPs r,forwardzSequential.forwards! "F5ME " r;cN|jtt|||S)a Append a given module to the end. Args: module (nn.Module): module to append Example:: >>> import torch.nn as nn >>> n = nn.Sequential(nn.Linear(1, 2), nn.Linear(2, 3)) >>> n.append(nn.Linear(3, 4)) Sequential( (0): Linear(in_features=1, out_features=2, bias=True) (1): Linear(in_features=2, out_features=3, bias=True) (2): Linear(in_features=3, out_features=4, bias=True) ) r5rOr$r6rPs r,rtzSequential.appends$ CI/ r;cvt|tstdtt|j}| |cxkr|ksnt d||dkr||z }t ||dD]3}|jt|dz |jt|<5||jt|<|S)a| Inserts a module into the Sequential container at the specified index. Args: index (int): The index to insert the module. module (Module): The module to be inserted. Example:: >>> import torch.nn as nn >>> n = nn.Sequential(nn.Linear(1, 2), nn.Linear(2, 3)) >>> n.insert(0, nn.Linear(3, 4)) Sequential( (0): Linear(in_features=3, out_features=4, bias=True) (1): Linear(in_features=1, out_features=2, bias=True) (2): Linear(in_features=2, out_features=3, bias=True) ) zmodule should be of type: zIndex out of range: rr)rMrAssertionErrorr$rErWrhrO)r6rVrPnrjs r,insertzSequential.inserts(&&) #=fX!FG G  e q 3E7;< < 19 QJEq%$ >A$(MM#a!e*$=DMM#a& ! >$* c%j! r;c6|D]}|j||S)a Extends the current Sequential container with layers from another Sequential container. Args: sequential (Sequential): A Sequential container whose layers will be added to the current container. Example:: >>> import torch.nn as nn >>> n = nn.Sequential(nn.Linear(1, 2), nn.Linear(2, 3)) >>> other = nn.Sequential(nn.Linear(3, 4), nn.Linear(4, 5)) >>> n.extend(other) # or `n + other` Sequential( (0): Linear(in_features=1, out_features=2, bias=True) (1): Linear(in_features=2, out_features=3, bias=True) (2): Linear(in_features=3, out_features=4, bias=True) (3): Linear(in_features=4, out_features=5, bias=True) ) )rt)r6 sequentialrys r,extendzSequential.extend2s$*  E KK   r;)rHrr<r=)rKzOrderedDict[str, Module]r<r=)rYz Iterable[_V]rQrr<r)rQUnion[slice, int]r<zUnion[Sequential, Module]rQrrPrr<r=)rQrr<r=r<r)r<rr8Union[int, slice]r<r)r<r)rwrr<r)rwrr<rr<z list[str]r<zIterator[Module]rPrr<r)rVrrPrr<r)rIterable[Module]r<r)r>r?r@__doc____annotations__r r3r[rrarerlrprzr%rrrrrrrrtrrrArBs@r,rr;s,\  22 BB21FF * T""  $#$ ,,*@r;rceZdZUdZded<ddfd ZdZeddZeddZe ddZdd Z dd Z e dd Z e dd Z dd ZddZd dZe d!fd Zd"dZd#dZd$dZddZxZS)%raHolds submodules in a list. :class:`~torch.nn.ModuleList` can be indexed like a regular Python list, but modules it contains are properly registered, and will be visible by all :class:`~torch.nn.Module` methods. Args: modules (iterable, optional): an iterable of modules to add Example:: class MyModule(nn.Module): def __init__(self) -> None: super().__init__() self.linears = nn.ModuleList([nn.Linear(10, 10) for i in range(10)]) def forward(self, x): # ModuleList can act as an iterable, or be indexed using ints for i, l in enumerate(self.linears): x = self.linears[i // 2](x) + l(x) return x rDrEc2t||||z }yyr1)r2r3r6modulesr:s r,r3zModuleList.__init__fs"    GOD r;ctj|}t| |cxkrt|ksntd|d|dkr|t|z }t |Sz/Get the absolute index for the list of modules.rSrTrrUrVr$rWrOr`s r,_get_abs_string_indexz ModuleList._get_abs_string_indexkZnnS!T c-CI-vcU*:;< < 7 3t9 C3xr;cyr1rGr`s r,razModuleList.__getitem__ts58r;cyr1rGr`s r,razModuleList.__getitem__wrIr;ct|tr5|jt|jj |S|j|j |Sr1)rMr]r:r^rEr_rr`s r,razModuleList.__getitem__zsL c5 !>>$t}}';';'=">s"CD D==!;!;C!@A Ar;cP|j|}t|t||Sr1)rrdrO)r6rQrPs r,rezModuleList.__setitem__s%((-tSXv..r;c t|tr>#d* *VH(+,mAB/3 &DAqOB''!"%a(A-(  $ $aV ,  " "1 %  &>>#c)%():O%L % ! XvXJc!-J6!X%)  !F83qcQC@ #J2J LL $ % FV[[//$66C96sD&cnt|}|Dcgc]}|jr|}}|Scc}wr1rrs r,rzModuleList.__dir__rrctt|j|dD]3}|jt|dz |jt|<5||jt|<y)zInsert a given module before a given index in the list. Args: index (int): index to insert. module (nn.Module): module to insert rrN)rhr$rErO)r6rVrPrjs r,rzModuleList.insertsZs4==)5"5 >A$(MM#a!e*$=DMM#a& ! >$* c%j!r;cN|jtt|||S)zvAppend a given module to the end of the list. Args: module (nn.Module): module to append rrs r,rtzModuleList.appends CI/ r;c||}||=|Sr1rGr|s r,r%zModuleList.pops I Ir;ct|tjs!tdt |j zt |}t|D]#\}}|jt||z|%|S)zAppend modules from a Python iterable to the end of the list. Args: modules (iterable): iterable of modules to append z=ModuleList.extend should be called with an iterable, but got ) rMcontainer_abcsrrrvr>r$rNr5rO)r6rrrjrPs r,rzModuleList.extendsv '>#:#:;%'+G}'='=> T"7+ 5IAv OOC OV 4 5 r;r1)rzOptional[Iterable[Module]]r<r=)rQr]r<r)rQrr<r)rQrr<zUnion[Module, ModuleList]r)rQrr<r=rr)rrr<r)rwrr<rr<rOr)rVrrPrr<r=rr)r>r?r@rrr3rr rarrerlrprrrzrrrrtr%rrArBs@r,rrLs.  88 22BB /T"",,$ @ + r;rceZdZUdZded<ddfd ZeddZddZddZ eddZ edd Z edd Z dd Z dd Zedd ZeddZeddZddZxZS)raHolds submodules in a dictionary. :class:`~torch.nn.ModuleDict` can be indexed like a regular Python dictionary, but modules it contains are properly registered, and will be visible by all :class:`~torch.nn.Module` methods. :class:`~torch.nn.ModuleDict` is an **ordered** dictionary that respects * the order of insertion, and * in :meth:`~torch.nn.ModuleDict.update`, the order of the merged ``OrderedDict``, ``dict`` (started from Python 3.6) or another :class:`~torch.nn.ModuleDict` (the argument to :meth:`~torch.nn.ModuleDict.update`). Note that :meth:`~torch.nn.ModuleDict.update` with other unordered mapping types (e.g., Python's plain ``dict`` before Python version 3.6) does not preserve the order of the merged mapping. Args: modules (iterable, optional): a mapping (dictionary) of (string: module) or an iterable of key-value pairs of type (string, module) Example:: class MyModule(nn.Module): def __init__(self) -> None: super().__init__() self.choices = nn.ModuleDict( {"conv": nn.Conv2d(10, 10, 3), "pool": nn.MaxPool2d(3)} ) self.activations = nn.ModuleDict( [["lrelu", nn.LeakyReLU()], ["prelu", nn.PReLU()]] ) def forward(self, x, choice, act): x = self.choices[choice](x) x = self.activations[act](x) return x rDrEcJt|||j|yyr1)r2r3updaters r,r3zModuleDict.__init__s%    KK  r;c |j|Sr1rEr6r8s r,razModuleDict.__getitem__#s}}S!!r;c(|j||yr1)r5)r6r8rPs r,rezModuleDict.__setitem__'s V$r;c|j|=yr1rrs r,rlzModuleDict.__delitem__*s MM# r;c,t|jSr1rnros r,rpzModuleDict.__len__-rqr;c,t|jSr1)rrEros r,rzModuleDict.__iter__1sDMM""r;c||jvSr1rrs r, __contains__zModuleDict.__contains__5sdmm##r;c8|jjy)z%Remove all items from the ModuleDict.N)rEclearros r,rzModuleDict.clear9s r;c||}||=|S)zRemove key from the ModuleDict and return its module. Args: key (str): key to pop from the ModuleDict rGr|s r,r%zModuleDict.pop= I Ir;c6|jjS)z*Return an iterable of the ModuleDict keys.)rErcros r,rczModuleDict.keysGs}}!!##r;c6|jjS)z5Return an iterable of the ModuleDict key/value pairs.)rEr4ros r,r4zModuleDict.itemsLs}}""$$r;c6|jjS)z,Return an iterable of the ModuleDict values.)rEr_ros r,r_zModuleDict.valuesQs}}##%%r;c Pt|tjs!tdt |j zt|t ttjfr|jD] \}}|||< y t|D]\}}t|tjs0tdt|zdzt |j zt|dk(s2tdt|zdztt|zdz|d||d<y ) aUpdate the :class:`~torch.nn.ModuleDict` with key-value pairs from a mapping, overwriting existing keys. .. note:: If :attr:`modules` is an ``OrderedDict``, a :class:`~torch.nn.ModuleDict`, or an iterable of key-value pairs, the order of new elements in it is preserved. Args: modules (iterable): a mapping (dictionary) from string to :class:`~torch.nn.Module`, or an iterable of key-value pairs of type (string, :class:`~torch.nn.Module`) zPModuleDict.update should be called with an iterable of key/value pairs, but got z$ModuleDict update sequence element # should be Iterable; isr has length ; 2 is requiredrrN)rMrrrrvr>rrrr4rNrOr$ru)r6rr8rPjms r,rzModuleDict.updateVs8'>#:#:;8:>w-:P:PQ  g Z9O9OP Q&}} # V"S  #"'* "1!!^%<%<=#!!f%'@ACG7CSCST1v{$!!f%'568;CF DFWX qTQqT  "r;r1)rzOptional[Mapping[str, Module]]r<r=)r8rOr<r)r8rOrPrr<r=r8rOr<r=rr<z Iterator[str]r8rOr<boolr<r=r<zcontainer_abcs.KeysView[str])r<z%container_abcs.ItemsView[str, Module])r<z!container_abcs.ValuesView[Module])rzMapping[str, Module]r<r=)r>r?r@rrr3rrarerlrprrrr%rcr4r_rrArBs@r,rrs'R ! ""%""##$$$$%%&&#"r;rceZdZdZddfd ZdZeddZeddZdZddZddZ dd Z dd Z dfd Z dd Z dd ZddZdZxZS)radHolds parameters in a list. :class:`~torch.nn.ParameterList` can be used like a regular Python list, but Tensors that are :class:`~torch.nn.Parameter` are properly registered, and will be visible by all :class:`~torch.nn.Module` methods. Note that the constructor, assigning an element of the list, the :meth:`~torch.nn.ParameterList.append` method and the :meth:`~torch.nn.ParameterList.extend` method will convert any :class:`~torch.Tensor` into :class:`~torch.nn.Parameter`. Args: parameters (iterable, optional): an iterable of elements to add to the list. Example:: class MyModule(nn.Module): def __init__(self) -> None: super().__init__() self.params = nn.ParameterList( [nn.Parameter(torch.randn(10, 10)) for i in range(10)] ) def forward(self, x): # ParameterList can act as an iterable, or be indexed using ints for i, p in enumerate(self.params): x = self.params[i // 2].mm(x) + p.mm(x) return x c@t|d|_|||z }yy)Nr)r2r3_size)r6r_r:s r,r3zParameterList.__init__s)    FND r;ctj|}t| |cxkrt|ksntd|d|dkr|t|z }t |Srrr`s r,rz#ParameterList._get_abs_string_indexrr;cyr1rGr`s r,razParameterList.__getitem__s,/r;cyr1rGr`s r,razParameterList.__getitem__rIr;ct|trV|jt|\}}}|j }t |||D]}|j |||S|j|}t|t|Sr1) rMr]indicesr$r:rhrtrgetattrrO)r6rQstartstopstepoutrjs r,razParameterList.__getitem__s c5 ! # CI 6 E4.."C5$- $ 47# $J,,S1C4S* *r;c|j|}t|tjrt|ts t |}t |t ||Sr1)rrMtorchTensorrrdrO)r6rQparams r,rezParameterList.__setitem__sH ((- eU\\ *:eY3Oe$EtSXu--r;c|jSr1)rros r,rpzParameterList.__len__s zzr;cPtfdttDS)Nc3(K|] }| ywr1rG).0rjr6s r, z)ParameterList.__iter__..s6DG6)rrhr$ros`r,rzParameterList.__iter__s6U3t9%5666r;c$|j|Sr1r)r6 parameterss r,rzParameterList.__iadd__s{{:&&r;cnt|}|Dcgc]}|jr|}}|Scc}wr1rrs r,rzParameterList.__dir__s4w #93;;=99 :rcPt|}|xjdz c_|||<|S)zmAppend a given value at the end of the list. Args: value (Any): value to append r)r$r)r6r9new_idxs r,rtzParameterList.appends( d) a W  r;ct|tjrt|tjr!t dt |jz|D]}|j||S)zAppend values from a Python iterable to the end of the list. Args: values (iterable): iterable of values to append z@ParameterList.extend should be called with an iterable, but got ) rMrrrrrrvr>rt)r6r_r9s r,rzParameterList.extendsl&."9"9:j ELL? %'+F|'<'<=  E KK   r;c|g}t|D]\}}t|tjrdj d|j D}|j jdtjjfvrd|j d}nd}djt|trdnd |j||}|jd t|zd z|z|jd t|zd zt|jzd j |}|S)z@ Return the extra representation of the module. xc32K|]}t|ywr1rOrrZs r,rz+ParameterList.extra_repr..#C$CI#Ccuda (r {} containing: [{} of size {}{}]rr (r): Object of type: r!)rNrMrrr&rZdevicerv_C_get_privateuse1_backend_nameformatrdtypertrOr>r6 child_linesrpsize_str device_strparastrtmpstrs r, extra_reprzParameterList.extra_reprs dO DAq!U\\*88#C!&&(#CC88==VUXX-S-S-U$VV#%ahhZq!1J!#J<CC#-a#;KGG  ""53q6>E#9G#CD""CFN%::T!W=M=MM &;' r;ctd)Nz#ParameterList should not be called. RuntimeError)r6rHr7s r,__call__zParameterList.__call__ @AAr;r1)r_zOptional[Iterable[Any]]r<r=)rQrr<r)r6rrQr]r<r)rQrrrr<r=r)r<z Iterator[Any])r Iterable[Any]r<rr)r9rr<r)r_r=r<rr)r>r?r@rr3rr rarerprrrrtrr7r;rArBs@r,rr~sc: // 22 + .7' $6Br;rceZdZdZddfd ZddZddZddZd dZd!dZ d"dZ d"d Z d#d Z d$d Z dd%d Zd&d ZddZd'dZdd%dZ d d(dZd)dZd*dZd+dZd,dZd-dZdZd.dZd.dZd/dZxZS)0raHolds parameters in a dictionary. ParameterDict can be indexed like a regular Python dictionary, but Parameters it contains are properly registered, and will be visible by all Module methods. Other objects are treated as would be done by a regular Python dictionary :class:`~torch.nn.ParameterDict` is an **ordered** dictionary. :meth:`~torch.nn.ParameterDict.update` with other unordered mapping types (e.g., Python's plain ``dict``) does not preserve the order of the merged mapping. On the other hand, ``OrderedDict`` or another :class:`~torch.nn.ParameterDict` will preserve their ordering. Note that the constructor, assigning an element of the dictionary and the :meth:`~torch.nn.ParameterDict.update` method will convert any :class:`~torch.Tensor` into :class:`~torch.nn.Parameter`. Args: values (iterable, optional): a mapping (dictionary) of (string : Any) or an iterable of key-value pairs of type (string, Any) Example:: class MyModule(nn.Module): def __init__(self) -> None: super().__init__() self.params = nn.ParameterDict( { "left": nn.Parameter(torch.randn(5, 10)), "right": nn.Parameter(torch.randn(5, 10)), } ) def forward(self, x, choice): x = self.params[choice].mm(x) return x cXt|i|_||j|yyr1)r2r3_keysr)r6rr:s r,r3zParameterDict.__init__8s, &(  ! KK # "r;cjt|ts"tdt|jd|S)NzUIndex given to ParameterDict cannot be used as a key as it is not a string (type is 'z8'). Open an issue on github if you need non-string keys.)rMrOrrvr>rs r, _key_to_attrzParameterDict._key_to_attr>s?#s#**.s)*<*<)=>66 Jr;c<|j|}t||Sr1)rBr r6r8attrs r,razParameterDict.__getitem__Is  %tT""r;cd|j|<|j|}t|tjrt|t s t |}t |||yr1)r@rBrMrrrrd)r6r8r9rEs r,rezParameterDict.__setitem__MsN  3  % eU\\ *:eY3Oe$EdE"r;cX|j|=|j|}t||yr1)r@rBrgrDs r,rlzParameterDict.__delitem__Ys' JJsO  %dr;c,t|jSr1)r$r@ros r,rpzParameterDict.__len__^s4::r;c,t|jSr1)rr@ros r,rzParameterDict.__iter__asDJJr;c,t|jSr1)reversedr@ros r, __reversed__zParameterDict.__reversed__ds ##r;cRttfdjDS)z@Return a copy of this :class:`~torch.nn.ParameterDict` instance.c3,K|] }||f ywr1rGrrr6s r,rz%ParameterDict.copy..ks(J!!T!W(J)rrr@ros`r,copyzParameterDict.copygs[(Jtzz(JJKKr;c||jvSr1r@rs r,rzParameterDict.__contains__msdjj  r;c||vr|||<||S)a\Set the default for a key in the Parameterdict. If key is in the ParameterDict, return its value. If not, insert `key` with a parameter `default` and return `default`. `default` defaults to `None`. Args: key (str): key to set default for default (Any): the parameter set to the key rGr6r8defaults r, setdefaultzParameterDict.setdefaultps d?DICyr;cH|jjD]}||=y)z(Remove all items from the ParameterDict.N)r@rQ)r6rs r,rzParameterDict.clears#" AQ r;c||}||=|S)zRemove key from the ParameterDict and return its parameter. Args: key (str): key to pop from the ParameterDict rGr|s r,r%zParameterDict.poprr;cr|jj\}}d|j|<||}||=||fS)zSRemove and return the last inserted `(key, parameter)` pair from the ParameterDict.N)r@popitem)r6rrvals r,r[zParameterDict.popitems>zz!!#1 1 1g G#v r;c||vr||S|S)aReturn the parameter associated with key if present. Otherwise return default if provided, None if not. Args: key (str): key to get from the ParameterDict default (Parameter, optional): value to return if key not present rGrUs r,getzParameterDict.gets 4KtCy4W4r;c,tfd|DS)zReturn a new ParameterDict with the keys provided. Args: keys (iterable, string): keys to make the new ParameterDict from default (Parameter, optional): value to set for all keys c3&K|]}|f ywr1rG)rrrVs r,rz)ParameterDict.fromkeys..s8aa\8s)r)r6rcrVs `r,fromkeyszParameterDict.fromkeyss84888r;c6|jjS)z-Return an iterable of the ParameterDict keys.)r@rcros r,rczParameterDict.keysszz  r;c.fdjDS)z8Return an iterable of the ParameterDict key/value pairs.c3,K|] }||f ywr1rGrOs r,rz&ParameterDict.items..s1DG 1rPrSros`r,r4zParameterDict.itemss1djj11r;c.fdjDS)z/Return an iterable of the ParameterDict values.c3(K|] }| ywr1rGrOs r,rz'ParameterDict.values..s,AQ,rrSros`r,r_zParameterDict.valuess,,,r;c t|tjs!tdt |j zt|t tfr|jD] \}}|||< y t|tjr't|jD] \}}|||< y t|D]\}}t|tjs0tdt|zdzt |j zt|dk(s2tdt|zdztt|zdz|d||d<y ) a-Update the :class:`~torch.nn.ParameterDict` with key-value pairs from ``parameters``, overwriting existing keys. .. note:: If :attr:`parameters` is an ``OrderedDict``, a :class:`~torch.nn.ParameterDict`, or an iterable of key-value pairs, the order of new elements in it is preserved. Args: parameters (iterable): a mapping (dictionary) from string to :class:`~torch.nn.Parameter`, or an iterable of key-value pairs of type (string, :class:`~torch.nn.Parameter`) zTParametersDict.update should be called with an iterable of key/value pairs, but got z'ParameterDict update sequence element #rrrrrrN)rMrrrrvr>rrr4rsortedrNrOr$ru)r6rr8 parameterrr2s r,rzParameterDict.updatesn*n&=&=>8:>z:J:S:ST  j; "> ?","2"2"4 &Y%S  &  N$:$: ;"()9)9);"< &Y%S  &"*- "1!!^%<%<=#!!f%'@ACG7CSCST1v{$!!f%'568;CF DFWX qTQqT  "r;cg}|jD]"\}}t|tjrdj d|j D}|j jdtjjfvrd|j d}nd}djt|trdnd tj|||}|jd t|zd z|z|jd t|zd zt|jz%d j |}|S)Nrc32K|]}t|ywr1r!r"s r,rz+ParameterDict.extra_repr..r#r$r%r&rr'r(rrr)rr*r!)r4rMrrr&rZr+rvr,r-r.rtypenamertrOr>r0s r,r7zParameterDict.extra_reprs JJL DAq!U\\*88#C!&&(#CC88==VUXX-S-S-U$VV#%ahhZq!1J!#J<CC#-a#;KNN1%  ""53q6>E#9G#CD""CFN%::T!W=M=MM $;' r;ctd)Nz#ParameterDict should not be called.r9)r6rs r,r;zParameterDict.__call__r<r;cH|j}|j||Sr1rQrr6rwrQs r,__or__zParameterDict.__or__syy{ E r;cH|j}|j||Sr1rorps r,__ror__zParameterDict.__ror__szz| D r;c(|j||Sr1)rrs r,__ior__zParameterDict.__ior__s E r;r1)rrr<r=)r8rOr<rO)r8rOr<r)r8rOr9rr<r=rrr)r<rr)r8rOrV Optional[Any]r<rr)r<ztuple[str, Any])rcz Iterable[str]rVrvr<rr)r<zIterable[tuple[str, Any]])r<r=)rz'Union[Mapping[str, Any], ParameterDict]r<r=r)rwrr<r)rwrr<r)r>r?r@rr3rBrarerlrprrLrQrrWrr%r[r^rarcr4r_rr7r;rqrsrurArBs@r,rrs$L$ # #  $L !  5=A 9! 9,9 9  9!2-%"N.B  r;r)* __future__rrU collectionsrrr itertoolsrrtypingrr r r r r typing_extensionsrrrtorch._jit_internalrtorch.nn.parameterrrPrcollections.abcrrr__all__rrr- FutureWarningrrrrrrrGr;r,rs":#II. 7(;;  Cv T]   Z  ((  (NNbaaLG"G"XPBFPBfsFsr;