~L i6 ddlZddlZddlmZddlmZddlmZm Z m Z ddl m Z ddl Z ddlZ ddlZ ddlZ ddlmcmZddlmZgdZe j.j0Ze j.j4Ze j.j8ZdZe d Ze d Z d ee jBjDfd Z#ed Z$dZ%dZ&GddZ'de(d e(fdZ)de jBjDee fded e eee feffdZ*edZ+y)N)Iterator)contextmanager)CallableTypeVarUnion) ParamSpec) DispatchKey)enable_python_dispatcherno_python_dispatcherenable_pre_dispatchF_P_Treturnc#KtjD]D}ttj|}|D]#}t||}|D]}t||%Fyw)a Warning: the set of overloads this will report is very subtle. It is precisely the set of torch.ops functions that have actually been accessed from Python (e.g., we actually called torch.ops.aten.blah at some point. This is DIFFERENT from the set of registered operators, which will in general be a larger set, as this would include all operators which we ran C++ static initializers or Python operator registration on. This does not eagerly populate the list on torch.ops.aten; this list is lazy! In other words, this is good for traversing over everything that has an OpOverload object allocated in Python. We use it for cache invalidation, but don't rely on this list being complete. Note that even if we did report all C++ registered overloads, this isn't guaranteed to be complete either, as a subsequent lazy load of a library which triggers more registrations could add more things to the set. N)torchopsgetattr)nspacketsop_namepacketoverloads \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/_dispatch/python.pyall_py_loaded_overloadsrsb$ii0%))R( 0GWg.F" 0fh// 0 00sAAc#nKtjjtjjj}tjj }|rtj  d|rtj|yy#|rtj|wwxYww)N) reapply_views)r_C&_dispatch_tls_is_dispatch_key_includedr Functionalize$_functionalization_reapply_views_tls_disable_functionalization_enable_functionalization)f_tlsf_rvs rsuspend_functionalizationr%7s HH ; ; ** E 88 8 8 :D  ((*@   + +$ ? 5  + +$ ? sA6B59B=B5B22B5c t|sJ|j|jk(s0J|d|jd|j|j|jk(s(J|d|jd|jtjj ||d\}}|s4J|d|j d|j d|dy) Nz: sizes  != z: dtype F) only_cudaz : strides z (mismatch at index ))callablesizedtyper _prims_commoncheck_significant_stridesstride)nvrvdesc same_stridesidxs rcheck_tensor_metadata_matchesr5Fs D>> 779 !PdfXXbggi[RWWYK#PP ! 88rxx LDF88BHH:T"((!LL ++EE B%FL#  6(*RYY[Mbiik]:NseSTU<c tsJtj|\}}tj|\}}t|t|k(sJt|dt|t t t|||D]2\ }}t |tjs"t|| fd4y)Nr'cdS)Nz output )r2isrz(check_metadata_matches..\s6Lr6) r*pytree tree_flattenlenziprange isinstancerTensorr5) nrr2n_vals_n_specr_vals_r_specr0r1r:s ` @rcheck_metadata_matchesrIRs D>>))!,OFG))!,OFG v;#f+ %H#f+d3v;-'HH %s6{+VV<N 2r"ell+ %b".LMNr6ceZdZdZdZy)Litc||_yNs)selfrOs r__init__z Lit.__init__`s r6c|jSrMrN)rPs r__repr__z Lit.__repr__cs vv r6N)__name__ __module__ __qualname__rQrSr9r6rrKrK_s r6rKac t|tjrDtdt |j d|j d|jdS|S)Nztorch.empty_strided(, z, dtype=r))rArrBrKtupler+r/r,)rWs r_fmtr[gsR!U\\""5?"32ahhj\!''RS T  r6op final_keycddlmtjjj j k(rSdtjdtjdtffd }|S)Nr)FakeTensorModeargskwargsrc  fd}d}tjjj5t 5t j |||f\}}t j |||f\ 5|i|}dddddddddj g|i|} fd}t|||S#1swYExYw#1swYIxYw#1swYMxYw)NcBt|tjrtj|r[tj|}|j |j k(sJ|j |j k(sJ|}j|S|SrM)rArrB_is_functional_tensor_from_functional_tensorr+r/ from_tensor)trD fake_modes r fakeify_defunzCmake_crossref_functionalize..handler..fakeify_defun|s!U\\*..q155a8A 668qvvx///88:333A ,,Q//Hr6cZt|tjr|jS|SrM)rArrBdetach)rgs r maybe_detachzBmake_crossref_functionalize..handler..maybe_detachs!!U\\*xxz!r6cdjtjdDdjD}d|dS)NrYc3bK|]'}ttjt|)ywrM)reprr<tree_mapr[).0rWs r zMmake_crossref_functionalize..handler..desc..s IT&//$23Is-/c3`K|]&\}}|dtjt|(yw)=N)r<rpr[)rqkvs rrrzMmake_crossref_functionalize..handler..desc..s3 Aq#QvtQ789s,.(r))join itertoolschainitems)fmt_argsr\ orig_f_args orig_f_kwargss rr2z:make_crossref_functionalize..handler..descsPyyI[I$1$7$7$9HT8*A& &r6) rutils_python_dispatch_disable_current_modesr%r<rp_op_dkrI)r`rarirlf_argsf_kwargsf_rrDr2rhr}r~r_r]r\s @@@rhandlerz,make_crossref_functionalize..handlerys"$     KK ( ( ? ? A . % ' . &}tVnM FH)/vx0* &K .&-H- . . . BIIi 1$ 1& 1 ' sAt,# . . . . . .s; C%9C C  CC% C CC" C%%C.) torch._subclasses.fake_tensorr_rraten lift_freshdefaultr r`rar)r\r]rr_s`` @rmake_crossref_functionalizerpsV= UYY^^ & & . ..4rww4"))44l Nr6c#TKtD]5}|jtjjj 7 t 5tjjdd5dddddddtD]5}|jtjjj 7y#1swYTxYw#1swYXxYw#tD]5}|jtjjj 7wxYww)Nz-torch._dispatch.python.CROSSREF_FUNCTIONALIZET) r_uncache_dispatchrrr rr unittestmockpatch)r\s renable_crossref_functionalizers%'A UXX11??@AE $ &  MM   OQU V      *+ EB  !5!5!C!C D E      *+ EB  !5!5!C!C D EsPAD( C!!C1C 6C>C!AD( C CCC!!AD%%D(),ry unittest.mockrcollections.abcr contextlibrtypingrrrtyping_extensionsrrtorch._C torch._opstorch.utils._python_dispatchtorch.utils._pytreer_pytreer<r __all__r_DisablePythonDispatcherr _EnablePythonDispatcherr _EnablePreDispatchr CROSSREF_FUNCTIONALIZEr r_ops OpOverloadrr%r5rIrKobjectr[rrr9r6rrs2$%++' #$$  Vxx88 88;;hh11t_ T]0%***?*?!@04 @ @  NFv? b"f%?2=? 8BF [ ()?H E Er6