trace_rules.py 153 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029
  1. """
  2. Tracing rules and policies for TorchDynamo compilation decisions.
  3. This module defines the rules that govern what code TorchDynamo should trace and compile
  4. versus what should be executed eagerly. It contains functions and classes that determine:
  5. - Which modules, functions, and objects should be skipped during tracing
  6. - Which parts of the code should cause graph breaks
  7. - How to handle different Python libraries and third-party packages
  8. - Rules for determining when to inline functions vs calling them eagerly
  9. Key components:
  10. - Skip rules: Functions that return True if an object should be skipped during tracing
  11. - Inlining rules: Policies for when to inline function calls during compilation
  12. - Library-specific handling: Special cases for popular Python packages
  13. - Performance heuristics: Rules that balance compilation overhead vs runtime benefits
  14. These rules are critical for TorchDynamo's ability to automatically determine
  15. compilation boundaries and optimize PyTorch programs effectively.
  16. """
  17. import abc
  18. import builtins
  19. import copy
  20. import dataclasses
  21. import functools
  22. import importlib
  23. import inspect
  24. import linecache
  25. import operator
  26. import os
  27. import random
  28. import re
  29. import sys
  30. import traceback
  31. import types
  32. import unittest
  33. from collections import defaultdict
  34. from pathlib import Path
  35. from typing import Any, Callable, cast, Optional, Union
  36. import torch
  37. import torch._inductor.test_operators
  38. import torch.distributed
  39. import torch.utils._content_store
  40. from torch._environment import is_fbcode
  41. from torch.utils import _config_module
  42. from . import config
  43. from .resume_execution import TORCH_DYNAMO_RESUME_IN_PREFIX
  44. from .utils import (
  45. getfile,
  46. hashable,
  47. is_lru_cache_wrapped_function,
  48. NP_SUPPORTED_MODULES,
  49. unwrap_if_wrapper,
  50. )
  51. from .variables import (
  52. BuiltinVariable,
  53. FunctionalCallVariable,
  54. FunctorchHigherOrderVariable,
  55. LocalGeneratorFunctionVariable,
  56. LocalGeneratorObjectVariable,
  57. NestedUserFunctionVariable,
  58. PolyfilledFunctionVariable,
  59. ReparametrizeModuleCallVariable,
  60. SkipFunctionVariable,
  61. TorchInGraphFunctionVariable,
  62. UserFunctionVariable,
  63. UserMethodVariable,
  64. )
  65. from .variables.base import VariableTracker
  66. np: Optional[types.ModuleType] = None
  67. try:
  68. import numpy as np
  69. except ModuleNotFoundError:
  70. pass
  71. """
  72. A note on skip/inline rules:
  73. Dynamo consults this file to determine whether function should be inlined or skipped.
  74. A skip applies at the frame boundary, meaning dynamo either triggers a graph break
  75. at the beginning of the frame or attempts to trace/inline the whole frame. When skipping
  76. a frame, recursively called frames are still traced by dynamo unless also skipped.
  77. Skipfiles (skipped at the file level instead of function level) still apply on a
  78. frame-by-frame boundary as dynamo traces, but apply to all functions in that file.
  79. @skip is a helper decorator that can be applied to your function to cause it to be
  80. included here.
  81. Dynamo skip/inline rules & priorities are defined as follows:
  82. * Inline is the default behavior and will be used unless explicitly skipped.
  83. * Dynamo has two SKIPLIST: BUILTIN_SKIPLIST and THIRDPARTY_SKIPLIST.
  84. * BUILTIN_SKIPLIST contains builtin python modules, such as abc, collections, etc.
  85. * THIRDPARTY_SKIPLIST contains common third party libraries, such as numpy, pandas, etc.
  86. * Functions in these two SKIPLISTs are always skipped, except:
  87. * They have explicitly defined rule in `manual_torch_name_rule_map`;
  88. * The corresponding python module has been put into MOD_INLINELIST.
  89. * PyTorch(torch) is in the BUILTIN_SKIPLIST by default, but there are many cases
  90. where we want inline the functions under torch namespace.
  91. We should specify inline for the functions in `manual_torch_name_rule_map` or
  92. put the corresponding python module into MOD_INLINELIST to make dynamo inline them.
  93. * If you call functions under skipped modules/files, Dynamo will wrap these functions
  94. as SkipFunctionVariable. There are a few functions(e.g, collections.OrderedDict) that
  95. we have special handling at SkipFunctionVariable.call_function.
  96. Overall: *_INLINELIST has precedence over *_SKIPLIST has precedence over DEFAULT (inline)
  97. To figure out what the behavior is, check the following list in order:
  98. * `manual_torch_name_rule_map` (Inline if YES)
  99. * MOD_INLINELIST (Inline if YES)
  100. * BUILTIN_SKIPLIST & THIRDPARTY_SKIPLIST (Skip if YES)
  101. * MOD_SKIPLIST (Skip if YES)
  102. * Inline by default
  103. In general, if you want to force inline a function or module, please consider adding
  104. the function's python module to MOD_INLINELIST first.
  105. Use the `manual_torch_name_rule_map` only when there are other functions under the same module that
  106. you don't want to inline them.
  107. """
  108. """
  109. Map of function objects to their tracing rules (Dynamo variables).
  110. * TorchInGraphFunctionVariable: The functions should be put into the FX graph or can be constant folded. E.g.,
  111. - torch.add: should be put into the FX graph.
  112. - torch.is_floating_point: constant folded.
  113. * SkipFunctionVariable: The objects should be skipped from tracing.
  114. * UserFunctionVariable: The functions should be inlined.
  115. For developers: If you add/remove a torch level API, it may trigger failures from
  116. test/dynamo/test_trace_rules.py:test_torch_name_rule_map_updated. To fix the failures:
  117. If you are adding a new torch level API or Dynamo implementation:
  118. * Add the name with the corresponding tracing rule to this map
  119. if you are adding a new in graph function or Dynamo implementation for an existing function.
  120. * Remove the object name from test/dynamo/test_trace_rules.ignored_c_binding_in_graph_function_names if it's there.
  121. If you are removing an existing torch level API:
  122. * Remove the entry represented the API from this map or test/dynamo/test_trace_rules.ignored_c_binding_in_graph_function_names
  123. depends on where it is.
  124. """
  125. manual_torch_name_rule_map: dict[
  126. str,
  127. Union[
  128. type[TorchInGraphFunctionVariable],
  129. type[SkipFunctionVariable],
  130. type[UserFunctionVariable],
  131. ],
  132. ] = {
  133. "torch.onnx.is_in_onnx_export": TorchInGraphFunctionVariable,
  134. "torch.onnx.operators.shape_as_tensor": TorchInGraphFunctionVariable,
  135. "torch.overrides.is_tensor_like": TorchInGraphFunctionVariable,
  136. "torch.jit.is_scripting": TorchInGraphFunctionVariable,
  137. "torch.jit.is_tracing": TorchInGraphFunctionVariable,
  138. "torch.jit.annotate": TorchInGraphFunctionVariable,
  139. "torch.distributed.is_available": TorchInGraphFunctionVariable,
  140. "torch.distributed.is_initialized": TorchInGraphFunctionVariable,
  141. "torch.distributed.get_rank": TorchInGraphFunctionVariable,
  142. "torch.distributed.get_world_size": TorchInGraphFunctionVariable,
  143. "torch.distributed.tensor._api.DTensor#from_local": TorchInGraphFunctionVariable,
  144. "torch.distributed.distributed_c10d._get_group_size_by_name": TorchInGraphFunctionVariable,
  145. "torch.distributed.distributed_c10d._resolve_group_name_by_ranks_and_tag": TorchInGraphFunctionVariable,
  146. "torch.distributed.distributed_c10d._get_group_tag": TorchInGraphFunctionVariable,
  147. "torch.distributed.distributed_c10d.get_process_group_ranks": TorchInGraphFunctionVariable,
  148. "torch._utils.is_compiling": TorchInGraphFunctionVariable,
  149. "torch.fx._symbolic_trace.is_fx_tracing": TorchInGraphFunctionVariable,
  150. "torch.fx._symbolic_trace.is_fx_symbolic_tracing": TorchInGraphFunctionVariable,
  151. "torch._dynamo.external_utils.is_compiling": TorchInGraphFunctionVariable,
  152. "torch._dynamo.utils._disable_side_effect_safety_checks_for_current_subtracer": UserFunctionVariable,
  153. "torch.compiler.is_compiling": TorchInGraphFunctionVariable,
  154. "torch.compiler.is_dynamo_compiling": TorchInGraphFunctionVariable,
  155. "torch.compiler.is_exporting": TorchInGraphFunctionVariable,
  156. "torch.autograd._profiler_enabled": SkipFunctionVariable,
  157. "torch._C._to_dlpack": SkipFunctionVariable,
  158. "torch.to_dlpack": SkipFunctionVariable,
  159. # We graph break on RNG state setters or getters like
  160. # `torch.get_rng_state` or `torch.set_rng_state`. These functions
  161. # are not aten operations and therefore they are completely ignored
  162. # by the AOT dispatcher. As a result, the AOT graph does not have
  163. # these setter or getter functions, producing an incorrect graph
  164. # when it comes to rng states.
  165. "torch.default_generator#get_state": SkipFunctionVariable,
  166. "torch._C.Generator#get_state": SkipFunctionVariable,
  167. "torch.get_rng_state": SkipFunctionVariable,
  168. "torch.cuda.get_rng_state": SkipFunctionVariable,
  169. "torch.default_generator#set_state": SkipFunctionVariable,
  170. "torch._C.Generator#set_state": SkipFunctionVariable,
  171. "torch.set_rng_state": SkipFunctionVariable,
  172. "torch.cuda.set_rng_state": SkipFunctionVariable,
  173. # https://github.com/pytorch/pytorch/issues/107187
  174. "torch.manual_seed": SkipFunctionVariable,
  175. # https://github.com/pytorch/pytorch/issues/93501
  176. "torch.nn.utils.rnn.pack_padded_sequence": SkipFunctionVariable,
  177. "torch.nn.Parameter": TorchInGraphFunctionVariable,
  178. "torch.nn.Buffer": TorchInGraphFunctionVariable,
  179. "torch._nested_tensor_from_mask": SkipFunctionVariable,
  180. "torch.nested._internal.nested_tensor.nested_from_padded": TorchInGraphFunctionVariable,
  181. "torch.nested.nested_tensor_from_jagged": UserFunctionVariable,
  182. "torch.nested.nested_tensor_from_padded": UserFunctionVariable,
  183. # torch.fx map utils
  184. "torch.fx.node.map_aggregate": UserFunctionVariable,
  185. "torch.fx.node.map_arg": UserFunctionVariable,
  186. "torch.fx.immutable_collections._no_mutation": UserFunctionVariable,
  187. "torch.fx.immutable_collections._immutable_list_flatten": UserFunctionVariable,
  188. "torch.fx.immutable_collections._immutable_list_unflatten": UserFunctionVariable,
  189. "torch.fx.immutable_collections._immutable_dict_flatten": UserFunctionVariable,
  190. "torch.fx.immutable_collections._immutable_dict_unflatten": UserFunctionVariable,
  191. # symbol operators implemented in Python
  192. "torch.sym_not": TorchInGraphFunctionVariable,
  193. "torch.sym_float": TorchInGraphFunctionVariable,
  194. "torch.sym_int": TorchInGraphFunctionVariable,
  195. "torch.sym_max": TorchInGraphFunctionVariable,
  196. "torch.sym_min": TorchInGraphFunctionVariable,
  197. "torch.sym_sqrt": TorchInGraphFunctionVariable,
  198. "torch.sym_ite": TorchInGraphFunctionVariable,
  199. "torch.sym_sum": TorchInGraphFunctionVariable,
  200. "torch.sym_fresh_size": UserFunctionVariable,
  201. "torch.Tensor#_make_wrapper_subclass": SkipFunctionVariable,
  202. "torch.Tensor#__init__": SkipFunctionVariable,
  203. "torch.Tensor#split": TorchInGraphFunctionVariable,
  204. "torch.cuda.set_device": SkipFunctionVariable,
  205. "torch.cuda.current_device": TorchInGraphFunctionVariable,
  206. "torch._C.autocast_decrement_nesting": SkipFunctionVariable,
  207. "torch._C.autocast_increment_nesting": SkipFunctionVariable,
  208. "torch.autograd.grad": SkipFunctionVariable,
  209. "torch.autograd.backward": SkipFunctionVariable,
  210. "torch._C.clear_autocast_cache": SkipFunctionVariable,
  211. "torch.distributions.constraints.is_dependent": SkipFunctionVariable,
  212. "torch.jit.isinstance": SkipFunctionVariable,
  213. "torch._C.set_anomaly_enabled": SkipFunctionVariable,
  214. "torch._C.set_autocast_cache_enabled": SkipFunctionVariable,
  215. "torch._C.set_autocast_cpu_dtype": SkipFunctionVariable,
  216. "torch._C.set_autocast_cpu_enabled": SkipFunctionVariable,
  217. "torch._C.set_autocast_enabled": SkipFunctionVariable,
  218. "torch._C.set_autocast_gpu_dtype": SkipFunctionVariable,
  219. "torch._C.set_autocast_ipu_dtype": SkipFunctionVariable,
  220. "torch._C.set_autocast_ipu_enabled": SkipFunctionVariable,
  221. "torch._C.set_autocast_xla_dtype": SkipFunctionVariable,
  222. "torch._C.set_autocast_xla_enabled": SkipFunctionVariable,
  223. "torch.resize_as_": SkipFunctionVariable,
  224. "torch._functorch.predispatch._add_batch_dim": TorchInGraphFunctionVariable,
  225. "torch._functorch.predispatch._remove_batch_dim": TorchInGraphFunctionVariable,
  226. "torch.resize_as_sparse_": SkipFunctionVariable,
  227. "torch.get_default_device": TorchInGraphFunctionVariable,
  228. # functorch/vmap
  229. "torch._functorch.vmap._check_int_or_none": UserFunctionVariable,
  230. "torch._functorch.vmap._check_out_dims_is_int_or_int_pytree": UserFunctionVariable,
  231. "torch._functorch.vmap._check_randomness_arg": UserFunctionVariable,
  232. "torch._functorch.vmap._chunked_vmap": UserFunctionVariable,
  233. "torch._functorch.vmap._concat_chunked_outputs": UserFunctionVariable,
  234. "torch._functorch.vmap._create_batched_inputs": UserFunctionVariable,
  235. "torch._functorch.vmap._flat_vmap": UserFunctionVariable,
  236. "torch._functorch.vmap._flatten_chunks_output": UserFunctionVariable,
  237. "torch._functorch.vmap._get_chunked_inputs": UserFunctionVariable,
  238. "torch._functorch.vmap._get_name": UserFunctionVariable,
  239. "torch._functorch.vmap._maybe_remove_batch_dim": UserFunctionVariable,
  240. "torch._functorch.vmap._num_outputs": UserFunctionVariable,
  241. "torch._functorch.vmap._process_batched_inputs": UserFunctionVariable,
  242. "torch._functorch.vmap._unwrap_batched": UserFunctionVariable,
  243. "torch._functorch.vmap._validate_and_get_batch_size": UserFunctionVariable,
  244. "torch._functorch.vmap.doesnt_support_saved_tensors_hooks": UserFunctionVariable,
  245. "torch._functorch.vmap.get_chunk_sizes": UserFunctionVariable,
  246. # lazy_load_decompositions uses a lock that is not supported yet in dynamo
  247. # "torch._functorch.vmap.lazy_load_decompositions": UserFunctionVariable,
  248. "torch._functorch.vmap.restore_vmap": UserFunctionVariable,
  249. "torch._functorch.apis.vmap": UserFunctionVariable,
  250. "torch._functorch.vmap.unwrap_batched": UserFunctionVariable,
  251. "torch._functorch.vmap.vmap_impl": FunctorchHigherOrderVariable,
  252. "torch._functorch.vmap.wrap_batched": UserFunctionVariable,
  253. # functorch/grad
  254. "torch._functorch.eager_transforms.grad_impl": FunctorchHigherOrderVariable,
  255. "torch._functorch.apis.grad_and_value": UserFunctionVariable,
  256. "torch._functorch.eager_transforms._as_tuple": UserFunctionVariable,
  257. "torch._functorch.eager_transforms._check_unique_non_empty": UserFunctionVariable,
  258. "torch._functorch.eager_transforms._create_differentiable": UserFunctionVariable,
  259. "torch._functorch.eager_transforms._slice_argnums": UserFunctionVariable,
  260. "torch._functorch.eager_transforms._undo_create_differentiable": UserFunctionVariable,
  261. "torch._functorch.eager_transforms._validate_and_wrap_argnum": UserFunctionVariable,
  262. "torch._functorch.eager_transforms._validate_and_wrap_argnums": UserFunctionVariable,
  263. "torch._functorch.eager_transforms._wrap_all_tensors": UserFunctionVariable,
  264. "torch._functorch.eager_transforms._wrap_tensor_for_grad": UserFunctionVariable,
  265. # functorch/jacrev
  266. "torch._functorch.eager_transforms.jacrev": FunctorchHigherOrderVariable,
  267. "torch._functorch.eager_transforms.error_if_complex": UserFunctionVariable,
  268. "torch._functorch.eager_transforms._chunked_standard_basis_for_": UserFunctionVariable,
  269. "torch._functorch.eager_transforms._safe_zero_index": UserFunctionVariable,
  270. # functorch/vjp
  271. "torch._functorch.eager_transforms.vjp": FunctorchHigherOrderVariable,
  272. "torch._functorch.eager_transforms._vjp_with_argnums": UserFunctionVariable,
  273. "torch._functorch.eager_transforms.assert_non_empty_tensor_output": UserFunctionVariable,
  274. # functorch/jvp
  275. "torch._functorch.eager_transforms._jvp_with_argnums": UserFunctionVariable,
  276. "torch._functorch.eager_transforms.jvp": FunctorchHigherOrderVariable,
  277. "torch._functorch.eager_transforms._replace_args": UserFunctionVariable,
  278. "torch._functorch.eager_transforms.safe_unpack_dual": UserFunctionVariable,
  279. "torch._functorch.eager_transforms.assert_non_empty_list_of_tensors": UserFunctionVariable,
  280. "torch._functorch.eager_transforms.assert_output_is_tensor_or_tensors": UserFunctionVariable,
  281. "torch.autograd.forward_ad.enter_dual_level": UserFunctionVariable,
  282. "torch.autograd.forward_ad.exit_dual_level": UserFunctionVariable,
  283. "torch.autograd.forward_ad.make_dual": UserFunctionVariable,
  284. "torch.autograd.forward_ad.unpack_dual": UserFunctionVariable,
  285. # functorch/linearize
  286. "torch._functorch.eager_transforms.linearize": FunctorchHigherOrderVariable,
  287. # functorch/jacfwd
  288. "torch._functorch.eager_transforms.jacfwd": FunctorchHigherOrderVariable,
  289. "torch._functorch.eager_transforms._construct_standard_basis_for": UserFunctionVariable,
  290. "torch._functorch.eager_transforms.safe_unflatten": UserFunctionVariable,
  291. # functorch/hessian
  292. "torch._functorch.eager_transforms.hessian": FunctorchHigherOrderVariable,
  293. # functional_call
  294. "torch._functorch.functional_call.functional_call": FunctionalCallVariable,
  295. "torch.nn.utils.stateless._groupby_tensor": TorchInGraphFunctionVariable,
  296. "torch.nn.utils.stateless._reparametrize_module": ReparametrizeModuleCallVariable,
  297. # functorch/deprecated
  298. "torch._functorch.deprecated.jvp": UserFunctionVariable,
  299. "torch._functorch.deprecated.hessian": UserFunctionVariable,
  300. "torch._functorch.deprecated.jacfwd": UserFunctionVariable,
  301. "torch._functorch.deprecated.jacrev": UserFunctionVariable,
  302. "torch._functorch.deprecated.grad": UserFunctionVariable,
  303. "torch._functorch.deprecated.grad_and_value": UserFunctionVariable,
  304. "torch._functorch.deprecated.vjp": UserFunctionVariable,
  305. # functorch/C++ bindings
  306. "torch._C._functorch._wrap_for_grad": TorchInGraphFunctionVariable,
  307. "torch._C._functorch._unwrap_for_grad": TorchInGraphFunctionVariable,
  308. "torch._C._functorch._unwrap_batched": TorchInGraphFunctionVariable,
  309. "torch._C._functorch.current_level": TorchInGraphFunctionVariable,
  310. "torch._C._functorch.maybe_current_level": TorchInGraphFunctionVariable,
  311. "torch._C._functorch.is_batchedtensor": TorchInGraphFunctionVariable,
  312. "torch._C._functorch.peek_interpreter_stack": TorchInGraphFunctionVariable,
  313. "torch._C._functorch.unwrap_if_dead": TorchInGraphFunctionVariable,
  314. "torch._functorch.predispatch._vmap_increment_nesting": TorchInGraphFunctionVariable,
  315. "torch._functorch.predispatch._vmap_decrement_nesting": TorchInGraphFunctionVariable,
  316. # everything else
  317. "torch._functorch.pyfunctorch.coerce_cinterpreter": TorchInGraphFunctionVariable,
  318. "torch._higher_order_ops.triton_kernel_wrap.do_prune_configs": UserFunctionVariable,
  319. "torch._higher_order_ops.foreach_map.foreach_map": UserFunctionVariable,
  320. "torch._constrain_as_size": UserFunctionVariable,
  321. "torch._tensor._convert": UserFunctionVariable,
  322. "torch.jit._unwrap_optional": UserFunctionVariable,
  323. "torch.backends.mha.get_fastpath_enabled": UserFunctionVariable,
  324. "torch._dynamo.dont_skip_tracing": UserFunctionVariable,
  325. "torch._dynamo.mark_static": UserFunctionVariable,
  326. "torch._dynamo.nonstrict_trace": UserFunctionVariable,
  327. "torch._dynamo.patch_dynamo_config": UserFunctionVariable,
  328. "torch._dynamo.error_on_graph_break": UserFunctionVariable,
  329. "torch.fx.experimental.symbolic_shapes.guard_size_oblivious": TorchInGraphFunctionVariable,
  330. "torch.fx.experimental.symbolic_shapes.guard_or_true": TorchInGraphFunctionVariable,
  331. "torch.fx.experimental.symbolic_shapes.guard_or_false": TorchInGraphFunctionVariable,
  332. "torch.fx.experimental.symbolic_shapes.statically_known_true": TorchInGraphFunctionVariable,
  333. "torch.fx.experimental.symbolic_shapes.statically_known_false": TorchInGraphFunctionVariable,
  334. "torch.fx.experimental.symbolic_shapes.sym_and": TorchInGraphFunctionVariable,
  335. "torch.fx.experimental.symbolic_shapes.sym_or": TorchInGraphFunctionVariable,
  336. "torch.fx.experimental.symbolic_shapes.guard_scalar": TorchInGraphFunctionVariable,
  337. "torch.fx.experimental.symbolic_shapes.has_static_value": TorchInGraphFunctionVariable,
  338. "torch.cuda._get_device_properties": TorchInGraphFunctionVariable,
  339. "torch.utils.hooks.BackwardHook": TorchInGraphFunctionVariable,
  340. "torch.set_default_device": UserFunctionVariable,
  341. "torch.sparse_bsc_tensor": SkipFunctionVariable,
  342. "torch.sparse_bsr_tensor": SkipFunctionVariable,
  343. "torch.sparse_csc_tensor": SkipFunctionVariable,
  344. "torch.sparse_csr_tensor": SkipFunctionVariable,
  345. "torch.sparse_compressed_tensor": SkipFunctionVariable,
  346. "torch._C._autograd._unsafe_set_version_counter": TorchInGraphFunctionVariable,
  347. "torch.xpu.get_rng_state": SkipFunctionVariable,
  348. "torch.xpu.set_rng_state": SkipFunctionVariable,
  349. # avoid skipping user defined modules in distributed unit tests
  350. "torch/testing/_internal/common_fsdp.py#forward": UserFunctionVariable,
  351. f"torch/testing/_internal/common_fsdp.py#{TORCH_DYNAMO_RESUME_IN_PREFIX}": UserFunctionVariable,
  352. "torch/testing/_internal/distributed/_tensor/common_dtensor.py#forward": UserFunctionVariable,
  353. f"torch/testing/_internal/distributed/_tensor/common_dtensor.py#{TORCH_DYNAMO_RESUME_IN_PREFIX}": UserFunctionVariable,
  354. "torch/testing/_internal/common_distributed.py#forward": UserFunctionVariable,
  355. f"torch/testing/_internal/common_distributed.py#{TORCH_DYNAMO_RESUME_IN_PREFIX}": UserFunctionVariable,
  356. }
  357. # In graph functions (including constant folding) that are C bindings
  358. torch_c_binding_in_graph_functions = dict.fromkeys(
  359. [
  360. "math.acos",
  361. "math.acosh",
  362. "math.asin",
  363. "math.asinh",
  364. "math.atan",
  365. "math.atan2",
  366. "math.atanh",
  367. "math.ceil",
  368. "math.comb",
  369. "math.copysign",
  370. "math.cos",
  371. "math.cosh",
  372. "math.degrees",
  373. "math.dist",
  374. "math.erf",
  375. "math.erfc",
  376. "math.exp",
  377. "math.expm1",
  378. "math.fabs",
  379. "math.factorial",
  380. "math.floor",
  381. "math.fmod",
  382. "math.frexp",
  383. "math.fsum",
  384. "math.gamma",
  385. "math.gcd",
  386. "math.hypot",
  387. "math.isclose",
  388. "math.isfinite",
  389. "math.isinf",
  390. "math.isnan",
  391. "math.isqrt",
  392. "math.lcm",
  393. "math.ldexp",
  394. "math.lgamma",
  395. "math.log",
  396. "math.log10",
  397. "math.log1p",
  398. "math.log2",
  399. "math.modf",
  400. "math.nextafter",
  401. "math.perm",
  402. "math.pow",
  403. "math.prod",
  404. "math.radians",
  405. "math.remainder",
  406. "math.sin",
  407. "math.sinh",
  408. "math.tan",
  409. "math.tanh",
  410. "math.trunc",
  411. "math.ulp",
  412. "torch._adaptive_avg_pool2d",
  413. "torch._adaptive_avg_pool3d",
  414. "torch._add_batch_dim",
  415. "torch._add_relu_",
  416. "torch._add_relu",
  417. "torch._addmm_activation",
  418. "torch._aminmax",
  419. "torch._amp_foreach_non_finite_check_and_unscale_",
  420. "torch._amp_update_scale_",
  421. "torch._assert_async",
  422. "torch._assert_tensor_metadata",
  423. "torch._batch_norm_impl_index",
  424. "torch._C._accelerator_getAccelerator",
  425. "torch._C._accelerator_getDeviceIndex",
  426. "torch._C._accelerator_getStream",
  427. "torch._C._accelerator_setStream",
  428. "torch._C._accelerator_synchronizeDevice",
  429. "torch._C._activate_gpu_trace",
  430. "torch._C._add_cached_tensor",
  431. "torch._C._add_docstr",
  432. "torch._C._are_functorch_transforms_active",
  433. "torch._C._autograd_init",
  434. "torch._C._awaitable_nowait",
  435. "torch._C._awaitable_wait",
  436. "torch._C._awaitable",
  437. "torch._C._backport_for_mobile_from_buffer_to_buffer",
  438. "torch._C._backport_for_mobile_from_buffer",
  439. "torch._C._backport_for_mobile_to_buffer",
  440. "torch._C._backport_for_mobile",
  441. "torch._C._broadcast_coalesced",
  442. "torch._C._broadcast_out",
  443. "torch._C._broadcast",
  444. "torch._C._c10d_init",
  445. "torch._C._calculate_package_version_based_on_upgraders",
  446. "torch._C._can_use_flash_attention",
  447. "torch._C._can_use_mem_efficient_attention",
  448. "torch._C._can_use_cudnn_attention",
  449. "torch._C._check_onnx_proto",
  450. "torch._C._check_sparse_tensor_invariants",
  451. "torch._C._collect_all",
  452. "torch._C._commit_update",
  453. "torch._C._compile_graph_to_code_table",
  454. "torch._C._construct_CUDA_Tensor_From_Storage_And_Metadata",
  455. "torch._C._construct_storage_from_data_pointer",
  456. "torch._C._conv_determine_backend_memory_format",
  457. "torch._C._cpu._is_avx2_supported",
  458. "torch._C._cpu._is_avx512_supported",
  459. "torch._C._cpu._is_avx512_vnni_supported",
  460. "torch._C._cpu._is_avx512_bf16_supported",
  461. "torch._C._cpu._is_amx_tile_supported",
  462. "torch._C._cpu._is_amx_fp16_supported",
  463. "torch._C._cpu._init_amx",
  464. "torch._C._crash_if_aten_asan",
  465. "torch._C._crash_if_csrc_asan",
  466. "torch._C._crash_if_csrc_ubsan",
  467. "torch._C._crash_if_debug_asserts_fail",
  468. "torch._C._crash_if_vptr_ubsan",
  469. "torch._C._create_function_from_graph",
  470. "torch._C._create_function_from_trace_with_dict",
  471. "torch._C._create_function_from_trace",
  472. "torch._C._create_graph_by_tracing",
  473. "torch._C._create_module_with_type",
  474. "torch._C._create_object_with_type",
  475. "torch._C._cuda_attach_out_of_memory_observer",
  476. "torch._C._cuda_beginAllocateCurrentStreamToPool",
  477. "torch._C._cuda_canDeviceAccessPeer",
  478. "torch._C._cuda_changeCurrentAllocator",
  479. "torch._C._cuda_checkPoolLiveAllocations",
  480. "torch._C._cuda_clearCublasWorkspaces",
  481. "torch._C._cuda_cudaCachingAllocator_raw_alloc",
  482. "torch._C._cuda_cudaCachingAllocator_raw_delete",
  483. "torch._C._cuda_cudaCachingAllocator_set_allocator_settings",
  484. "torch._C._cuda_cudaHostAllocator",
  485. "torch._C._cuda_customAllocator",
  486. "torch._C._cuda_emptyCache",
  487. "torch._C._cuda_endAllocateToPool",
  488. "torch._C._cuda_exchangeDevice",
  489. "torch._C._cuda_get_conv_benchmark_empty_cache",
  490. "torch._C._cuda_get_cudnn_benchmark_limit",
  491. "torch._C._cuda_get_sync_debug_mode",
  492. "torch._C._cuda_getAllocator",
  493. "torch._C._cuda_getAllocatorBackend",
  494. "torch._C._cuda_getArchFlags",
  495. "torch._C._cuda_getCheckpointState",
  496. "torch._C._cuda_getCompiledVersion",
  497. "torch._C._cuda_getCurrentBlasHandle",
  498. "torch._C._cuda_getCurrentRawStream",
  499. "torch._C._cuda_getCurrentStream",
  500. "torch._C._cuda_getDefaultStream",
  501. "torch._C._cuda_getDevice",
  502. "torch._C._cuda_getDeviceCount",
  503. "torch._C._cuda_hasPrimaryContext",
  504. "torch._C._cuda_hostMemoryStats",
  505. "torch._C._cuda_init",
  506. "torch._C._cuda_ipc_collect",
  507. "torch._C._cuda_isCurrentStreamCapturing",
  508. "torch._C._cuda_isHistoryEnabled",
  509. "torch._C._cuda_isInBadFork",
  510. "torch._C._cuda_jiterator_compile_and_launch_kernel",
  511. "torch._C._cuda_lock_mutex",
  512. "torch._C._cuda_maybeExchangeDevice",
  513. "torch._C._cuda_memorySnapshot",
  514. "torch._C._cuda_memoryStats",
  515. "torch._C._cuda_record_memory_history_legacy",
  516. "torch._C._cuda_record_memory_history",
  517. "torch._C._cuda_releasePool",
  518. "torch._C._cuda_resetAccumulatedHostMemoryStats",
  519. "torch._C._cuda_resetAccumulatedMemoryStats",
  520. "torch._C._cuda_resetPeakHostMemoryStats",
  521. "torch._C._cuda_resetPeakMemoryStats",
  522. "torch._C._cuda_set_cudnn_benchmark_limit",
  523. "torch._C._cuda_set_sync_debug_mode",
  524. "torch._C._cuda_setCheckpointPoolState",
  525. "torch._C._cuda_setDevice",
  526. "torch._C._cuda_setMemoryFraction",
  527. "torch._C._cuda_setStream",
  528. "torch._C._cuda_sleep",
  529. "torch._C._cuda_synchronize",
  530. "torch._C._cuda_unlock_mutex",
  531. "torch._C._cudnn_set_conv_benchmark_empty_cache",
  532. "torch._C._cudnn.getCompileVersion",
  533. "torch._C._cudnn.getRuntimeVersion",
  534. "torch._C._cudnn.getVersionInt",
  535. "torch._C._current_autograd_node",
  536. "torch._C._current_graph_task_execution_order",
  537. "torch._C._current_graph_task_id",
  538. "torch._C._cxx_flags",
  539. "torch._C._debug_get_fusion_group_inlining",
  540. "torch._C._debug_only_are_vmap_fallback_warnings_enabled",
  541. "torch._C._debug_only_display_vmap_fallback_warnings",
  542. "torch._C._debug_set_autodiff_subgraph_inlining",
  543. "torch._C._debug_set_fusion_group_inlining",
  544. "torch._C._demangle",
  545. "torch._C._disabled_torch_dispatch_impl",
  546. "torch._C._dispatch_call_boxed",
  547. "torch._C._dispatch_check_all_invariants",
  548. "torch._C._dispatch_check_invariants",
  549. "torch._C._dispatch_dump_table",
  550. "torch._C._dispatch_dump",
  551. "torch._C._dispatch_find_dangling_impls",
  552. "torch._C._dispatch_find_schema_or_throw",
  553. "torch._C._dispatch_get_all_op_names",
  554. "torch._C._dispatch_get_backend_keyset_from_autograd",
  555. "torch._C._dispatch_get_registrations_for_dispatch_key",
  556. "torch._C._dispatch_has_backend_fallback",
  557. "torch._C._dispatch_has_computed_kernel_for_dispatch_key",
  558. "torch._C._dispatch_has_kernel_for_any_dispatch_key",
  559. "torch._C._dispatch_has_kernel_for_dispatch_key",
  560. "torch._C._dispatch_has_kernel",
  561. "torch._C._dispatch_is_alias_key",
  562. "torch._C._dispatch_is_included_in_alias",
  563. "torch._C._dispatch_isTensorSubclassLike",
  564. "torch._C._dispatch_key_for_device",
  565. "torch._C._dispatch_key_name",
  566. "torch._C._dispatch_key_parse",
  567. "torch._C._dispatch_key_set",
  568. "torch._C._dispatch_keys",
  569. "torch._C._dispatch_keyset_full_after",
  570. "torch._C._dispatch_keyset_full",
  571. "torch._C._dispatch_keyset_to_string",
  572. "torch._C._dispatch_library",
  573. "torch._C._dispatch_num_backends",
  574. "torch._C._dispatch_print_registrations_for_dispatch_key",
  575. "torch._C._dispatch_pystub",
  576. "torch._C._dispatch_set_report_error_callback",
  577. "torch._C._dispatch_tls_is_dispatch_key_excluded",
  578. "torch._C._dispatch_tls_is_dispatch_key_included",
  579. "torch._C._dispatch_tls_local_exclude_set",
  580. "torch._C._dispatch_tls_local_include_set",
  581. "torch._C._dispatch_tls_set_dispatch_key_excluded",
  582. "torch._C._dispatch_tls_set_dispatch_key_included",
  583. "torch._C._dist_autograd_init",
  584. "torch._C._dump_local_tls_set",
  585. "torch._C._dump_upgraders_map",
  586. "torch._C._enable_mobile_interface_call_export",
  587. "torch._C._enter_dual_level",
  588. "torch._C._error_if_any_worker_fails",
  589. "torch._C._exit_dual_level",
  590. "torch._C._export_operator_list",
  591. "torch._C._export_opnames",
  592. "torch._C._faulty_agent_init",
  593. "torch._C._fft.fft_fft",
  594. "torch._C._fft.fft_fft2",
  595. "torch._C._fft.fft_fftfreq",
  596. "torch._C._fft.fft_fftn",
  597. "torch._C._fft.fft_fftshift",
  598. "torch._C._fft.fft_hfft",
  599. "torch._C._fft.fft_hfft2",
  600. "torch._C._fft.fft_hfftn",
  601. "torch._C._fft.fft_ifft",
  602. "torch._C._fft.fft_ifft2",
  603. "torch._C._fft.fft_ifftn",
  604. "torch._C._fft.fft_ifftshift",
  605. "torch._C._fft.fft_ihfft",
  606. "torch._C._fft.fft_ihfft2",
  607. "torch._C._fft.fft_ihfftn",
  608. "torch._C._fft.fft_irfft",
  609. "torch._C._fft.fft_irfft2",
  610. "torch._C._fft.fft_irfftn",
  611. "torch._C._fft.fft_rfft",
  612. "torch._C._fft.fft_rfft2",
  613. "torch._C._fft.fft_rfftfreq",
  614. "torch._C._fft.fft_rfftn",
  615. "torch._C._free_And_Remove_DeleterFn",
  616. "torch._C._freeze_module",
  617. "torch._C._from_dlpack",
  618. "torch._C._functionality_to_backend_keys",
  619. "torch._C._functionalization_reapply_views_tls",
  620. "torch._C._fuse_to_static_module",
  621. "torch._C._gather_out",
  622. "torch._C._gather",
  623. "torch._C._generate_upgraders_graph",
  624. "torch._C._get_autograd_fallback_mode",
  625. "torch._C._get_backcompat_broadcast_warn",
  626. "torch._C._get_backcompat_keepdim_warn",
  627. "torch._C._get_blas_preferred_backend",
  628. "torch._C._get_caught_jit_exception_class_name",
  629. "torch._C._get_caught_jit_exception_original_msg",
  630. "torch._C._get_constant_bool_symnode",
  631. "torch._C._get_cpp_backtrace",
  632. "torch._C._get_cpu_capability",
  633. "torch._C._get_cublas_allow_bf16_reduced_precision_reduction",
  634. "torch._C._get_cublas_allow_fp16_reduced_precision_reduction",
  635. "torch._C._get_cublas_allow_tf32",
  636. "torch._C._get_cudnn_allow_tf32",
  637. "torch._C._get_cudnn_benchmark",
  638. "torch._C._get_miopen_immediate",
  639. "torch._C._get_cudnn_deterministic",
  640. "torch._C._get_cudnn_enabled",
  641. "torch._C._get_custom_class_python_wrapper",
  642. "torch._C._get_default_device",
  643. "torch._C._get_deterministic_algorithms_warn_only",
  644. "torch._C._get_deterministic_algorithms",
  645. "torch._C._get_deterministic_fill_uninitialized_memory",
  646. "torch._C._get_dispatch_mode",
  647. "torch._C._get_dispatch_stack_at",
  648. "torch._C._get_file_format",
  649. "torch._C._get_flash_sdp_enabled",
  650. "torch._C._get_float32_matmul_precision",
  651. "torch._C._get_function_stack_at",
  652. "torch._C._get_graph_executor_optimize",
  653. "torch._C._get_linalg_preferred_backend",
  654. "torch._C._get_rocm_fa_preferred_backend",
  655. "torch._C._get_math_sdp_enabled",
  656. "torch._C._get_math_sdp_allow_fp16_bf16_reduction",
  657. "torch._C._get_max_operator_version",
  658. "torch._C._get_mem_efficient_sdp_enabled",
  659. "torch._C._get_mkldnn_enabled",
  660. "torch._C._get_cudnn_sdp_enabled",
  661. "torch._C._set_sdp_use_cudnn",
  662. "torch._C._get_mobile_model_contained_types_from_buffer",
  663. "torch._C._get_mobile_model_contained_types",
  664. "torch._C._get_model_bytecode_version_from_buffer",
  665. "torch._C._get_model_bytecode_version",
  666. "torch._C._get_model_extra_files_from_buffer",
  667. "torch._C._get_model_extra_files",
  668. "torch._C._get_model_ops_and_info_from_buffer",
  669. "torch._C._get_model_ops_and_info",
  670. "torch._C._get_module_info_from_flatbuffer",
  671. "torch._C._get_nnpack_enabled",
  672. "torch._C._get_obj_in_tls",
  673. "torch._C._get_operation_overload",
  674. "torch._C._get_operator_version_map",
  675. "torch._C._get_privateuse1_backend_name",
  676. "torch._C._get_qengine",
  677. "torch._C._get_schema",
  678. "torch._C._get_sm_carveout_experimental",
  679. "torch._C._get_nested_int",
  680. "torch._C._get_tensor_metadata",
  681. "torch._C._get_tracing_state",
  682. "torch._C._get_upgrader_ranges",
  683. "torch._C._get_upgraders_entry_map",
  684. "torch._C._get_upgraders_map_size",
  685. "torch._C._get_value_trace",
  686. "torch._C._get_version_calculator_flag",
  687. "torch._C._get_warnAlways",
  688. "torch._C._graph_pool_handle",
  689. "torch._C._group_tensors_by_device_and_dtype",
  690. "torch._C._hack_do_not_use_clone_module_with_class",
  691. "torch._C._has_distributed",
  692. "torch._C._has_Standard_Deleter",
  693. "torch._C._has_storage",
  694. "torch._C._has_tensorexpr_cpp_tests",
  695. "torch._C._run_tensorexpr_cpp_tests",
  696. "torch._C._has_torch_function_unary",
  697. "torch._C._has_torch_function_variadic",
  698. "torch._C._has_torch_function",
  699. "torch._C._import_ir_module_from_package",
  700. "torch._C._increment_version",
  701. "torch._C._infer_size",
  702. "torch._C._init_names",
  703. "torch._C._initExtension",
  704. "torch._C._is_alias_of",
  705. "torch._C._is_any_autocast_enabled",
  706. "torch._C._is_cached_tensor",
  707. "torch._C._is_flash_attention_available",
  708. "torch._C._is_fwd_grad_enabled",
  709. "torch._C._is_key_in_tls",
  710. "torch._C._is_multithreading_enabled",
  711. "torch._C._is_torch_function_enabled",
  712. "torch._C._is_torch_function_mode_enabled",
  713. "torch._C._is_torch_function_all_disabled",
  714. "torch._C._is_tracing",
  715. "torch._C._is_view_replay_enabled",
  716. "torch._C._is_xnnpack_enabled",
  717. "torch._C._itt.is_available",
  718. "torch._C._itt.mark",
  719. "torch._C._itt.rangePop",
  720. "torch._C._itt.rangePush",
  721. "torch._C._ivalue_debug_python_object",
  722. "torch._C._ivalue_tags_match",
  723. "torch._C._jit_assert_is_instance",
  724. "torch._C._jit_can_fuse_on_cpu_legacy",
  725. "torch._C._jit_can_fuse_on_cpu",
  726. "torch._C._jit_can_fuse_on_gpu",
  727. "torch._C._jit_cat_wo_conditionals",
  728. "torch._C._jit_check_alias_annotation",
  729. "torch._C._jit_clear_class_registry",
  730. "torch._C._jit_debug_fuser_num_cached_kernel_specs",
  731. "torch._C._jit_debug_module_iterators",
  732. "torch._C._jit_decay_packed_param_input_types",
  733. "torch._C._jit_decomposition_graph_for_node",
  734. "torch._C._jit_differentiate",
  735. "torch._C._jit_erase_non_input_shape_information",
  736. "torch._C._jit_flatten",
  737. "torch._C._jit_fuser_get_fused_kernel_code",
  738. "torch._C._jit_get_all_schemas",
  739. "torch._C._jit_get_custom_class_schemas",
  740. "torch._C._jit_get_emit_hooks",
  741. "torch._C._jit_get_inline_everything_mode",
  742. "torch._C._jit_get_logging_option",
  743. "torch._C._jit_get_num_profiled_runs",
  744. "torch._C._jit_get_operation",
  745. "torch._C._jit_get_schemas_for_operator",
  746. "torch._C._jit_get_te_cuda_pointwise_block_count",
  747. "torch._C._jit_get_te_cuda_pointwise_block_size",
  748. "torch._C._jit_get_te_cuda_pointwise_loop_levels",
  749. "torch._C._jit_get_te_generate_block_code",
  750. "torch._C._jit_get_te_must_use_llvm_cpu",
  751. "torch._C._jit_get_tracer_state_warn",
  752. "torch._C._jit_has_cpp_tests",
  753. "torch._C._jit_init",
  754. "torch._C._jit_interpret_graph",
  755. "torch._C._jit_is_onnx_log_enabled",
  756. "torch._C._jit_is_script_object",
  757. "torch._C._jit_llga_enabled",
  758. "torch._C._jit_nvfuser_can_be_enabled",
  759. "torch._C._jit_nvfuser_clear_comparison_callback",
  760. "torch._C._jit_nvfuser_enabled",
  761. "torch._C._jit_nvfuser_horizontal_mode",
  762. "torch._C._jit_nvfuser_set_comparison_callback",
  763. "torch._C._jit_nvfuser_single_node_mode",
  764. "torch._C._jit_object_is_non_holding",
  765. "torch._C._jit_onnx_convert_pattern_from_subblock",
  766. "torch._C._jit_onnx_create_full_scope_name",
  767. "torch._C._jit_onnx_list_model_parameters",
  768. "torch._C._jit_onnx_log",
  769. "torch._C._jit_opt_conditionals",
  770. "torch._C._jit_override_can_fuse_on_cpu_legacy",
  771. "torch._C._jit_override_can_fuse_on_cpu",
  772. "torch._C._jit_override_can_fuse_on_gpu",
  773. "torch._C._jit_pass_autocast",
  774. "torch._C._jit_pass_batch_mm",
  775. "torch._C._jit_pass_canonicalize_graph_fuser_ops",
  776. "torch._C._jit_pass_canonicalize",
  777. "torch._C._jit_pass_complete_shape_analysis",
  778. "torch._C._jit_pass_concat_frozen_linear",
  779. "torch._C._jit_pass_constant_loop_unrolling",
  780. "torch._C._jit_pass_constant_pooling",
  781. "torch._C._jit_pass_constant_propagation_immutable_types",
  782. "torch._C._jit_pass_constant_propagation",
  783. "torch._C._jit_pass_convert_frozen_ops_to_mkldnn",
  784. "torch._C._jit_pass_create_autodiff_subgraphs",
  785. "torch._C._jit_pass_create_functional_graphs",
  786. "torch._C._jit_pass_cse",
  787. "torch._C._jit_pass_custom_pattern_based_rewrite_graph",
  788. "torch._C._jit_pass_custom_pattern_based_rewrite",
  789. "torch._C._jit_pass_dbr_quant_remove_redundant_aliases",
  790. "torch._C._jit_pass_dce_allow_deleting_nodes_with_side_effects",
  791. "torch._C._jit_pass_dce",
  792. "torch._C._jit_pass_decompose_ops",
  793. "torch._C._jit_pass_dedup_module_uses",
  794. "torch._C._jit_pass_erase_number_types",
  795. "torch._C._jit_pass_erase_shape_information",
  796. "torch._C._jit_pass_filter_non_tensor_arguments",
  797. "torch._C._jit_pass_fixup_onnx_controlflow_node",
  798. "torch._C._jit_pass_fold_convbn",
  799. "torch._C._jit_pass_fold_frozen_conv_add_or_sub",
  800. "torch._C._jit_pass_fold_frozen_conv_bn",
  801. "torch._C._jit_pass_fold_frozen_conv_mul_or_div",
  802. "torch._C._jit_pass_fold_frozen_linear_bn",
  803. "torch._C._jit_pass_fold_prepacking_ops",
  804. "torch._C._jit_pass_functional_to_inplace_activation",
  805. "torch._C._jit_pass_fuse_add_relu",
  806. "torch._C._jit_pass_fuse_addmm",
  807. "torch._C._jit_pass_fuse_clamp_w_prepacked_linear_conv",
  808. "torch._C._jit_pass_fuse_frozen_conv_add_relu",
  809. "torch._C._jit_pass_fuse_linear",
  810. "torch._C._jit_pass_fuse_quantized_add_relu",
  811. "torch._C._jit_pass_fuse_tensorexprs",
  812. "torch._C._jit_pass_fuse",
  813. "torch._C._jit_pass_inline_fork_wait",
  814. "torch._C._jit_pass_inline_functional_graphs",
  815. "torch._C._jit_pass_inline",
  816. "torch._C._jit_pass_inplace_to_functional_activation",
  817. "torch._C._jit_pass_insert_observer_method_for_ondevice_ptq",
  818. "torch._C._jit_pass_insert_observers",
  819. "torch._C._jit_pass_insert_prepack_unpack",
  820. "torch._C._jit_pass_insert_prepacked_ops",
  821. "torch._C._jit_pass_insert_quant_dequant_for_ondevice_ptq",
  822. "torch._C._jit_pass_insert_quant_dequant",
  823. "torch._C._jit_pass_integer_value_refinement",
  824. "torch._C._jit_pass_lint",
  825. "torch._C._jit_pass_loop_unrolling",
  826. "torch._C._jit_pass_lower_all_tuples",
  827. "torch._C._jit_pass_lower_graph",
  828. "torch._C._jit_pass_metal_fold_prepacking_ops",
  829. "torch._C._jit_pass_metal_fuse_clamp_w_prepacked_conv",
  830. "torch._C._jit_pass_metal_insert_prepacked_ops",
  831. "torch._C._jit_pass_metal_optimize_for_mobile",
  832. "torch._C._jit_pass_onnx_assign_output_shape",
  833. "torch._C._jit_pass_onnx_assign_scoped_names_for_node_and_value",
  834. "torch._C._jit_pass_onnx_autograd_function_process",
  835. "torch._C._jit_pass_onnx_block",
  836. "torch._C._jit_pass_onnx_cast_all_constant_to_floating",
  837. "torch._C._jit_pass_onnx_clear_scope_records",
  838. "torch._C._jit_pass_onnx_constant_fold",
  839. "torch._C._jit_pass_onnx_deduplicate_initializers",
  840. "torch._C._jit_pass_onnx_eliminate_unused_items",
  841. "torch._C._jit_pass_onnx_eval_peephole",
  842. "torch._C._jit_pass_onnx_function_extraction",
  843. "torch._C._jit_pass_onnx_function_substitution",
  844. "torch._C._jit_pass_onnx_graph_shape_type_inference",
  845. "torch._C._jit_pass_onnx_lint",
  846. "torch._C._jit_pass_onnx_node_shape_type_inference",
  847. "torch._C._jit_pass_onnx_peephole",
  848. "torch._C._jit_pass_onnx_preprocess_caffe2",
  849. "torch._C._jit_pass_onnx_preprocess",
  850. "torch._C._jit_pass_onnx_quantization_insert_permutes",
  851. "torch._C._jit_pass_onnx_remove_inplace_ops_for_onnx",
  852. "torch._C._jit_pass_onnx_remove_print",
  853. "torch._C._jit_pass_onnx_scalar_type_analysis",
  854. "torch._C._jit_pass_onnx_set_dynamic_input_shape",
  855. "torch._C._jit_pass_onnx_track_scope_attributes",
  856. "torch._C._jit_pass_onnx_unpack_quantized_weights",
  857. "torch._C._jit_pass_onnx",
  858. "torch._C._jit_pass_optimize_for_inference",
  859. "torch._C._jit_pass_optimize_for_mobile",
  860. "torch._C._jit_pass_optimize_frozen_graph",
  861. "torch._C._jit_pass_pattern_based_rewrite",
  862. "torch._C._jit_pass_peephole_list_idioms",
  863. "torch._C._jit_pass_peephole",
  864. "torch._C._jit_pass_prepare_division_for_onnx",
  865. "torch._C._jit_pass_propagate_device",
  866. "torch._C._jit_pass_propagate_dtype",
  867. "torch._C._jit_pass_propagate_shapes_on_graph_and_build_compute",
  868. "torch._C._jit_pass_propagate_shapes_on_graph",
  869. "torch._C._jit_pass_quant_finalize_for_ondevice_ptq",
  870. "torch._C._jit_pass_quant_finalize",
  871. "torch._C._jit_pass_quant_fusion",
  872. "torch._C._jit_pass_refine_integer_values",
  873. "torch._C._jit_pass_refine_tuple_types",
  874. "torch._C._jit_pass_remove_dropout",
  875. "torch._C._jit_pass_remove_expands",
  876. "torch._C._jit_pass_remove_inplace_ops",
  877. "torch._C._jit_pass_remove_mutation",
  878. "torch._C._jit_pass_replace_old_ops_with_upgraders",
  879. "torch._C._jit_pass_replicate_dequantize",
  880. "torch._C._jit_pass_run_decompositions",
  881. "torch._C._jit_pass_specialize_autogradzero",
  882. "torch._C._jit_pass_swap_functional_linear",
  883. "torch._C._jit_pass_transform_conv1d_to_conv2d",
  884. "torch._C._jit_pass_transpose_frozen_linear",
  885. "torch._C._jit_pass_vulkan_fold_prepacking_ops",
  886. "torch._C._jit_pass_vulkan_fuse_clamp_w_prepacked_conv",
  887. "torch._C._jit_pass_vulkan_insert_prepacked_ops",
  888. "torch._C._jit_pass_vulkan_optimize_for_mobile",
  889. "torch._C._jit_register_decomposition_for_schema",
  890. "torch._C._jit_register_shape_compute_graph_for_node",
  891. "torch._C._jit_resolve_packet",
  892. "torch._C._jit_run_cpp_tests",
  893. "torch._C._jit_script_class_compile",
  894. "torch._C._jit_script_compile_overload",
  895. "torch._C._jit_script_compile",
  896. "torch._C._jit_script_interface_compile",
  897. "torch._C._jit_set_autocast_mode",
  898. "torch._C._jit_set_bailout_depth",
  899. "torch._C._jit_set_emit_hooks",
  900. "torch._C._jit_set_fusion_strategy",
  901. "torch._C._jit_set_inline_everything_mode",
  902. "torch._C._jit_set_llga_enabled",
  903. "torch._C._jit_set_logging_option",
  904. "torch._C._jit_set_logging_stream",
  905. "torch._C._jit_set_num_profiled_runs",
  906. "torch._C._jit_set_nvfuser_enabled",
  907. "torch._C._jit_set_nvfuser_guard_mode",
  908. "torch._C._jit_set_nvfuser_horizontal_mode",
  909. "torch._C._jit_set_nvfuser_single_node_mode",
  910. "torch._C._jit_set_nvfuser_skip_node_kind",
  911. "torch._C._jit_set_onnx_log_enabled",
  912. "torch._C._jit_set_onnx_log_output_stream",
  913. "torch._C._jit_set_profiling_executor",
  914. "torch._C._jit_set_profiling_mode",
  915. "torch._C._jit_set_symbolic_shapes_test_mode",
  916. "torch._C._jit_set_te_cuda_pointwise_block_count",
  917. "torch._C._jit_set_te_cuda_pointwise_block_size",
  918. "torch._C._jit_set_te_cuda_pointwise_loop_levels",
  919. "torch._C._jit_set_te_generate_block_code",
  920. "torch._C._jit_set_te_must_use_llvm_cpu",
  921. "torch._C._jit_set_texpr_dynamic_shape_enabled",
  922. "torch._C._jit_set_texpr_fuser_enabled",
  923. "torch._C._jit_set_texpr_reductions_enabled",
  924. "torch._C._jit_set_tracer_state_warn",
  925. "torch._C._jit_set_utf8_decoding_ignore",
  926. "torch._C._jit_shape_compute_graph_for_node",
  927. "torch._C._jit_symbolic_shapes_test_mode_enabled",
  928. "torch._C._jit_texpr_dynamic_shape_enabled",
  929. "torch._C._jit_texpr_fallback_allowed",
  930. "torch._C._jit_texpr_fuser_enabled",
  931. "torch._C._jit_texpr_reductions_enabled",
  932. "torch._C._jit_texpr_set_fallback_allowed",
  933. "torch._C._jit_to_backend_selective",
  934. "torch._C._jit_to_backend",
  935. "torch._C._jit_to_static_module",
  936. "torch._C._jit_trace_graph",
  937. "torch._C._jit_trace_module",
  938. "torch._C._jit_tree_views.FalseLiteral",
  939. "torch._C._jit_tree_views.NoneLiteral",
  940. "torch._C._jit_tree_views.TrueLiteral",
  941. "torch._C._jit_try_infer_type",
  942. "torch._C._jit_unflatten",
  943. "torch._C._last_executed_optimized_graph",
  944. "torch._C._len_torch_dispatch_stack",
  945. "torch._C._len_torch_function_stack",
  946. "torch._C._linalg._linalg_eigvals",
  947. "torch._C._linalg.linalg_cholesky_ex",
  948. "torch._C._linalg.linalg_cholesky",
  949. "torch._C._linalg.linalg_cond",
  950. "torch._C._linalg.linalg_cross",
  951. "torch._C._linalg.linalg_det",
  952. "torch._C._linalg.linalg_diagonal",
  953. "torch._C._linalg.linalg_eig",
  954. "torch._C._linalg.linalg_eigh",
  955. "torch._C._linalg.linalg_eigvals",
  956. "torch._C._linalg.linalg_eigvalsh",
  957. "torch._C._linalg.linalg_householder_product",
  958. "torch._C._linalg.linalg_inv_ex",
  959. "torch._C._linalg.linalg_inv",
  960. "torch._C._linalg.linalg_ldl_factor_ex",
  961. "torch._C._linalg.linalg_ldl_factor",
  962. "torch._C._linalg.linalg_ldl_solve",
  963. "torch._C._linalg.linalg_lstsq",
  964. "torch._C._linalg.linalg_lu_factor_ex",
  965. "torch._C._linalg.linalg_lu_factor",
  966. "torch._C._linalg.linalg_lu_solve",
  967. "torch._C._linalg.linalg_lu",
  968. "torch._C._linalg.linalg_matmul",
  969. "torch._C._linalg.linalg_matrix_exp",
  970. "torch._C._linalg.linalg_matrix_norm",
  971. "torch._C._linalg.linalg_matrix_power",
  972. "torch._C._linalg.linalg_matrix_rank",
  973. "torch._C._linalg.linalg_multi_dot",
  974. "torch._C._linalg.linalg_norm",
  975. "torch._C._linalg.linalg_pinv",
  976. "torch._C._linalg.linalg_qr",
  977. "torch._C._linalg.linalg_slogdet",
  978. "torch._C._linalg.linalg_solve_ex",
  979. "torch._C._linalg.linalg_solve_triangular",
  980. "torch._C._linalg.linalg_solve",
  981. "torch._C._linalg.linalg_svd",
  982. "torch._C._linalg.linalg_svdvals",
  983. "torch._C._linalg.linalg_tensorinv",
  984. "torch._C._linalg.linalg_tensorsolve",
  985. "torch._C._linalg.linalg_vander",
  986. "torch._C._linalg.linalg_vecdot",
  987. "torch._C._linalg.linalg_vector_norm",
  988. "torch._C._llvm_enabled",
  989. "torch._C._load_for_lite_interpreter_from_buffer",
  990. "torch._C._load_for_lite_interpreter",
  991. "torch._C._load_jit_module_from_bytes",
  992. "torch._C._load_jit_module_from_file",
  993. "torch._C._load_mobile_module_from_bytes",
  994. "torch._C._load_mobile_module_from_file",
  995. "torch._C._log_api_usage_metadata",
  996. "torch._C._log_api_usage_once",
  997. "torch._C._logging_set_logger",
  998. "torch._C._meta_in_tls_dispatch_include",
  999. "torch._C._mps_acquireEvent",
  1000. "torch._C._mps_currentAllocatedMemory",
  1001. "torch._C._mps_deviceSynchronize",
  1002. "torch._C._mps_driverAllocatedMemory",
  1003. "torch._C._mps_recommendedMaxMemory",
  1004. "torch._C._mps_elapsedTimeOfEvents",
  1005. "torch._C._mps_emptyCache",
  1006. "torch._C._mps_get_default_generator",
  1007. "torch._C._mps_is_available",
  1008. "torch._C._mps_is_in_bad_fork",
  1009. "torch._C._mps_is_on_macos_13_or_newer",
  1010. "torch._C._mps_profilerStartTrace",
  1011. "torch._C._mps_profilerStopTrace",
  1012. "torch._C._mps_queryEvent",
  1013. "torch._C._mps_recordEvent",
  1014. "torch._C._mps_releaseEvent",
  1015. "torch._C._mps_setMemoryFraction",
  1016. "torch._C._mps_synchronizeEvent",
  1017. "torch._C._mps_waitForEvent",
  1018. "torch._C._multiprocessing_init",
  1019. "torch._C._nccl_all_gather",
  1020. "torch._C._nccl_all_reduce",
  1021. "torch._C._nccl_broadcast",
  1022. "torch._C._nccl_init_rank",
  1023. "torch._C._nccl_reduce_scatter",
  1024. "torch._C._nccl_reduce",
  1025. "torch._C._nccl_unique_id",
  1026. "torch._C._nccl_version_suffix",
  1027. "torch._C._nccl_version",
  1028. "torch._C._nested.nested_tensor",
  1029. "torch._C._nested.nested_to_padded_tensor",
  1030. "torch._C._new_symbolic_shape_symbol",
  1031. "torch._C._nn_module_to_mobile",
  1032. "torch._C._nn._conv_depthwise2d",
  1033. "torch._C._nn._pad_circular",
  1034. "torch._C._nn._pad_enum",
  1035. "torch._C._nn._parse_to",
  1036. "torch._C._nn._test_ambiguous_defaults",
  1037. "torch._C._nn._test_optional_filled_intlist",
  1038. "torch._C._nn._test_optional_floatlist",
  1039. "torch._C._nn._test_optional_intlist",
  1040. "torch._C._nn._test_string_default",
  1041. "torch._C._nn._test_warn_in_autograd",
  1042. "torch._C._nn._upsample_bicubic2d_aa",
  1043. "torch._C._nn._upsample_bilinear2d_aa",
  1044. "torch._C._nn._upsample_nearest_exact1d",
  1045. "torch._C._nn._upsample_nearest_exact2d",
  1046. "torch._C._nn._upsample_nearest_exact3d",
  1047. "torch._C._nn.adaptive_avg_pool2d",
  1048. "torch._C._nn.adaptive_avg_pool3d",
  1049. "torch._C._nn.adaptive_max_pool2d",
  1050. "torch._C._nn.adaptive_max_pool3d",
  1051. "torch._C._nn.avg_pool2d",
  1052. "torch._C._nn.avg_pool3d",
  1053. "torch._C._nn.binary_cross_entropy",
  1054. "torch._C._nn.col2im",
  1055. "torch._C._nn.conv_depthwise3d",
  1056. "torch._C._nn.cross_entropy_loss",
  1057. "torch._C._nn.elu_",
  1058. "torch._C._nn.elu",
  1059. "torch._C._nn.flatten_dense_tensors",
  1060. "torch._C._nn.fractional_max_pool2d",
  1061. "torch._C._nn.fractional_max_pool3d",
  1062. "torch._C._nn.gelu_",
  1063. "torch._C._nn.gelu",
  1064. "torch._C._nn.glu",
  1065. "torch._C._nn.hardsigmoid_",
  1066. "torch._C._nn.hardsigmoid",
  1067. "torch._C._nn.hardswish_",
  1068. "torch._C._nn.hardswish",
  1069. "torch._C._nn.hardtanh_",
  1070. "torch._C._nn.hardtanh",
  1071. "torch._C._nn.huber_loss",
  1072. "torch._C._nn.im2col",
  1073. "torch._C._nn.l1_loss",
  1074. "torch._C._nn.leaky_relu_",
  1075. "torch._C._nn.leaky_relu",
  1076. "torch._C._nn.linear",
  1077. "torch._C._nn.log_sigmoid",
  1078. "torch._C._nn.max_pool2d_with_indices",
  1079. "torch._C._nn.max_pool3d_with_indices",
  1080. "torch._C._nn.max_unpool2d",
  1081. "torch._C._nn.max_unpool3d",
  1082. "torch._C._nn.mish_",
  1083. "torch._C._nn.mish",
  1084. "torch._C._nn.mkldnn_linear",
  1085. "torch._C._nn.mkldnn_reorder_conv2d_weight",
  1086. "torch._C._nn.mkldnn_reorder_conv3d_weight",
  1087. "torch._C._nn.mse_loss",
  1088. "torch._C._nn.multi_margin_loss",
  1089. "torch._C._nn.multilabel_margin_loss",
  1090. "torch._C._nn.nll_loss_nd",
  1091. "torch._C._nn.nll_loss",
  1092. "torch._C._nn.nll_loss2d",
  1093. "torch._C._nn.one_hot",
  1094. "torch._C._nn.pad_sequence",
  1095. "torch._C._nn.pad",
  1096. "torch._C._nn.reflection_pad1d",
  1097. "torch._C._nn.reflection_pad2d",
  1098. "torch._C._nn.reflection_pad3d",
  1099. "torch._C._nn.relu6_",
  1100. "torch._C._nn.relu6",
  1101. "torch._C._nn.replication_pad1d",
  1102. "torch._C._nn.replication_pad2d",
  1103. "torch._C._nn.replication_pad3d",
  1104. "torch._C._nn.rrelu_with_noise_",
  1105. "torch._C._nn.rrelu_with_noise",
  1106. "torch._C._nn.scaled_dot_product_attention",
  1107. "torch._C._nn.silu_",
  1108. "torch._C._nn.silu",
  1109. "torch._C._nn.slow_conv_dilated2d",
  1110. "torch._C._nn.slow_conv_dilated3d",
  1111. "torch._C._nn.slow_conv_transpose2d",
  1112. "torch._C._nn.slow_conv_transpose3d",
  1113. "torch._C._nn.slow_conv3d",
  1114. "torch._C._nn.smooth_l1_loss",
  1115. "torch._C._nn.soft_margin_loss",
  1116. "torch._C._nn.softplus",
  1117. "torch._C._nn.softshrink",
  1118. "torch._C._nn.thnn_conv2d",
  1119. "torch._C._nn.unflatten_dense_tensors",
  1120. "torch._C._nn.upsample_bicubic2d",
  1121. "torch._C._nn.upsample_bilinear2d",
  1122. "torch._C._nn.upsample_linear1d",
  1123. "torch._C._nn.upsample_nearest1d",
  1124. "torch._C._nn.upsample_nearest2d",
  1125. "torch._C._nn.upsample_nearest3d",
  1126. "torch._C._nn.upsample_trilinear3d",
  1127. "torch._C._non_sym_sizes",
  1128. "torch._C._overlaps",
  1129. "torch._C._parallel_info",
  1130. "torch._C._parse_dispatch_key",
  1131. "torch._C._parse_source_def",
  1132. "torch._C._pop_torch_dispatch_stack",
  1133. "torch._C._pop_torch_function_stack",
  1134. "torch._C._propagate_and_assign_input_shapes",
  1135. "torch._C._propagate_shapes",
  1136. "torch._C._propagate_xla_data",
  1137. "torch._C._push_on_torch_dispatch_stack",
  1138. "torch._C._push_on_torch_function_stack",
  1139. "torch._C._quantize_ondevice_ptq_dynamic",
  1140. "torch._C._register_py_class_for_device",
  1141. "torch._C._remove_cached_tensor",
  1142. "torch._C._remove_worker_pids",
  1143. "torch._C._rename_privateuse1_backend",
  1144. "torch._C._replace_",
  1145. "torch._C._replace_overloaded_method_decl",
  1146. "torch._C._resolve_type_from_object",
  1147. "torch._C._resolve_type",
  1148. "torch._C._rocm_is_backward_pass",
  1149. "torch._C._rpc_init",
  1150. "torch._C._run_emit_module_hook",
  1151. "torch._C._save_jit_module_to_bytes",
  1152. "torch._C._save_jit_module",
  1153. "torch._C._save_mobile_module_to_bytes",
  1154. "torch._C._save_mobile_module",
  1155. "torch._C._save_parameters",
  1156. "torch._C._scatter_out",
  1157. "torch._C._scatter",
  1158. "torch._C._select_conv_backend",
  1159. "torch._C._select_batch_norm_backend",
  1160. "torch._C._set_autograd_fallback_mode",
  1161. "torch._C._set_backcompat_broadcast_warn",
  1162. "torch._C._set_backcompat_keepdim_warn",
  1163. "torch._C._set_blas_preferred_backend",
  1164. "torch._C._set_cached_tensors_enabled",
  1165. "torch._C._set_check_sparse_tensor_invariants",
  1166. "torch._C._set_conj",
  1167. "torch._C._set_cublas_allow_bf16_reduced_precision_reduction",
  1168. "torch._C._set_cublas_allow_fp16_reduced_precision_reduction",
  1169. "torch._C._set_cublas_allow_tf32",
  1170. "torch._C._set_cudnn_allow_tf32",
  1171. "torch._C._set_cudnn_benchmark",
  1172. "torch._C._set_cudnn_deterministic",
  1173. "torch._C._set_cudnn_enabled",
  1174. "torch._C._set_default_dtype",
  1175. "torch._C._set_default_mobile_cpu_allocator",
  1176. "torch._C._set_default_tensor_type",
  1177. "torch._C._set_deterministic_algorithms",
  1178. "torch._C._set_deterministic_fill_uninitialized_memory",
  1179. "torch._C._set_dispatch_mode",
  1180. "torch._C._set_float32_matmul_precision",
  1181. "torch._C._set_fwd_grad_enabled",
  1182. "torch._C._set_grad_enabled",
  1183. "torch._C._set_graph_executor_optimize",
  1184. "torch._C._set_linalg_preferred_backend",
  1185. "torch._C._set_rocm_fa_preferred_backend",
  1186. "torch._C._set_meta_in_tls_dispatch_include",
  1187. "torch._C._set_mkldnn_enabled",
  1188. "torch._C._set_multithreading_enabled",
  1189. "torch._C._set_neg",
  1190. "torch._C._set_nnpack_enabled",
  1191. "torch._C._set_print_stack_traces_on_fatal_signal",
  1192. "torch._C._set_qengine",
  1193. "torch._C._set_sdp_use_flash",
  1194. "torch._C._set_sdp_use_math",
  1195. "torch._C._set_math_sdp_allow_fp16_bf16_reduction",
  1196. "torch._C._set_sdp_use_mem_efficient",
  1197. "torch._C._set_should_use_format_with_string_table",
  1198. "torch._C._set_sm_carveout_experimental",
  1199. "torch._C._set_storage_access_error_msg",
  1200. "torch._C._set_tensor_metadata",
  1201. "torch._C._set_tracing_state",
  1202. "torch._C._set_value_trace",
  1203. "torch._C._set_view_replay_enabled",
  1204. "torch._C._set_warnAlways",
  1205. "torch._C._set_worker_pids",
  1206. "torch._C._set_worker_signal_handlers",
  1207. "torch._C._should_allow_numbers_as_tensors",
  1208. "torch._C._show_config",
  1209. "torch._C._sparse._sparse_addmm",
  1210. "torch._C._sparse._sparse_log_softmax",
  1211. "torch._C._sparse._sparse_mm_reduce_impl",
  1212. "torch._C._sparse._sparse_mm",
  1213. "torch._C._sparse._sparse_softmax",
  1214. "torch._C._sparse._spdiags",
  1215. "torch._C._sparse.sparse_sampled_addmm",
  1216. "torch._C._special.special_airy_ai",
  1217. "torch._C._special.special_bessel_j0",
  1218. "torch._C._special.special_bessel_j1",
  1219. "torch._C._special.special_bessel_y0",
  1220. "torch._C._special.special_bessel_y1",
  1221. "torch._C._special.special_chebyshev_polynomial_t",
  1222. "torch._C._special.special_chebyshev_polynomial_u",
  1223. "torch._C._special.special_chebyshev_polynomial_v",
  1224. "torch._C._special.special_chebyshev_polynomial_w",
  1225. "torch._C._special.special_digamma",
  1226. "torch._C._special.special_entr",
  1227. "torch._C._special.special_erf",
  1228. "torch._C._special.special_erfc",
  1229. "torch._C._special.special_erfcx",
  1230. "torch._C._special.special_erfinv",
  1231. "torch._C._special.special_exp2",
  1232. "torch._C._special.special_expit",
  1233. "torch._C._special.special_expm1",
  1234. "torch._C._special.special_gammainc",
  1235. "torch._C._special.special_gammaincc",
  1236. "torch._C._special.special_gammaln",
  1237. "torch._C._special.special_hermite_polynomial_h",
  1238. "torch._C._special.special_hermite_polynomial_he",
  1239. "torch._C._special.special_i0",
  1240. "torch._C._special.special_i0e",
  1241. "torch._C._special.special_i1",
  1242. "torch._C._special.special_i1e",
  1243. "torch._C._special.special_laguerre_polynomial_l",
  1244. "torch._C._special.special_legendre_polynomial_p",
  1245. "torch._C._special.special_log_ndtr",
  1246. "torch._C._special.special_log_softmax",
  1247. "torch._C._special.special_log1p",
  1248. "torch._C._special.special_logit",
  1249. "torch._C._special.special_logsumexp",
  1250. "torch._C._special.special_modified_bessel_i0",
  1251. "torch._C._special.special_modified_bessel_i1",
  1252. "torch._C._special.special_modified_bessel_k0",
  1253. "torch._C._special.special_modified_bessel_k1",
  1254. "torch._C._special.special_multigammaln",
  1255. "torch._C._special.special_ndtr",
  1256. "torch._C._special.special_ndtri",
  1257. "torch._C._special.special_polygamma",
  1258. "torch._C._special.special_psi",
  1259. "torch._C._special.special_round",
  1260. "torch._C._special.special_scaled_modified_bessel_k0",
  1261. "torch._C._special.special_scaled_modified_bessel_k1",
  1262. "torch._C._special.special_shifted_chebyshev_polynomial_t",
  1263. "torch._C._special.special_shifted_chebyshev_polynomial_u",
  1264. "torch._C._special.special_shifted_chebyshev_polynomial_v",
  1265. "torch._C._special.special_shifted_chebyshev_polynomial_w",
  1266. "torch._C._special.special_sinc",
  1267. "torch._C._special.special_softmax",
  1268. "torch._C._special.special_spherical_bessel_j0",
  1269. "torch._C._special.special_xlog1py",
  1270. "torch._C._special.special_xlogy",
  1271. "torch._C._special.special_zeta",
  1272. "torch._C._stash_obj_in_tls",
  1273. "torch._C._storage_id",
  1274. "torch._C._storage_Use_Count",
  1275. "torch._C._supported_qengines",
  1276. "torch._C._te.abs",
  1277. "torch._C._te.acos",
  1278. "torch._C._te.annotate_input_shapes",
  1279. "torch._C._te.asin",
  1280. "torch._C._te.atan",
  1281. "torch._C._te.atan2",
  1282. "torch._C._te.ceil",
  1283. "torch._C._te.Compute",
  1284. "torch._C._te.Compute2",
  1285. "torch._C._te.construct_codegen",
  1286. "torch._C._te.cos",
  1287. "torch._C._te.cosh",
  1288. "torch._C._te.erf",
  1289. "torch._C._te.erfc",
  1290. "torch._C._te.exp",
  1291. "torch._C._te.expm1",
  1292. "torch._C._te.fixup_missing_shape_info",
  1293. "torch._C._te.floor",
  1294. "torch._C._te.fmod",
  1295. "torch._C._te.frac",
  1296. "torch._C._te.ifThenElse",
  1297. "torch._C._te.is_graph_compilable",
  1298. "torch._C._te.isnan",
  1299. "torch._C._te.lgamma",
  1300. "torch._C._te.log",
  1301. "torch._C._te.log10",
  1302. "torch._C._te.log1p",
  1303. "torch._C._te.log2",
  1304. "torch._C._te.lower",
  1305. "torch._C._te.make_shapes_symbolic",
  1306. "torch._C._te.pow",
  1307. "torch._C._te.Reduce",
  1308. "torch._C._te.remainder",
  1309. "torch._C._te.remove_graph_output",
  1310. "torch._C._te.remove_unused_self_argument",
  1311. "torch._C._te.replace_list_output_with_tuple",
  1312. "torch._C._te.round",
  1313. "torch._C._te.rsqrt",
  1314. "torch._C._te.sigmoid",
  1315. "torch._C._te.simplify",
  1316. "torch._C._te.sin",
  1317. "torch._C._te.sinh",
  1318. "torch._C._te.sqrt",
  1319. "torch._C._te.tan",
  1320. "torch._C._te.tanh",
  1321. "torch._C._te.trim_graph",
  1322. "torch._C._te.trunc",
  1323. "torch._C._tensor_impl_raw_handle",
  1324. "torch._C._test_only_add_entry_to_op_version_map",
  1325. "torch._C._test_only_populate_upgraders",
  1326. "torch._C._test_only_remove_entry_to_op_version_map",
  1327. "torch._C._test_only_remove_upgraders",
  1328. "torch._C._to_functionality_key",
  1329. "torch._C._tracer_set_force_outplace",
  1330. "torch._C._tracer_set_get_unique_name_fn",
  1331. "torch._C._tracer_warn_use_python",
  1332. "torch._C._unset_default_mobile_cpu_allocator",
  1333. "torch._C._unset_dispatch_mode",
  1334. "torch._C._valgrind_supported_platform",
  1335. "torch._C._valgrind_toggle_and_dump_stats",
  1336. "torch._C._valgrind_toggle",
  1337. "torch._C._verbose.mkl_set_verbose",
  1338. "torch._C._verbose.mkldnn_set_verbose",
  1339. "torch._C._vmapmode_decrement_nesting",
  1340. "torch._C._vmapmode_increment_nesting",
  1341. "torch._C._warn_deprecation",
  1342. "torch._C._warn",
  1343. "torch._C._will_engine_execute_node",
  1344. "torch._C._wrap_tensor_impl",
  1345. "torch._C._xpu_emptyCache",
  1346. "torch._C._xpu_getArchFlags",
  1347. "torch._C._xpu_getCurrentStream",
  1348. "torch._C._xpu_getCurrentRawStream",
  1349. "torch._C._xpu_getDeviceCount",
  1350. "torch._C._xpu_getDevice",
  1351. "torch._C._xpu_getMemoryInfo",
  1352. "torch._C._xpu_getStreamFromExternal",
  1353. "torch._C._xpu_isInBadFork",
  1354. "torch._C._xpu_init",
  1355. "torch._C._xpu_memoryStats",
  1356. "torch._C._xpu_resetAccumulatedMemoryStats",
  1357. "torch._C._xpu_resetPeakMemoryStats",
  1358. "torch._C._xpu_setStream",
  1359. "torch._C._xpu_synchronize",
  1360. "torch._C.fork",
  1361. "torch._C.get_autocast_cpu_dtype",
  1362. "torch._C.get_autocast_dtype",
  1363. "torch._C.get_autocast_gpu_dtype",
  1364. "torch._C.get_autocast_ipu_dtype",
  1365. "torch._C.get_autocast_xla_dtype",
  1366. "torch._C.get_default_dtype",
  1367. "torch._C.get_num_interop_threads",
  1368. "torch._C.get_num_threads",
  1369. "torch._C.import_ir_module_from_buffer",
  1370. "torch._C.import_ir_module",
  1371. "torch._C.init_num_threads",
  1372. "torch._C.is_anomaly_check_nan_enabled",
  1373. "torch._C.is_anomaly_enabled",
  1374. "torch._C.is_autocast_cache_enabled",
  1375. "torch._C.is_autocast_cpu_enabled",
  1376. "torch._C.is_autocast_enabled",
  1377. "torch._C.is_autocast_ipu_enabled",
  1378. "torch._C.is_autocast_xla_enabled",
  1379. "torch._C.is_grad_enabled",
  1380. "torch._C.is_inference_mode_enabled",
  1381. "torch._C.merge_type_from_type_comment",
  1382. "torch._C.parse_ir",
  1383. "torch._C.parse_schema",
  1384. "torch._C.parse_type_comment",
  1385. "torch._C.read_vitals",
  1386. "torch._C.set_vital",
  1387. "torch._C.unify_type_list",
  1388. "torch._C.vitals_enabled",
  1389. "torch._C.wait",
  1390. "torch._cast_Byte",
  1391. "torch._cast_Char",
  1392. "torch._cast_Double",
  1393. "torch._cast_Float",
  1394. "torch._cast_Half",
  1395. "torch._cast_Int",
  1396. "torch._cast_Long",
  1397. "torch._cast_Short",
  1398. "torch._choose_qparams_per_tensor",
  1399. "torch._chunk_cat",
  1400. "torch._coalesce",
  1401. "torch._compute_linear_combination",
  1402. "torch._conj_copy",
  1403. "torch._conj_physical",
  1404. "torch._conj",
  1405. "torch._convert_indices_from_coo_to_csr",
  1406. "torch._convert_indices_from_csr_to_coo",
  1407. "torch._convert_weight_to_int4pack",
  1408. "torch._convert_weight_to_int4pack_for_cpu",
  1409. "torch._convolution_mode",
  1410. "torch._convolution",
  1411. "torch._copy_from_and_resize",
  1412. "torch._copy_from",
  1413. "torch._cslt_compress",
  1414. "torch._cslt_sparse_mm",
  1415. "torch._ctc_loss",
  1416. "torch._cudnn_ctc_loss",
  1417. "torch._cudnn_init_dropout_state",
  1418. "torch._cudnn_rnn_flatten_weight",
  1419. "torch._cudnn_rnn",
  1420. "torch._cufft_clear_plan_cache",
  1421. "torch._cufft_get_plan_cache_max_size",
  1422. "torch._cufft_get_plan_cache_size",
  1423. "torch._cufft_set_plan_cache_max_size",
  1424. "torch._cummax_helper",
  1425. "torch._cummin_helper",
  1426. "torch._debug_has_internal_overlap",
  1427. "torch._dim_arange",
  1428. "torch._dirichlet_grad",
  1429. "torch._disable_functionalization",
  1430. "torch._dyn_quant_matmul_4bit",
  1431. "torch._dyn_quant_pack_4bit_weight",
  1432. "torch._efficientzerotensor",
  1433. "torch._embedding_bag_forward_only",
  1434. "torch._embedding_bag",
  1435. "torch._empty_affine_quantized",
  1436. "torch._empty_per_channel_affine_quantized",
  1437. "torch._enable_functionalization",
  1438. "torch._euclidean_dist",
  1439. "torch._fake_quantize_learnable_per_channel_affine",
  1440. "torch._fake_quantize_learnable_per_tensor_affine",
  1441. "torch._fake_quantize_per_tensor_affine_cachemask_tensor_qparams",
  1442. "torch._fft_c2c",
  1443. "torch._fft_c2r",
  1444. "torch._fft_r2c",
  1445. "torch._fill_mem_eff_dropout_mask_",
  1446. "torch._foobar",
  1447. "torch._foreach_abs_",
  1448. "torch._foreach_abs",
  1449. "torch._foreach_acos_",
  1450. "torch._foreach_acos",
  1451. "torch._foreach_add_",
  1452. "torch._foreach_add",
  1453. "torch._foreach_addcdiv_",
  1454. "torch._foreach_addcdiv",
  1455. "torch._foreach_addcmul_",
  1456. "torch._foreach_addcmul",
  1457. "torch._foreach_asin_",
  1458. "torch._foreach_asin",
  1459. "torch._foreach_atan_",
  1460. "torch._foreach_atan",
  1461. "torch._foreach_ceil_",
  1462. "torch._foreach_ceil",
  1463. "torch._foreach_clamp_max_",
  1464. "torch._foreach_clamp_max",
  1465. "torch._foreach_clamp_min_",
  1466. "torch._foreach_clamp_min",
  1467. "torch._foreach_copy_",
  1468. "torch._foreach_cos_",
  1469. "torch._foreach_cos",
  1470. "torch._foreach_cosh_",
  1471. "torch._foreach_cosh",
  1472. "torch._foreach_div_",
  1473. "torch._foreach_div",
  1474. "torch._foreach_erf_",
  1475. "torch._foreach_erf",
  1476. "torch._foreach_erfc_",
  1477. "torch._foreach_erfc",
  1478. "torch._foreach_exp_",
  1479. "torch._foreach_exp",
  1480. "torch._foreach_expm1_",
  1481. "torch._foreach_expm1",
  1482. "torch._foreach_floor_",
  1483. "torch._foreach_floor",
  1484. "torch._foreach_frac_",
  1485. "torch._foreach_frac",
  1486. "torch._foreach_lerp_",
  1487. "torch._foreach_lerp",
  1488. "torch._foreach_lgamma_",
  1489. "torch._foreach_lgamma",
  1490. "torch._foreach_log_",
  1491. "torch._foreach_log",
  1492. "torch._foreach_log10_",
  1493. "torch._foreach_log10",
  1494. "torch._foreach_log1p_",
  1495. "torch._foreach_log1p",
  1496. "torch._foreach_log2_",
  1497. "torch._foreach_log2",
  1498. "torch._foreach_maximum_",
  1499. "torch._foreach_maximum",
  1500. "torch._foreach_minimum_",
  1501. "torch._foreach_minimum",
  1502. "torch._foreach_mul_",
  1503. "torch._foreach_mul",
  1504. "torch._foreach_neg_",
  1505. "torch._foreach_neg",
  1506. "torch._foreach_norm",
  1507. "torch._foreach_pow_",
  1508. "torch._foreach_pow",
  1509. "torch._foreach_reciprocal_",
  1510. "torch._foreach_reciprocal",
  1511. "torch._foreach_round_",
  1512. "torch._foreach_round",
  1513. "torch._foreach_sigmoid_",
  1514. "torch._foreach_sigmoid",
  1515. "torch._foreach_rsqrt_",
  1516. "torch._foreach_rsqrt",
  1517. "torch._foreach_sign_",
  1518. "torch._foreach_sign",
  1519. "torch._foreach_sin_",
  1520. "torch._foreach_sin",
  1521. "torch._foreach_sinh_",
  1522. "torch._foreach_sinh",
  1523. "torch._foreach_sqrt_",
  1524. "torch._foreach_sqrt",
  1525. "torch._foreach_sub_",
  1526. "torch._foreach_sub",
  1527. "torch._foreach_tan_",
  1528. "torch._foreach_tan",
  1529. "torch._foreach_tanh_",
  1530. "torch._foreach_tanh",
  1531. "torch._foreach_trunc_",
  1532. "torch._foreach_trunc",
  1533. "torch._foreach_zero_",
  1534. "torch._freeze_functional_tensor",
  1535. "torch._from_functional_tensor",
  1536. "torch._functional_assert_async",
  1537. "torch._functional_sym_constrain_range_for_size",
  1538. "torch._functional_sym_constrain_range",
  1539. "torch._functionalize_are_all_mutations_hidden_from_autograd",
  1540. "torch._functionalize_commit_update",
  1541. "torch._functionalize_enable_reapply_views",
  1542. "torch._functionalize_has_data_mutation",
  1543. "torch._functionalize_has_metadata_mutation",
  1544. "torch._functionalize_is_multi_output_view",
  1545. "torch._functionalize_mark_mutation_hidden_from_autograd",
  1546. "torch._functionalize_replace",
  1547. "torch._functionalize_sync",
  1548. "torch._functionalize_was_storage_changed",
  1549. "torch._fused_adam_",
  1550. "torch._fused_adamw_",
  1551. "torch._fused_dropout",
  1552. "torch._fused_moving_avg_obs_fq_helper",
  1553. "torch._fused_sdp_choice",
  1554. "torch._fw_primal_copy",
  1555. "torch._grid_sampler_2d_cpu_fallback",
  1556. "torch._grouped_mm",
  1557. "torch._has_compatible_shallow_copy_type",
  1558. "torch._histogramdd_bin_edges",
  1559. "torch._histogramdd_from_bin_cts",
  1560. "torch._histogramdd_from_bin_tensors",
  1561. "torch._index_put_impl_",
  1562. "torch._indices_copy",
  1563. "torch._int_mm",
  1564. "torch._is_all_true",
  1565. "torch._is_any_true",
  1566. "torch._is_functional_tensor",
  1567. "torch._is_zerotensor",
  1568. "torch._linalg_check_errors",
  1569. "torch._linalg_det",
  1570. "torch._linalg_eigh",
  1571. "torch._linalg_eigvals",
  1572. "torch._linalg_slogdet",
  1573. "torch._linalg_solve_ex",
  1574. "torch._linalg_svd",
  1575. "torch._log_softmax_backward_data",
  1576. "torch._log_softmax",
  1577. "torch._logcumsumexp",
  1578. "torch._lstm_mps",
  1579. "torch._lu_with_info",
  1580. "torch._make_dep_token",
  1581. "torch._make_dual_copy",
  1582. "torch._make_dual",
  1583. "torch._make_per_channel_quantized_tensor",
  1584. "torch._make_per_tensor_quantized_tensor",
  1585. "torch._masked_scale",
  1586. "torch._masked_softmax",
  1587. "torch._mirror_autograd_meta_to",
  1588. "torch._mixed_dtypes_linear",
  1589. "torch._mkldnn_reshape",
  1590. "torch._mkldnn_transpose_",
  1591. "torch._mkldnn_transpose",
  1592. "torch._mps_convolution_transpose",
  1593. "torch._mps_convolution",
  1594. "torch._native_batch_norm_legit_no_training",
  1595. "torch._native_batch_norm_legit",
  1596. "torch._native_multi_head_attention",
  1597. "torch._neg_view_copy",
  1598. "torch._neg_view",
  1599. "torch._nested_from_padded_and_nested_example",
  1600. "torch._nested_from_padded_tensor",
  1601. "torch._nested_tensor_from_mask_left_aligned",
  1602. "torch._nested_tensor_from_tensor_list",
  1603. "torch._nested_tensor_softmax_with_shape",
  1604. "torch._nested_view_from_buffer_copy",
  1605. "torch._nested_view_from_buffer",
  1606. "torch._nnpack_available",
  1607. "torch._nnpack_spatial_convolution",
  1608. "torch._pack_padded_sequence",
  1609. "torch._pad_packed_sequence",
  1610. "torch._pin_memory",
  1611. "torch._prelu_kernel",
  1612. "torch._propagate_xla_data",
  1613. "torch._remove_batch_dim",
  1614. "torch._reshape_alias_copy",
  1615. "torch._reshape_from_tensor",
  1616. "torch._resize_output_",
  1617. "torch._rowwise_prune",
  1618. "torch._sample_dirichlet",
  1619. "torch._saturate_weight_to_fp16",
  1620. "torch._scaled_dot_product_attention_math",
  1621. "torch._scaled_dot_product_efficient_attention",
  1622. "torch._scaled_dot_product_flash_attention",
  1623. "torch._scaled_dot_product_flash_attention_for_cpu",
  1624. "torch._scaled_dot_product_cudnn_attention",
  1625. "torch._scaled_mm",
  1626. "torch._scaled_grouped_mm",
  1627. "torch._shape_as_tensor",
  1628. "torch._sobol_engine_draw",
  1629. "torch._sobol_engine_ff_",
  1630. "torch._sobol_engine_initialize_state_",
  1631. "torch._sobol_engine_scramble_",
  1632. "torch._softmax_backward_data",
  1633. "torch._softmax",
  1634. "torch._sparse_broadcast_to_copy",
  1635. "torch._sparse_broadcast_to",
  1636. "torch._sparse_csr_prod",
  1637. "torch._sparse_csr_sum",
  1638. "torch._sparse_log_softmax_backward_data",
  1639. "torch._sparse_semi_structured_addmm",
  1640. "torch._sparse_semi_structured_linear",
  1641. "torch._sparse_semi_structured_mm",
  1642. "torch._sparse_softmax_backward_data",
  1643. "torch._sparse_sparse_matmul",
  1644. "torch._sparse_sum",
  1645. "torch._stack",
  1646. "torch._standard_gamma_grad",
  1647. "torch._standard_gamma",
  1648. "torch._test_autograd_multiple_dispatch_view_copy",
  1649. "torch._test_autograd_multiple_dispatch_view",
  1650. "torch._test_autograd_multiple_dispatch",
  1651. "torch._test_check_tensor",
  1652. "torch._test_functorch_fallback",
  1653. "torch._test_serialization_subcmul",
  1654. "torch._to_cpu",
  1655. "torch._to_functional_tensor",
  1656. "torch._to_sparse_semi_structured",
  1657. "torch._transform_bias_rescale_qkv",
  1658. "torch._transformer_encoder_layer_fwd",
  1659. "torch._trilinear",
  1660. "torch._triton_multi_head_attention",
  1661. "torch._triton_scaled_dot_attention",
  1662. "torch._unique",
  1663. "torch._unique2",
  1664. "torch._unpack_dual",
  1665. "torch._unsafe_index_put",
  1666. "torch._unsafe_index",
  1667. "torch._unsafe_masked_index_put_accumulate",
  1668. "torch._unsafe_masked_index",
  1669. "torch._use_cudnn_ctc_loss",
  1670. "torch._use_cudnn_rnn_flatten_weight",
  1671. "torch._values_copy",
  1672. "torch._weight_int4pack_mm",
  1673. "torch._weight_int4pack_mm_for_cpu",
  1674. "torch._weight_int4pack_mm_with_scales_and_zeros",
  1675. "torch._weight_int8pack_mm",
  1676. "torch._weight_norm_interface",
  1677. "torch._weight_norm",
  1678. "torch.abs_",
  1679. "torch.abs",
  1680. "torch.absolute",
  1681. "torch.acos_",
  1682. "torch.acos",
  1683. "torch.acosh_",
  1684. "torch.acosh",
  1685. "torch.adaptive_avg_pool1d",
  1686. "torch.adaptive_max_pool1d",
  1687. "torch.add",
  1688. "torch.addbmm",
  1689. "torch.addcdiv",
  1690. "torch.addcmul",
  1691. "torch.addmm",
  1692. "torch.addmv_",
  1693. "torch.addmv",
  1694. "torch.addr",
  1695. "torch.adjoint",
  1696. "torch.affine_grid_generator",
  1697. "torch.alias_copy",
  1698. "torch.all",
  1699. "torch.allclose",
  1700. "torch.alpha_dropout_",
  1701. "torch.alpha_dropout",
  1702. "torch.amax",
  1703. "torch.amin",
  1704. "torch.aminmax",
  1705. "torch.angle",
  1706. "torch.any",
  1707. "torch.arange",
  1708. "torch.arccos_",
  1709. "torch.arccos",
  1710. "torch.arccosh_",
  1711. "torch.arccosh",
  1712. "torch.arcsin_",
  1713. "torch.arcsin",
  1714. "torch.arcsinh_",
  1715. "torch.arcsinh",
  1716. "torch.arctan_",
  1717. "torch.arctan",
  1718. "torch.arctan2",
  1719. "torch.arctanh_",
  1720. "torch.arctanh",
  1721. "torch.argmax",
  1722. "torch.argmin",
  1723. "torch.argsort",
  1724. "torch.argwhere",
  1725. "torch.as_strided_",
  1726. "torch.as_strided_copy",
  1727. "torch.as_strided_scatter",
  1728. "torch.as_strided",
  1729. "torch.as_tensor",
  1730. "torch.asarray",
  1731. "torch.asin_",
  1732. "torch.asin",
  1733. "torch.asinh_",
  1734. "torch.asinh",
  1735. "torch.atan_",
  1736. "torch.atan",
  1737. "torch.atan2",
  1738. "torch.atanh_",
  1739. "torch.atanh",
  1740. "torch.avg_pool1d",
  1741. "torch.baddbmm",
  1742. "torch.bartlett_window",
  1743. "torch.batch_norm_backward_elemt",
  1744. "torch.batch_norm_backward_reduce",
  1745. "torch.batch_norm_elemt",
  1746. "torch.batch_norm_gather_stats_with_counts",
  1747. "torch.batch_norm_gather_stats",
  1748. "torch.batch_norm_stats",
  1749. "torch.batch_norm_update_stats",
  1750. "torch.batch_norm",
  1751. "torch.bernoulli",
  1752. "torch.bilinear",
  1753. "torch.binary_cross_entropy_with_logits",
  1754. "torch.bincount",
  1755. "torch.binomial",
  1756. "torch.bitwise_and",
  1757. "torch.bitwise_left_shift",
  1758. "torch.bitwise_not",
  1759. "torch.bitwise_or",
  1760. "torch.bitwise_right_shift",
  1761. "torch.bitwise_xor",
  1762. "torch.blackman_window",
  1763. "torch.bmm",
  1764. "torch.broadcast_to",
  1765. "torch.bucketize",
  1766. "torch.can_cast",
  1767. "torch.cat",
  1768. "torch.ccol_indices_copy",
  1769. "torch.ceil_",
  1770. "torch.ceil",
  1771. "torch.celu_",
  1772. "torch.celu",
  1773. "torch.channel_shuffle",
  1774. "torch.cholesky_inverse",
  1775. "torch.cholesky_solve",
  1776. "torch.cholesky",
  1777. "torch.choose_qparams_optimized",
  1778. "torch.chunk",
  1779. "torch.clamp_",
  1780. "torch.clamp_max_",
  1781. "torch.clamp_max",
  1782. "torch.clamp_min_",
  1783. "torch.clamp_min",
  1784. "torch.clamp",
  1785. "torch.clip_",
  1786. "torch.clip",
  1787. "torch.clone",
  1788. "torch.col_indices_copy",
  1789. "torch.column_stack",
  1790. "torch.combinations",
  1791. "torch.complex",
  1792. "torch.concat",
  1793. "torch.concatenate",
  1794. "torch.conj_physical_",
  1795. "torch.conj_physical",
  1796. "torch.conj",
  1797. "torch.constant_pad_nd",
  1798. "torch.conv_tbc",
  1799. "torch.conv_transpose1d",
  1800. "torch.conv_transpose2d",
  1801. "torch.conv_transpose3d",
  1802. "torch.conv1d",
  1803. "torch.conv2d",
  1804. "torch.conv3d",
  1805. "torch.convolution",
  1806. "torch.copysign",
  1807. "torch.corrcoef",
  1808. "torch.cos_",
  1809. "torch.cos",
  1810. "torch.cosh_",
  1811. "torch.cosh",
  1812. "torch.cosine_embedding_loss",
  1813. "torch.cosine_similarity",
  1814. "torch.count_nonzero",
  1815. "torch.cov",
  1816. "torch.cross",
  1817. "torch.crow_indices_copy",
  1818. "torch.ctc_loss",
  1819. "torch.cudnn_affine_grid_generator",
  1820. "torch.cudnn_batch_norm",
  1821. "torch.cudnn_convolution_add_relu",
  1822. "torch.cudnn_convolution_relu",
  1823. "torch.cudnn_convolution_transpose",
  1824. "torch.cudnn_convolution",
  1825. "torch.cudnn_grid_sampler",
  1826. "torch.cudnn_is_acceptable",
  1827. "torch.cummax",
  1828. "torch.cummin",
  1829. "torch.cumprod",
  1830. "torch.cumsum",
  1831. "torch.cumulative_trapezoid",
  1832. "torch.deg2rad_",
  1833. "torch.deg2rad",
  1834. "torch.dequantize",
  1835. "torch.det",
  1836. "torch.detach_",
  1837. "torch.detach_copy",
  1838. "torch.detach",
  1839. "torch.diag_embed",
  1840. "torch.diag",
  1841. "torch.diagflat",
  1842. "torch.diagonal_copy",
  1843. "torch.diagonal_scatter",
  1844. "torch.diagonal",
  1845. "torch.diff",
  1846. "torch.digamma",
  1847. "torch.dist",
  1848. "torch.div",
  1849. "torch.divide",
  1850. "torch.dot",
  1851. "torch.dropout_",
  1852. "torch.dropout",
  1853. "torch.dsmm",
  1854. "torch.dsplit",
  1855. "torch.dstack",
  1856. "torch.embedding_bag",
  1857. "torch.embedding_renorm_",
  1858. "torch.embedding",
  1859. "torch.empty_like",
  1860. "torch.empty_permuted",
  1861. "torch.empty_quantized",
  1862. "torch.empty_strided",
  1863. "torch.empty",
  1864. "torch.eq",
  1865. "torch.equal",
  1866. "torch.erf_",
  1867. "torch.erf",
  1868. "torch.erfc_",
  1869. "torch.erfc",
  1870. "torch.erfinv",
  1871. "torch.exp_",
  1872. "torch.exp",
  1873. "torch.exp2_",
  1874. "torch.exp2",
  1875. "torch.expand_copy",
  1876. "torch.expm1_",
  1877. "torch.expm1",
  1878. "torch.eye",
  1879. "torch.fake_quantize_per_channel_affine",
  1880. "torch.fake_quantize_per_tensor_affine",
  1881. "torch.fbgemm_linear_fp16_weight_fp32_activation",
  1882. "torch.fbgemm_linear_fp16_weight",
  1883. "torch.fbgemm_linear_int8_weight_fp32_activation",
  1884. "torch.fbgemm_linear_int8_weight",
  1885. "torch.fbgemm_linear_quantize_weight",
  1886. "torch.fbgemm_pack_gemm_matrix_fp16",
  1887. "torch.fbgemm_pack_quantized_matrix",
  1888. "torch.feature_alpha_dropout_",
  1889. "torch.feature_alpha_dropout",
  1890. "torch.feature_dropout_",
  1891. "torch.feature_dropout",
  1892. "torch.fill_",
  1893. "torch.fill",
  1894. "torch.fix_",
  1895. "torch.fix",
  1896. "torch.flatten",
  1897. "torch.flip",
  1898. "torch.fliplr",
  1899. "torch.flipud",
  1900. "torch.float_power",
  1901. "torch.floor_",
  1902. "torch.floor_divide",
  1903. "torch.floor",
  1904. "torch.fmax",
  1905. "torch.fmin",
  1906. "torch.fmod",
  1907. "torch.frac_",
  1908. "torch.frac",
  1909. "torch.frexp",
  1910. "torch.frobenius_norm",
  1911. "torch.from_file",
  1912. "torch.from_numpy",
  1913. "torch.frombuffer",
  1914. "torch.full_like",
  1915. "torch.full",
  1916. "torch.fused_moving_avg_obs_fake_quant",
  1917. "torch.gather",
  1918. "torch.gcd_",
  1919. "torch.gcd",
  1920. "torch.ge",
  1921. "torch.geqrf",
  1922. "torch.ger",
  1923. "torch.get_device",
  1924. "torch.get_device_module",
  1925. "torch.gradient",
  1926. "torch.greater_equal",
  1927. "torch.greater",
  1928. "torch.grid_sampler_2d",
  1929. "torch.grid_sampler_3d",
  1930. "torch.grid_sampler",
  1931. "torch.group_norm",
  1932. "torch.gru_cell",
  1933. "torch.gru",
  1934. "torch.gt",
  1935. "torch.hamming_window",
  1936. "torch.hann_window",
  1937. "torch.hardshrink",
  1938. "torch.hash_tensor",
  1939. "torch.heaviside",
  1940. "torch.hinge_embedding_loss",
  1941. "torch.histc",
  1942. "torch.histogram",
  1943. "torch.histogramdd",
  1944. "torch.hsmm",
  1945. "torch.hsplit",
  1946. "torch.hspmm",
  1947. "torch.hstack",
  1948. "torch.hypot",
  1949. "torch.i0_",
  1950. "torch.i0",
  1951. "torch.igamma",
  1952. "torch.igammac",
  1953. "torch.imag",
  1954. "torch.index_add",
  1955. "torch.index_copy",
  1956. "torch.index_fill",
  1957. "torch.index_put_",
  1958. "torch.index_put",
  1959. "torch.index_reduce",
  1960. "torch.index_select",
  1961. "torch.indices_copy",
  1962. "torch.inner",
  1963. "torch.instance_norm",
  1964. "torch.int_repr",
  1965. "torch.inverse",
  1966. "torch.is_complex",
  1967. "torch.is_conj",
  1968. "torch.is_distributed",
  1969. "torch.is_floating_point",
  1970. "torch.is_inference",
  1971. "torch.is_neg",
  1972. "torch.is_nonzero",
  1973. "torch.is_same_size",
  1974. "torch.is_signed",
  1975. "torch.is_vulkan_available",
  1976. "torch.isclose",
  1977. "torch.isfinite",
  1978. "torch.isin",
  1979. "torch.isinf",
  1980. "torch.isnan",
  1981. "torch.isneginf",
  1982. "torch.isposinf",
  1983. "torch.isreal",
  1984. "torch.istft",
  1985. "torch.kaiser_window",
  1986. "torch.kl_div",
  1987. "torch.kron",
  1988. "torch.kthvalue",
  1989. "torch.layer_norm",
  1990. "torch.lcm_",
  1991. "torch.lcm",
  1992. "torch.ldexp_",
  1993. "torch.ldexp",
  1994. "torch.le",
  1995. "torch.lerp",
  1996. "torch.less_equal",
  1997. "torch.less",
  1998. "torch.lgamma",
  1999. "torch.linspace",
  2000. "torch.log_",
  2001. "torch.log_softmax",
  2002. "torch.log",
  2003. "torch.log10_",
  2004. "torch.log10",
  2005. "torch.log1p_",
  2006. "torch.log1p",
  2007. "torch.log2_",
  2008. "torch.log2",
  2009. "torch.logaddexp",
  2010. "torch.logaddexp2",
  2011. "torch.logcumsumexp",
  2012. "torch.logdet",
  2013. "torch.logical_and",
  2014. "torch.logical_not",
  2015. "torch.logical_or",
  2016. "torch.logical_xor",
  2017. "torch.logit_",
  2018. "torch.logit",
  2019. "torch.logspace",
  2020. "torch.logsumexp",
  2021. "torch.lstm_cell",
  2022. "torch.lstm",
  2023. "torch.lt",
  2024. "torch.lu_solve",
  2025. "torch.lu_unpack",
  2026. "torch.margin_ranking_loss",
  2027. "torch.masked_fill",
  2028. "torch.masked_scatter",
  2029. "torch.masked_select",
  2030. "torch.matmul",
  2031. "torch.matrix_exp",
  2032. "torch.matrix_power",
  2033. "torch.max_pool1d_with_indices",
  2034. "torch.max_pool1d",
  2035. "torch.max_pool2d",
  2036. "torch.max_pool3d",
  2037. "torch.max",
  2038. "torch.maximum",
  2039. "torch.mean",
  2040. "torch.median",
  2041. "torch.min",
  2042. "torch.minimum",
  2043. "torch.miopen_batch_norm",
  2044. "torch.miopen_convolution_add_relu",
  2045. "torch.miopen_convolution_relu",
  2046. "torch.miopen_convolution_transpose",
  2047. "torch.miopen_convolution",
  2048. "torch.miopen_depthwise_convolution",
  2049. "torch.miopen_rnn",
  2050. "torch.mkldnn_adaptive_avg_pool2d",
  2051. "torch.mkldnn_convolution",
  2052. "torch.mkldnn_linear_backward_weights",
  2053. "torch.mkldnn_max_pool2d",
  2054. "torch.mkldnn_max_pool3d",
  2055. "torch.mkldnn_rnn_layer",
  2056. "torch.mm",
  2057. "torch.mode",
  2058. "torch.moveaxis",
  2059. "torch.movedim",
  2060. "torch.msort",
  2061. "torch.mul",
  2062. "torch.multinomial",
  2063. "torch.multiply",
  2064. "torch.mv",
  2065. "torch.mvlgamma",
  2066. "torch.nan_to_num_",
  2067. "torch.nan_to_num",
  2068. "torch.nanmean",
  2069. "torch.nanmedian",
  2070. "torch.nanquantile",
  2071. "torch.nansum",
  2072. "torch.narrow_copy",
  2073. "torch.narrow",
  2074. "torch.native_batch_norm",
  2075. "torch.native_channel_shuffle",
  2076. "torch.native_dropout",
  2077. "torch.native_group_norm",
  2078. "torch.native_layer_norm",
  2079. "torch.native_norm",
  2080. "torch.ne",
  2081. "torch.neg_",
  2082. "torch.neg",
  2083. "torch.negative_",
  2084. "torch.negative",
  2085. "torch.nextafter",
  2086. "torch.nonzero_static",
  2087. "torch.nonzero",
  2088. "torch.norm_except_dim",
  2089. "torch.normal",
  2090. "torch.not_equal",
  2091. "torch.nuclear_norm",
  2092. "torch.numel",
  2093. "torch.ones_like",
  2094. "torch.ones",
  2095. "torch.orgqr",
  2096. "torch.ormqr",
  2097. "torch.outer",
  2098. "torch.pairwise_distance",
  2099. "torch.pdist",
  2100. "torch.permute_copy",
  2101. "torch.permute",
  2102. "torch.pinverse",
  2103. "torch.pixel_shuffle",
  2104. "torch.pixel_unshuffle",
  2105. "torch.poisson_nll_loss",
  2106. "torch.poisson",
  2107. "torch.polar",
  2108. "torch.polygamma",
  2109. "torch.positive",
  2110. "torch.pow",
  2111. "torch.prelu",
  2112. "torch._print",
  2113. "torch.prod",
  2114. "torch.promote_types",
  2115. "torch.put",
  2116. "torch.q_per_channel_axis",
  2117. "torch.q_per_channel_scales",
  2118. "torch.q_per_channel_zero_points",
  2119. "torch.q_scale",
  2120. "torch.q_zero_point",
  2121. "torch.qr",
  2122. "torch.quantile",
  2123. "torch.quantize_per_channel",
  2124. "torch.quantize_per_tensor_dynamic",
  2125. "torch.quantize_per_tensor",
  2126. "torch.quantized_batch_norm",
  2127. "torch.quantized_gru_cell",
  2128. "torch.quantized_lstm_cell",
  2129. "torch.quantized_max_pool1d",
  2130. "torch.quantized_max_pool2d",
  2131. "torch.quantized_max_pool3d",
  2132. "torch.quantized_rnn_relu_cell",
  2133. "torch.quantized_rnn_tanh_cell",
  2134. "torch.rad2deg_",
  2135. "torch.rad2deg",
  2136. "torch.rand_like",
  2137. "torch.rand",
  2138. "torch.randint_like",
  2139. "torch.randint",
  2140. "torch.randn_like",
  2141. "torch.randn",
  2142. "torch.randperm",
  2143. "torch.range",
  2144. "torch.ravel",
  2145. "torch.real",
  2146. "torch.reciprocal_",
  2147. "torch.reciprocal",
  2148. "torch.relu_",
  2149. "torch.relu",
  2150. "torch.remainder",
  2151. "torch.renorm",
  2152. "torch.repeat_interleave",
  2153. "torch.reshape",
  2154. "torch.resolve_conj",
  2155. "torch.resolve_neg",
  2156. "torch.result_type",
  2157. "torch.rms_norm",
  2158. "torch.rnn_relu_cell",
  2159. "torch.rnn_relu",
  2160. "torch.rnn_tanh_cell",
  2161. "torch.rnn_tanh",
  2162. "torch.roll",
  2163. "torch.rot90",
  2164. "torch.round_",
  2165. "torch.round",
  2166. "torch.row_indices_copy",
  2167. "torch.row_stack",
  2168. "torch.rrelu_",
  2169. "torch.rrelu",
  2170. "torch.rsqrt_",
  2171. "torch.rsqrt",
  2172. "torch.rsub",
  2173. "torch.saddmm",
  2174. "torch.scalar_tensor",
  2175. "torch.scatter_add",
  2176. "torch.scatter_reduce",
  2177. "torch.scatter",
  2178. "torch.searchsorted",
  2179. "torch.segment_reduce",
  2180. "torch.select_copy",
  2181. "torch.select_scatter",
  2182. "torch.select",
  2183. "torch.selu_",
  2184. "torch.selu",
  2185. "torch.sgn",
  2186. "torch.sigmoid_",
  2187. "torch.sigmoid",
  2188. "torch.sign",
  2189. "torch.signal.windows.windows.sqrt",
  2190. "torch.signbit",
  2191. "torch.sin_",
  2192. "torch.sin",
  2193. "torch.sinc_",
  2194. "torch.sinc",
  2195. "torch.sinh_",
  2196. "torch.sinh",
  2197. "torch.slice_copy",
  2198. "torch.slice_scatter",
  2199. "torch.slogdet",
  2200. "torch.smm",
  2201. "torch.softmax",
  2202. "torch.sort",
  2203. "torch.split_copy",
  2204. "torch.split_with_sizes_copy",
  2205. "torch.split_with_sizes",
  2206. "torch.spmm",
  2207. "torch.sqrt_",
  2208. "torch.sqrt",
  2209. "torch.square_",
  2210. "torch.square",
  2211. "torch.squeeze_copy",
  2212. "torch.squeeze",
  2213. "torch.sspaddmm",
  2214. "torch.stack",
  2215. "torch.std_mean",
  2216. "torch.std",
  2217. "torch.sub",
  2218. "torch.subtract",
  2219. "torch.sum",
  2220. "torch.svd",
  2221. "torch.swapaxes",
  2222. "torch.swapdims",
  2223. "torch.sym_constrain_range_for_size",
  2224. "torch.sym_constrain_range",
  2225. "torch.t_copy",
  2226. "torch.t",
  2227. "torch.take_along_dim",
  2228. "torch.take",
  2229. "torch.tan_",
  2230. "torch.tan",
  2231. "torch.tanh_",
  2232. "torch.tanh",
  2233. "torch.tensor_split",
  2234. "torch.tensor",
  2235. "torch.threshold_",
  2236. "torch.threshold",
  2237. "torch.tile",
  2238. "torch.topk",
  2239. "torch.trace",
  2240. "torch.transpose_copy",
  2241. "torch.transpose",
  2242. "torch.trapezoid",
  2243. "torch.trapz",
  2244. "torch.triangular_solve",
  2245. "torch.tril_indices",
  2246. "torch.tril",
  2247. "torch.triplet_margin_loss",
  2248. "torch.triu_indices",
  2249. "torch.triu",
  2250. "torch.true_divide",
  2251. "torch.trunc_",
  2252. "torch.trunc",
  2253. "torch.unbind_copy",
  2254. "torch.unbind",
  2255. "torch.unflatten",
  2256. "torch.unfold_copy",
  2257. "torch.unsafe_chunk",
  2258. "torch.unsafe_split_with_sizes",
  2259. "torch.unsafe_split",
  2260. "torch.unsqueeze_copy",
  2261. "torch.unsqueeze",
  2262. "torch.values_copy",
  2263. "torch.vander",
  2264. "torch.var_mean",
  2265. "torch.var",
  2266. "torch.vdot",
  2267. "torch.view_as_complex_copy",
  2268. "torch.view_as_complex",
  2269. "torch.view_as_real_copy",
  2270. "torch.view_as_real",
  2271. "torch.view_copy",
  2272. "torch.vsplit",
  2273. "torch.vstack",
  2274. "torch.where",
  2275. "torch.xlogy_",
  2276. "torch.xlogy",
  2277. "torch.zero_",
  2278. "torch.zeros",
  2279. "torch.zeros_like",
  2280. "torch._fused_sgd_",
  2281. "torch.slice_inverse",
  2282. "torch._assert_scalar",
  2283. "torch._functional_assert_scalar",
  2284. "torch.xpu._get_device_properties",
  2285. ],
  2286. TorchInGraphFunctionVariable,
  2287. )
  2288. if sys.version_info >= (3, 11):
  2289. torch_c_binding_in_graph_functions["math.exp2"] = TorchInGraphFunctionVariable
  2290. torch_c_binding_in_graph_functions["math.cbrt"] = TorchInGraphFunctionVariable
  2291. # In graph functions (including constant folding) that are not C bindings
  2292. # NOTE: [Cacheability of in-graph torch functions]
  2293. # Functions in this list have the property that graphs containing them are safe to cache/serialize.
  2294. # serialize given only the information in the graph. I.e, either:
  2295. # - Your function does not access or close over global state, or
  2296. # - Your function closes over global state, but this state is guarded by dynamo, either
  2297. # through constant folding or other mechanisms
  2298. # If your function needs a custom special handler (via @register on TorchInGraphFunctionVariable),
  2299. # or captures global state, please add it to manual_torch_name_rule_map instead
  2300. torch_non_c_binding_in_graph_functions = dict.fromkeys(
  2301. [
  2302. "torch.__future__.get_overwrite_module_params_on_conversion",
  2303. "torch.__future__.set_overwrite_module_params_on_conversion",
  2304. "torch.__getattr__",
  2305. "torch._assert",
  2306. "torch._check_index",
  2307. "torch._check_is_size",
  2308. "torch._check_not_implemented",
  2309. "torch._check_tensor_all_with",
  2310. "torch._check_tensor_all",
  2311. "torch._check_type",
  2312. "torch._check_value",
  2313. "torch._check_with",
  2314. "torch._check",
  2315. "torch._compile._disable_dynamo",
  2316. "torch._functorch.apis.chunk_vmap",
  2317. "torch._functorch.batch_norm_replacement.batch_norm_without_running_stats",
  2318. "torch._functorch.batch_norm_replacement.replace_all_batch_norm_modules_",
  2319. "torch._functorch.deprecated.combine_state_for_ensemble",
  2320. "torch._functorch.deprecated.functionalize",
  2321. "torch._functorch.deprecated.get_warning",
  2322. "torch._functorch.deprecated.make_functional_with_buffers",
  2323. "torch._functorch.deprecated.make_functional",
  2324. "torch._functorch.deprecated.setup_docs",
  2325. "torch._functorch.deprecated.warn_deprecated",
  2326. "torch._functorch.eager_transforms._any_differentiable",
  2327. "torch._functorch.eager_transforms._autograd_grad",
  2328. "torch._functorch.eager_transforms._set_tensor_requires_grad",
  2329. "torch._functorch.eager_transforms._is_differentiable",
  2330. "torch._functorch.eager_transforms._maybe_unwrap_functional_tensor",
  2331. "torch._functorch.eager_transforms._maybe_wrap_functional_tensor",
  2332. "torch._functorch.eager_transforms._unwrap_all_tensors_from_functional",
  2333. "torch._functorch.eager_transforms._wrap_all_tensors_to_functional",
  2334. "torch._functorch.eager_transforms.assert_flat_tuple_of_tensors",
  2335. "torch._functorch.eager_transforms.functionalize",
  2336. "torch._functorch.eager_transforms.lazy_dynamo_disable",
  2337. "torch._functorch.eager_transforms.noop",
  2338. "torch._functorch.utils.enable_single_level_autograd_function",
  2339. "torch._functorch.utils.exposed_in",
  2340. "torch._functorch.utils.unwrap_dead_wrappers",
  2341. "torch._functorch.predispatch.lazy_load_decompositions",
  2342. "torch._functorch.predispatch._vmap_increment_nesting",
  2343. "torch._functorch.predispatch._vmap_decrement_nesting",
  2344. "torch._functorch.predispatch._add_batch_dim",
  2345. "torch._functorch.predispatch._remove_batch_dim",
  2346. "torch._guards.compile_context",
  2347. "torch._guards.detect_fake_mode",
  2348. "torch._guards.tracing",
  2349. "torch._higher_order_ops.map._has_potential_branch_input_alias",
  2350. "torch._higher_order_ops.map._has_potential_branch_input_mutation",
  2351. "torch._higher_order_ops.map._stack_pytree",
  2352. "torch._higher_order_ops.map._unstack_pytree",
  2353. "torch._higher_order_ops.map.create_fw_bw_graph",
  2354. "torch._higher_order_ops.map.map_autograd",
  2355. "torch._higher_order_ops.map.map_dense",
  2356. "torch._higher_order_ops.map.map_fake_tensor_mode",
  2357. "torch._higher_order_ops.map.map_functionalize",
  2358. "torch._higher_order_ops.map.map_proxy_torch_dispatch_mode",
  2359. "torch._higher_order_ops.map.map_wrapper",
  2360. "torch._higher_order_ops.map.trace_map",
  2361. "torch._higher_order_ops.out_dtype.elementwise_dtypes",
  2362. "torch._higher_order_ops.out_dtype.is_int_mm",
  2363. "torch._higher_order_ops.out_dtype.out_dtype_dense",
  2364. "torch._higher_order_ops.out_dtype.out_dtype_fake_tensor_mode",
  2365. "torch._higher_order_ops.out_dtype.out_dtype_fallback",
  2366. "torch._higher_order_ops.out_dtype.out_dtype_func",
  2367. "torch._higher_order_ops.out_dtype.out_dtype_proxy",
  2368. "torch._higher_order_ops.out_dtype.trace_out_dtype",
  2369. "torch._higher_order_ops.utils.autograd_not_implemented_inner",
  2370. "torch._higher_order_ops.utils.autograd_not_implemented",
  2371. "torch._linalg_utils._symeig",
  2372. "torch._linalg_utils.basis",
  2373. "torch._linalg_utils.bform",
  2374. "torch._linalg_utils.eig",
  2375. "torch._linalg_utils.get_floating_dtype",
  2376. "torch._linalg_utils.is_sparse",
  2377. "torch._linalg_utils.lstsq",
  2378. "torch._linalg_utils.matmul",
  2379. "torch._linalg_utils.matrix_rank",
  2380. "torch._linalg_utils.qform",
  2381. "torch._linalg_utils.solve",
  2382. "torch._linalg_utils.symeig",
  2383. "torch._load_global_deps",
  2384. "torch._lowrank._svd_lowrank",
  2385. "torch._lowrank.get_approximate_basis",
  2386. "torch._lowrank.pca_lowrank",
  2387. "torch._lowrank.svd_lowrank",
  2388. "torch._preload_cuda_deps",
  2389. "torch._register_device_module",
  2390. "torch._utils._dummy_type",
  2391. "torch._utils._flatten_dense_tensors",
  2392. "torch._utils._unflatten_dense_tensors",
  2393. "torch._weights_only_unpickler._get_allowed_globals",
  2394. "torch._weights_only_unpickler.load",
  2395. "torch.accelerator.current_accelerator",
  2396. "torch.accelerator.current_device_index",
  2397. "torch.accelerator.current_stream",
  2398. "torch.accelerator.device_count",
  2399. "torch.accelerator.is_available",
  2400. "torch.accelerator.set_stream",
  2401. "torch.accelerator.synchronize",
  2402. "torch.align_tensors",
  2403. "torch.amp.autocast_mode._enter_autocast",
  2404. "torch.amp.autocast_mode._exit_autocast",
  2405. "torch.amp.autocast_mode.autocast_decorator",
  2406. "torch.amp.autocast_mode.custom_bwd",
  2407. "torch.amp.autocast_mode.custom_fwd",
  2408. "torch.are_deterministic_algorithms_enabled",
  2409. "torch.atleast_1d",
  2410. "torch.atleast_2d",
  2411. "torch.atleast_3d",
  2412. "torch.autograd._calculate_shape",
  2413. "torch.autograd._is_checkpoint_valid",
  2414. "torch.autograd._make_grads",
  2415. "torch.autograd._register_py_tensor_class_for_device",
  2416. "torch.autograd._tensor_or_tensors_to_tuple",
  2417. "torch.autograd.forward_ad._maybe_load_decompositions",
  2418. "torch.autograd.function._iter_filter",
  2419. "torch.autograd.function._iter_jit_values",
  2420. "torch.autograd.function._iter_None_tensors",
  2421. "torch.autograd.function._iter_tensors_permissive",
  2422. "torch.autograd.function._iter_tensors",
  2423. "torch.autograd.function._jit_unwrap_structured",
  2424. "torch.autograd.function._map_tensor_data",
  2425. "torch.autograd.function._nested_map",
  2426. "torch.autograd.function._unflatten",
  2427. "torch.autograd.function.once_differentiable",
  2428. "torch.autograd.function.traceable",
  2429. "torch.autograd.functional._as_tuple_nocheck",
  2430. "torch.autograd.functional._as_tuple",
  2431. "torch.autograd.functional._autograd_grad",
  2432. "torch.autograd.functional._check_requires_grad",
  2433. "torch.autograd.functional._construct_standard_basis_for",
  2434. "torch.autograd.functional._fill_in_zeros",
  2435. "torch.autograd.functional._grad_postprocess",
  2436. "torch.autograd.functional._grad_preprocess",
  2437. "torch.autograd.functional._jacfwd",
  2438. "torch.autograd.functional._tuple_postprocess",
  2439. "torch.autograd.functional._validate_v",
  2440. "torch.autograd.functional.hessian",
  2441. "torch.autograd.functional.hvp",
  2442. "torch.autograd.functional.jacobian",
  2443. "torch.autograd.functional.jvp",
  2444. "torch.autograd.functional.vhp",
  2445. "torch.autograd.functional.vjp",
  2446. "torch.autograd.grad_mode._enter_inference_mode",
  2447. "torch.autograd.grad_mode._exit_inference_mode",
  2448. "torch.autograd.graph._get_sid",
  2449. "torch.autograd.graph._get_tid",
  2450. "torch.autograd.graph.allow_mutation_on_saved_tensors",
  2451. "torch.autograd.graph.get_gradient_edge",
  2452. "torch.autograd.graph.increment_version",
  2453. "torch.autograd.graph.register_multi_grad_hook",
  2454. "torch.autograd.variable",
  2455. "torch.backends.__allow_nonbracketed_mutation",
  2456. "torch.backends.cpu.get_cpu_capability",
  2457. "torch.backends.cuda.can_use_efficient_attention",
  2458. "torch.backends.cuda.can_use_flash_attention",
  2459. "torch.backends.cuda.can_use_cudnn_attention",
  2460. "torch.backends.cuda.enable_flash_sdp",
  2461. "torch.backends.cuda.enable_math_sdp",
  2462. "torch.backends.cuda.allow_fp16_bf16_reduction_math_sdp",
  2463. "torch.backends.cuda.enable_mem_efficient_sdp",
  2464. "torch.backends.cuda.flash_sdp_enabled",
  2465. "torch.backends.cuda.is_built",
  2466. "torch.backends.cuda.is_flash_attention_available",
  2467. "torch.backends.cuda.math_sdp_enabled",
  2468. "torch.backends.cuda.fp16_bf16_reduction_math_sdp_allowed",
  2469. "torch.backends.cuda.mem_efficient_sdp_enabled",
  2470. "torch.backends.cuda.cudnn_sdp_enabled",
  2471. "torch.backends.cuda.enable_cudnn_sdp",
  2472. "torch.backends.cuda.preferred_blas_library",
  2473. "torch.backends.cuda.preferred_linalg_library",
  2474. "torch.backends.cuda.preferred_rocm_fa_library",
  2475. "torch.backends.cuda.sdp_kernel",
  2476. "torch.backends.cudnn._init",
  2477. "torch.backends.cudnn.flags",
  2478. "torch.backends.cudnn.is_acceptable",
  2479. "torch.backends.cudnn.is_available",
  2480. "torch.backends.cudnn.set_flags",
  2481. "torch.backends.cudnn.version",
  2482. "torch.backends.disable_global_flags",
  2483. "torch.backends.flags_frozen",
  2484. "torch.backends.mkl.is_available",
  2485. "torch.backends.mkldnn.flags",
  2486. "torch.backends.mkldnn.is_available",
  2487. "torch.backends.mkldnn.set_flags",
  2488. "torch.backends.mps._init",
  2489. "torch.backends.mps.is_available",
  2490. "torch.backends.mps.is_built",
  2491. "torch.backends.mps.is_macos13_or_newer",
  2492. "torch.backends.openmp.is_available",
  2493. "torch.backends.quantized._get_qengine_id",
  2494. "torch.backends.quantized._get_qengine_str",
  2495. "torch.block_diag",
  2496. "torch.broadcast_tensors",
  2497. "torch.cartesian_prod",
  2498. "torch.cdist",
  2499. "torch.chain_matmul",
  2500. "torch.compile",
  2501. "torch.compiled_with_cxx11_abi",
  2502. "torch._C._cpu._is_avx2_supported",
  2503. "torch._C._cpu._is_avx512_supported",
  2504. "torch._C._cpu._is_avx512_vnni_supported",
  2505. "torch._C._cpu._is_avx512_bf16_supported",
  2506. "torch._C._cpu._is_amx_tile_supported",
  2507. "torch._C._cpu._is_amx_fp16_supported",
  2508. "torch.cpu._init_amx",
  2509. "torch.cpu.current_device",
  2510. "torch.cpu.current_stream",
  2511. "torch.cpu.device_count",
  2512. "torch.cpu.is_available",
  2513. "torch.cpu.set_device",
  2514. "torch.cpu.stream",
  2515. "torch.cpu.synchronize",
  2516. "torch.cuda._check_capability",
  2517. "torch.cuda._check_cubins",
  2518. "torch.cuda._device_count_amdsmi",
  2519. "torch.cuda._device_count_nvml",
  2520. "torch.cuda._get_amdsmi_handler",
  2521. "torch.cuda._get_amdsmi_device_index",
  2522. "torch.cuda._get_device",
  2523. "torch.cuda._get_generator",
  2524. "torch.cuda._get_nvml_device_index",
  2525. "torch.cuda._get_pynvml_handler",
  2526. "torch.cuda._get_rng_state_offset",
  2527. "torch.cuda._is_compiled",
  2528. "torch.cuda._lazy_call",
  2529. "torch.cuda._lazy_init",
  2530. "torch.cuda._memory_viz._block_extra_legacy",
  2531. "torch.cuda._memory_viz._block_extra",
  2532. "torch.cuda._memory_viz._format_size",
  2533. "torch.cuda._memory_viz._format_viz",
  2534. "torch.cuda._memory_viz._frame_filter",
  2535. "torch.cuda._memory_viz._frame_fmt",
  2536. "torch.cuda._memory_viz._frames_fmt",
  2537. "torch.cuda._memory_viz._profile_to_snapshot",
  2538. "torch.cuda._memory_viz._report_free",
  2539. "torch.cuda._memory_viz._write_blocks",
  2540. "torch.cuda._memory_viz.calc_active",
  2541. "torch.cuda._memory_viz.compare",
  2542. "torch.cuda._memory_viz.format_flamegraph",
  2543. "torch.cuda._memory_viz.memory",
  2544. "torch.cuda._memory_viz.profile_plot",
  2545. "torch.cuda._memory_viz.segment_plot",
  2546. "torch.cuda._memory_viz.segments",
  2547. "torch.cuda._memory_viz.segsum",
  2548. "torch.cuda._memory_viz.trace_plot",
  2549. "torch.cuda._memory_viz.trace",
  2550. "torch.cuda._nvml_based_avail",
  2551. "torch.cuda._parse_visible_devices",
  2552. "torch.cuda._raw_device_count_amdsmi",
  2553. "torch.cuda._raw_device_count_nvml",
  2554. "torch.cuda._raw_device_uuid_amdsmi",
  2555. "torch.cuda._raw_device_uuid_nvml",
  2556. "torch.cuda._register_triton_kernels",
  2557. "torch.cuda._set_rng_state_offset",
  2558. "torch.cuda._set_stream_by_id",
  2559. "torch.cuda._sleep",
  2560. "torch.cuda._transform_uuid_to_ordinals",
  2561. "torch.cuda._utils._get_device_index",
  2562. "torch.cuda.amp.autocast_mode._cast",
  2563. "torch.cuda.amp.autocast_mode.custom_bwd",
  2564. "torch.cuda.amp.autocast_mode.custom_fwd",
  2565. "torch.cuda.amp.common.amp_definitely_not_available",
  2566. "torch.amp.grad_scaler._refresh_per_optimizer_state",
  2567. "torch.cuda.can_device_access_peer",
  2568. "torch.cuda.check_error",
  2569. "torch.cuda.clock_rate",
  2570. "torch.cuda.cudart",
  2571. "torch.cuda.current_blas_handle",
  2572. "torch.cuda.current_stream",
  2573. "torch.cuda.default_stream",
  2574. "torch.cuda.device_count",
  2575. "torch.cuda.device_memory_used",
  2576. "torch.cuda.get_arch_list",
  2577. "torch.cuda.get_device_capability",
  2578. "torch.cuda.get_device_name",
  2579. "torch.cuda.get_device_properties",
  2580. "torch.cuda.get_gencode_flags",
  2581. "torch.cuda.get_sync_debug_mode",
  2582. "torch.cuda.graphs.graph_pool_handle",
  2583. "torch.cuda.graphs.is_current_stream_capturing",
  2584. "torch.cuda.graphs.make_graphed_callables",
  2585. "torch.cuda.init",
  2586. "torch.cuda.ipc_collect",
  2587. "torch.cuda.is_available",
  2588. "torch.cuda.is_bf16_supported",
  2589. "torch.cuda.is_initialized",
  2590. "torch.cuda.jiterator._create_jit_fn",
  2591. "torch.cuda.jiterator._create_multi_output_jit_fn",
  2592. "torch.cuda.memory_usage",
  2593. "torch.cuda.memory._dump_snapshot",
  2594. "torch.cuda.memory._free_mutex",
  2595. "torch.cuda.memory._get_current_allocator",
  2596. "torch.cuda.memory._host_allocator",
  2597. "torch.cuda.memory._record_memory_history_impl",
  2598. "torch.cuda.memory._record_memory_history_legacy",
  2599. "torch.cuda.memory._record_memory_history",
  2600. "torch.cuda.memory._save_memory_usage",
  2601. "torch.cuda.memory._save_segment_usage",
  2602. "torch.cuda.memory._set_allocator_settings",
  2603. "torch.cuda.memory._snapshot",
  2604. "torch.cuda.memory.caching_allocator_alloc",
  2605. "torch.cuda.memory.caching_allocator_delete",
  2606. "torch.cuda.memory.caching_allocator_enable",
  2607. "torch.cuda.memory.change_current_allocator",
  2608. "torch.cuda.memory.empty_cache",
  2609. "torch.cuda.memory.get_allocator_backend",
  2610. "torch.cuda.memory.get_per_process_memory_fraction",
  2611. "torch.cuda.memory.host_memory_stats_as_nested_dict",
  2612. "torch.cuda.memory.host_memory_stats",
  2613. "torch.cuda.memory.list_gpu_processes",
  2614. "torch.cuda.memory.max_memory_allocated",
  2615. "torch.cuda.memory.max_memory_cached",
  2616. "torch.cuda.memory.max_memory_reserved",
  2617. "torch.cuda.memory.mem_get_info",
  2618. "torch.cuda.memory.memory_allocated",
  2619. "torch.cuda.memory.memory_cached",
  2620. "torch.cuda.memory.memory_reserved",
  2621. "torch.cuda.memory.memory_snapshot",
  2622. "torch.cuda.memory.memory_stats_as_nested_dict",
  2623. "torch.cuda.memory.memory_stats",
  2624. "torch.cuda.memory.memory_summary",
  2625. "torch.cuda.memory.reset_accumulated_host_memory_stats",
  2626. "torch.cuda.memory.reset_accumulated_memory_stats",
  2627. "torch.cuda.memory.reset_max_memory_allocated",
  2628. "torch.cuda.memory.reset_max_memory_cached",
  2629. "torch.cuda.memory.reset_peak_host_memory_stats",
  2630. "torch.cuda.memory.reset_peak_memory_stats",
  2631. "torch.cuda.memory.set_per_process_memory_fraction",
  2632. "torch.cuda.nccl._check_sequence_type",
  2633. "torch.cuda.nccl.all_gather",
  2634. "torch.cuda.nccl.all_reduce",
  2635. "torch.cuda.nccl.broadcast",
  2636. "torch.cuda.nccl.init_rank",
  2637. "torch.cuda.nccl.is_available",
  2638. "torch.cuda.nccl.reduce_scatter",
  2639. "torch.cuda.nccl.reduce",
  2640. "torch.cuda.nccl.unique_id",
  2641. "torch.cuda.nccl.version",
  2642. "torch.cuda.nvtx.mark",
  2643. "torch.cuda.nvtx.range_end",
  2644. "torch.cuda.nvtx.range_pop",
  2645. "torch.cuda.nvtx.range_push",
  2646. "torch.cuda.nvtx.range_start",
  2647. "torch.cuda.nvtx.range",
  2648. "torch.cuda.power_draw",
  2649. "torch.cuda.profiler.init",
  2650. "torch.cuda.profiler.profile",
  2651. "torch.cuda.profiler.start",
  2652. "torch.cuda.profiler.stop",
  2653. "torch.cuda.random.get_rng_state_all",
  2654. "torch.cuda.random.initial_seed",
  2655. "torch.cuda.random.manual_seed_all",
  2656. "torch.cuda.random.manual_seed",
  2657. "torch.cuda.random.seed_all",
  2658. "torch.cuda.random.seed",
  2659. "torch.cuda.random.set_rng_state_all",
  2660. "torch.cuda.set_stream",
  2661. "torch.cuda.set_sync_debug_mode",
  2662. "torch.cuda.stream",
  2663. "torch.cuda.temperature",
  2664. "torch.cuda.utilization",
  2665. "torch.einsum",
  2666. "torch.functional._check_list_size",
  2667. "torch.functional._consecutive_return_counts",
  2668. "torch.functional._consecutive_return_inverse_false",
  2669. "torch.functional._consecutive_return_inverse_true",
  2670. "torch.functional._consecutive_return_inverse",
  2671. "torch.functional._consecutive_return_output",
  2672. "torch.functional._lu_impl",
  2673. "torch.functional._lu_no_infos",
  2674. "torch.functional._lu_with_infos",
  2675. "torch.functional._meshgrid",
  2676. "torch.functional._return_counts",
  2677. "torch.functional._return_inverse_false",
  2678. "torch.functional._return_inverse_true",
  2679. "torch.functional._return_inverse",
  2680. "torch.functional._return_output",
  2681. "torch.functional._unique_consecutive_impl",
  2682. "torch.functional._unique_impl",
  2683. "torch.functional._unravel_index",
  2684. "torch.functional.broadcast_shapes",
  2685. "torch.functional.lu",
  2686. "torch.functional.unique",
  2687. "torch.functional.unravel_index",
  2688. "torch.futures.collect_all",
  2689. "torch.futures.wait_all",
  2690. "torch.fx.experimental.const_fold.split_const_subgraphs",
  2691. "torch.fx.experimental.proxy_tensor.make_fx",
  2692. "torch.get_deterministic_debug_mode",
  2693. "torch.get_float32_matmul_precision",
  2694. "torch.is_deterministic_algorithms_warn_only_enabled",
  2695. "torch.is_storage",
  2696. "torch.is_tensor",
  2697. "torch.is_warn_always_enabled",
  2698. "torch.masked._ops._any",
  2699. "torch.masked._ops._apply_docstring_templates",
  2700. "torch.masked._ops._canonical_dim",
  2701. "torch.masked._ops._combine_input_and_mask",
  2702. "torch.masked._ops._generate_docstring",
  2703. "torch.masked._ops._input_mask",
  2704. "torch.masked._ops._output_mask",
  2705. "torch.masked._ops._reduction_identity",
  2706. "torch.masked._ops._sparse_coo_flatten_indices",
  2707. "torch.masked._ops._sparse_coo_scatter_reduction_helper",
  2708. "torch.masked._ops._sparse_coo_where",
  2709. "torch.masked._ops._sparse_csr_segment_reduction_helper",
  2710. "torch.masked._ops._sparse_csr_where",
  2711. "torch.masked._ops._std_var",
  2712. "torch.masked._ops._where",
  2713. "torch.masked._ops.amax",
  2714. "torch.masked._ops.amin",
  2715. "torch.masked._ops.argmax",
  2716. "torch.masked._ops.argmin",
  2717. "torch.masked._ops.corresponding_real_dtype",
  2718. "torch.masked._ops.cumprod",
  2719. "torch.masked._ops.cumsum",
  2720. "torch.masked._ops.log_softmax",
  2721. "torch.masked._ops.logaddexp",
  2722. "torch.masked._ops.logsumexp",
  2723. "torch.masked._ops.mean",
  2724. "torch.masked._ops.median",
  2725. "torch.masked._ops.norm",
  2726. "torch.masked._ops.normalize",
  2727. "torch.masked._ops.prod",
  2728. "torch.masked._ops.softmax",
  2729. "torch.masked._ops.softmin",
  2730. "torch.masked._ops.std",
  2731. "torch.masked._ops.sum",
  2732. "torch.masked._ops.var",
  2733. "torch.meshgrid",
  2734. "torch.mps._get_default_mps_generator",
  2735. "torch.mps.current_allocated_memory",
  2736. "torch.mps.driver_allocated_memory",
  2737. "torch.mps.empty_cache",
  2738. "torch.mps.get_rng_state",
  2739. "torch.mps.manual_seed",
  2740. "torch.mps.profiler.profile",
  2741. "torch.mps.profiler.start",
  2742. "torch.mps.profiler.stop",
  2743. "torch.mps.seed",
  2744. "torch.mps.set_per_process_memory_fraction",
  2745. "torch.mps.set_rng_state",
  2746. "torch.mps.synchronize",
  2747. "torch.nested._internal.nested_tensor.buffer_from_jagged",
  2748. "torch.nested._internal.nested_tensor.get_tensor_symint",
  2749. "torch.nested._internal.nested_tensor.is_expandable_to",
  2750. "torch.nested._internal.nested_tensor.jagged_from_list",
  2751. "torch.nested._internal.nested_tensor.jagged_from_tensor_and_lengths",
  2752. "torch.nested._internal.nested_tensor.nested_view_from_values_offsets",
  2753. "torch.nested._internal.nested_tensor.nested_view_from_values_offsets_lengths",
  2754. "torch.nested.as_nested_tensor",
  2755. "torch.nested.narrow",
  2756. "torch.nested.nested_tensor",
  2757. "torch.nn._reduction.get_enum",
  2758. "torch.nn._reduction.legacy_get_enum",
  2759. "torch.nn._reduction.legacy_get_string",
  2760. "torch.nn.factory_kwargs",
  2761. "torch.nn.functional.adaptive_avg_pool2d",
  2762. "torch.nn.functional.adaptive_avg_pool3d",
  2763. "torch.nn.functional.adaptive_max_pool1d_with_indices",
  2764. "torch.nn.functional.adaptive_max_pool1d",
  2765. "torch.nn.functional.adaptive_max_pool2d_with_indices",
  2766. "torch.nn.functional.adaptive_max_pool2d",
  2767. "torch.nn.functional.adaptive_max_pool3d_with_indices",
  2768. "torch.nn.functional.adaptive_max_pool3d",
  2769. "torch.nn.functional.affine_grid",
  2770. "torch.nn.functional.alpha_dropout",
  2771. "torch.nn.functional.assert_int_or_pair",
  2772. "torch.nn.functional.batch_norm",
  2773. "torch.nn.functional.binary_cross_entropy_with_logits",
  2774. "torch.nn.functional.binary_cross_entropy",
  2775. "torch.nn.functional.celu",
  2776. "torch.nn.functional.cosine_embedding_loss",
  2777. "torch.nn.functional.cross_entropy",
  2778. "torch.nn.functional.ctc_loss",
  2779. "torch.nn.functional.dropout",
  2780. "torch.nn.functional.dropout1d",
  2781. "torch.nn.functional.dropout2d",
  2782. "torch.nn.functional.dropout3d",
  2783. "torch.nn.functional.elu",
  2784. "torch.nn.functional.embedding_bag",
  2785. "torch.nn.functional.embedding",
  2786. "torch.nn.functional.feature_alpha_dropout",
  2787. "torch.nn.functional.fold",
  2788. "torch.nn.functional.fractional_max_pool2d_with_indices",
  2789. "torch.nn.functional.fractional_max_pool2d",
  2790. "torch.nn.functional.fractional_max_pool3d_with_indices",
  2791. "torch.nn.functional.fractional_max_pool3d",
  2792. "torch.nn.functional.gaussian_nll_loss",
  2793. "torch.nn.functional.glu",
  2794. "torch.nn.functional.grid_sample",
  2795. "torch.nn.functional.group_norm",
  2796. "torch.nn.functional.gumbel_softmax",
  2797. "torch.nn.functional.hardsigmoid",
  2798. "torch.nn.functional.hardswish",
  2799. "torch.nn.functional.hardtanh",
  2800. "torch.nn.functional.hinge_embedding_loss",
  2801. "torch.nn.functional.huber_loss",
  2802. "torch.nn.functional.instance_norm",
  2803. "torch.nn.functional.interpolate",
  2804. "torch.nn.functional.kl_div",
  2805. "torch.nn.functional.l1_loss",
  2806. "torch.nn.functional.layer_norm",
  2807. "torch.nn.functional.leaky_relu",
  2808. "torch.nn.functional.local_response_norm",
  2809. "torch.nn.functional.log_softmax",
  2810. "torch.nn.functional.lp_pool1d",
  2811. "torch.nn.functional.lp_pool2d",
  2812. "torch.nn.functional.margin_ranking_loss",
  2813. "torch.nn.functional.max_pool1d_with_indices",
  2814. "torch.nn.functional.max_pool1d",
  2815. "torch.nn.functional.max_pool2d_with_indices",
  2816. "torch.nn.functional.max_pool2d",
  2817. "torch.nn.functional.max_pool3d_with_indices",
  2818. "torch.nn.functional.max_pool3d",
  2819. "torch.nn.functional.max_unpool1d",
  2820. "torch.nn.functional.max_unpool2d",
  2821. "torch.nn.functional.max_unpool3d",
  2822. "torch.nn.functional.mish",
  2823. "torch.nn.functional.mse_loss",
  2824. "torch.nn.functional.multi_head_attention_forward",
  2825. "torch.nn.functional.multi_margin_loss",
  2826. "torch.nn.functional.multilabel_margin_loss",
  2827. "torch.nn.functional.multilabel_soft_margin_loss",
  2828. "torch.nn.functional.nll_loss",
  2829. "torch.nn.functional.normalize",
  2830. "torch.nn.functional.poisson_nll_loss",
  2831. "torch.nn.functional.relu",
  2832. "torch.nn.functional.relu6",
  2833. "torch.nn.functional.rrelu",
  2834. "torch.nn.functional.selu",
  2835. "torch.nn.functional.sigmoid",
  2836. "torch.nn.functional.silu",
  2837. "torch.nn.functional.smooth_l1_loss",
  2838. "torch.nn.functional.soft_margin_loss",
  2839. "torch.nn.functional.softmax",
  2840. "torch.nn.functional.softmin",
  2841. "torch.nn.functional.softsign",
  2842. "torch.nn.functional.tanh",
  2843. "torch.nn.functional.tanhshrink",
  2844. "torch.nn.functional.triplet_margin_loss",
  2845. "torch.nn.functional.unfold",
  2846. "torch.nn.functional.upsample_bilinear",
  2847. "torch.nn.functional.upsample_nearest",
  2848. "torch.nn.functional.upsample",
  2849. "torch.nn.grad._pair",
  2850. "torch.nn.grad._single",
  2851. "torch.nn.grad._triple",
  2852. "torch.nn.grad.conv1d_input",
  2853. "torch.nn.grad.conv1d_weight",
  2854. "torch.nn.grad.conv2d_input",
  2855. "torch.nn.grad.conv2d_weight",
  2856. "torch.nn.grad.conv3d_input",
  2857. "torch.nn.grad.conv3d_weight",
  2858. "torch.nn.modules.activation._is_make_fx_tracing",
  2859. "torch.nn.modules.utils._list_with_default",
  2860. "torch.nn.modules.utils._ntuple",
  2861. "torch.nn.modules.utils._quadruple",
  2862. "torch.nn.modules.utils._reverse_repeat_tuple",
  2863. "torch.nn.modules.utils.consume_prefix_in_state_dict_if_present",
  2864. "torch.nn.parameter.is_lazy",
  2865. "torch.norm",
  2866. "torch.quantization.default_eval_fn",
  2867. "torch.random._seed_custom_device",
  2868. "torch.random.fork_rng",
  2869. "torch.random.initial_seed",
  2870. "torch.random.seed",
  2871. "torch.return_types.pytree_register_structseq",
  2872. "torch.set_default_dtype",
  2873. "torch.set_default_tensor_type",
  2874. "torch.set_deterministic_debug_mode",
  2875. "torch.set_float32_matmul_precision",
  2876. "torch.set_warn_always",
  2877. "torch.signal.windows.windows._add_docstr",
  2878. "torch.signal.windows.windows._window_function_checks",
  2879. "torch.signal.windows.windows.bartlett",
  2880. "torch.signal.windows.windows.blackman",
  2881. "torch.signal.windows.windows.cosine",
  2882. "torch.signal.windows.windows.exponential",
  2883. "torch.signal.windows.windows.gaussian",
  2884. "torch.signal.windows.windows.general_cosine",
  2885. "torch.signal.windows.windows.general_hamming",
  2886. "torch.signal.windows.windows.hamming",
  2887. "torch.signal.windows.windows.hann",
  2888. "torch.signal.windows.windows.kaiser",
  2889. "torch.signal.windows.windows.merge_dicts",
  2890. "torch.signal.windows.windows.nuttall",
  2891. "torch.signal.windows.windows.parse_kwargs",
  2892. "torch.sparse.semi_structured.to_sparse_semi_structured",
  2893. "torch.sparse.sum",
  2894. "torch.split",
  2895. "torch.stft",
  2896. "torch.sym_float",
  2897. "torch.sym_int",
  2898. "torch.sym_ite",
  2899. "torch.sym_max",
  2900. "torch.sym_min",
  2901. "torch.sym_not",
  2902. "torch.tensordot",
  2903. "torch.unique_consecutive",
  2904. "torch.use_deterministic_algorithms",
  2905. "torch.xpu._get_device",
  2906. "torch.xpu._get_generator",
  2907. "torch.xpu._get_rng_state_offset",
  2908. "torch.xpu._is_compiled",
  2909. "torch.xpu._lazy_call",
  2910. "torch.xpu._lazy_init",
  2911. "torch.xpu._set_rng_state_offset",
  2912. "torch.xpu._set_stream_by_id",
  2913. "torch.xpu._utils._get_device_index",
  2914. "torch.xpu.current_device",
  2915. "torch.xpu.current_stream",
  2916. "torch.xpu.device_count",
  2917. "torch.xpu.get_arch_list",
  2918. "torch.xpu.get_device_capability",
  2919. "torch.xpu.get_device_name",
  2920. "torch.xpu.get_device_properties",
  2921. "torch.xpu.get_gencode_flags",
  2922. "torch.xpu.get_stream_from_external",
  2923. "torch.xpu.init",
  2924. "torch.xpu.is_available",
  2925. "torch.xpu.is_bf16_supported",
  2926. "torch.xpu.is_initialized",
  2927. "torch.xpu.memory.empty_cache",
  2928. "torch.xpu.memory.max_memory_allocated",
  2929. "torch.xpu.memory.max_memory_reserved",
  2930. "torch.xpu.memory.mem_get_info",
  2931. "torch.xpu.memory.memory_allocated",
  2932. "torch.xpu.memory.memory_reserved",
  2933. "torch.xpu.memory.memory_stats_as_nested_dict",
  2934. "torch.xpu.memory.memory_stats",
  2935. "torch.xpu.memory.reset_accumulated_memory_stats",
  2936. "torch.xpu.memory.reset_peak_memory_stats",
  2937. "torch.xpu.random.initial_seed",
  2938. "torch.xpu.random.seed_all",
  2939. "torch.xpu.random.seed",
  2940. "torch.xpu.set_stream",
  2941. "torch.xpu.stream",
  2942. "torch.xpu.synchronize",
  2943. ],
  2944. TorchInGraphFunctionVariable,
  2945. )
  2946. torch_name_rule_map = [
  2947. manual_torch_name_rule_map,
  2948. torch_c_binding_in_graph_functions,
  2949. torch_non_c_binding_in_graph_functions,
  2950. ]
  2951. """
  2952. Generate the torch object - Dynamo tracing rule (the wrapping variable) map.
  2953. """
  2954. @functools.cache
  2955. def get_torch_obj_rule_map() -> dict[Any, type["VariableTracker"]]:
  2956. d: dict[Any, type[VariableTracker]] = {}
  2957. for m in torch_name_rule_map:
  2958. for k, v in m.items(): # type: ignore[attr-defined]
  2959. if ".py#" not in k:
  2960. obj = load_object(k)
  2961. else:
  2962. torch_dir = _module_dir(torch)
  2963. if torch_dir is None:
  2964. continue
  2965. obj = torch_dir + k[len("torch/") :]
  2966. if obj is not None:
  2967. if is_lru_cache_wrapped_function(obj):
  2968. obj = obj.__wrapped__
  2969. if obj in d and d[obj] != v:
  2970. raise AssertionError(
  2971. f"Duplicate torch object {obj} with different rules: {v}, {d[obj]}"
  2972. )
  2973. else:
  2974. d[obj] = v
  2975. return d
  2976. def _load_obj_from_str(fully_qualified_name: str) -> Any:
  2977. module, obj_name = fully_qualified_name.rsplit(".", maxsplit=1)
  2978. return getattr(importlib.import_module(module), obj_name)
  2979. """
  2980. Load string represented torch objects.
  2981. """
  2982. def load_object(name: str) -> Any:
  2983. try:
  2984. x = name.split("#")
  2985. if len(x) == 2:
  2986. obj = _load_obj_from_str(x[0])
  2987. val = getattr(obj, x[1])
  2988. else:
  2989. assert len(x) == 1, f"Invalid obj name {name}"
  2990. val = _load_obj_from_str(x[0])
  2991. val = unwrap_if_wrapper(val)
  2992. except (AttributeError, ImportError):
  2993. val = None
  2994. return val
  2995. """
  2996. Get all torch.Tensor methods which are allowed to be in graph functions.
  2997. """
  2998. @functools.cache
  2999. def get_tensor_method() -> frozenset[Any]:
  3000. disallowed_tensor_methods = {"__new__", "_make_wrapper_subclass", "_make_subclass"}
  3001. s = set()
  3002. for name in dir(torch.Tensor):
  3003. method = getattr(torch.Tensor, name)
  3004. if (
  3005. isinstance(
  3006. method,
  3007. (
  3008. types.MethodDescriptorType,
  3009. types.WrapperDescriptorType,
  3010. types.BuiltinFunctionType,
  3011. ),
  3012. )
  3013. and name not in disallowed_tensor_methods
  3014. ):
  3015. s.add(method)
  3016. # mlazos: these are functions which we handle specially in TensorVariable
  3017. s.add(torch.Tensor.__contains__) # type: ignore[arg-type]
  3018. s.add(torch.Tensor.register_hook) # type: ignore[arg-type]
  3019. return frozenset(s)
  3020. """
  3021. Return if a torch object is ATen op or torch.Tensor method.
  3022. """
  3023. def is_aten_op_or_tensor_method(obj: Any) -> bool:
  3024. return obj in get_tensor_method() or isinstance(
  3025. obj,
  3026. (torch._ops.OpOverloadPacket, torch._ops.OpOverload),
  3027. )
  3028. class FunctionIdSet:
  3029. """
  3030. Track a set of `id()`s of objects which are either allowed or not
  3031. allowed to go into the generated FX graph. Use to test for torch.*,
  3032. numpy.*, builtins.*, etc.
  3033. Support user modification to permit customization of what can be
  3034. added to the graph and what will cause a graph break.
  3035. """
  3036. function_ids: Optional[set[int]] = None
  3037. function_names: Optional[dict[int, str]] = None
  3038. def __init__(
  3039. self, lazy_initializer: Callable[[], Union[dict[int, str], set[int]]]
  3040. ) -> None:
  3041. self.lazy_initializer = lazy_initializer
  3042. def __call__(self) -> set[int]:
  3043. if self.function_ids is None:
  3044. value = self.lazy_initializer()
  3045. if isinstance(value, dict):
  3046. self.function_ids = set(value.keys())
  3047. self.function_names = value
  3048. else:
  3049. assert isinstance(value, set)
  3050. self.function_ids = value
  3051. return self.function_ids
  3052. def get_name(self, idx: int, default: str) -> str:
  3053. self() # lazy init
  3054. assert self.function_names is not None
  3055. return self.function_names.get(idx, default)
  3056. def add(self, idx: int) -> None:
  3057. function_ids = self() # lazy init
  3058. function_ids.add(idx)
  3059. def remove(self, idx: int) -> None:
  3060. function_ids = self()
  3061. if idx in function_ids:
  3062. function_ids.remove(idx)
  3063. def __contains__(self, idx: int) -> bool:
  3064. return idx in self()
  3065. @FunctionIdSet
  3066. def _allowed_callable_ids() -> dict[int, str]:
  3067. rv: dict[int, str] = {}
  3068. return rv
  3069. @FunctionIdSet
  3070. def _disallowed_callable_ids() -> dict[int, str]:
  3071. rv: dict[int, str] = {}
  3072. return rv
  3073. @FunctionIdSet
  3074. def _nonstrict_trace_callable_ids() -> dict[int, str]:
  3075. rv: dict[int, str] = {}
  3076. return rv
  3077. @FunctionIdSet
  3078. def _builtin_function_ids() -> dict[int, str]:
  3079. # See also torch/_dynamo/polyfills/loader.py, which removes items in _builtin_function_ids
  3080. rv = {
  3081. id(v): f"builtins.{k}"
  3082. for k, v in builtins.__dict__.items()
  3083. if not k.startswith("_") and callable(v)
  3084. }
  3085. rv.update(
  3086. {
  3087. id(v): f"operator.{k}"
  3088. for k, v in operator.__dict__.items()
  3089. if not k.startswith("_") and callable(v)
  3090. }
  3091. )
  3092. rv.update(
  3093. {
  3094. id(cast): "typing.cast",
  3095. id(copy.deepcopy): "copy.deepcopy",
  3096. }
  3097. )
  3098. return rv
  3099. @FunctionIdSet
  3100. def _polyfilled_function_ids() -> set[int]:
  3101. # See also @torch._dynamo.decorators.substitute_in_graph(...), which adds items in _polyfilled_function_ids
  3102. return set()
  3103. @FunctionIdSet
  3104. def _numpy_function_ids() -> dict[int, str]:
  3105. unsupported_funcs = {
  3106. "seed",
  3107. "ranf",
  3108. "get_bit_generator",
  3109. "RandomState",
  3110. "set_bit_generator",
  3111. "sample",
  3112. }
  3113. def is_supported(k: str, v: Any, mod: Any) -> bool:
  3114. if not callable(v):
  3115. return False
  3116. if not getattr(v, "__module__", None):
  3117. return True
  3118. if v.__module__ == mod.__name__:
  3119. return True
  3120. if (
  3121. v.__module__ == "numpy.random.mtrand"
  3122. and mod.__name__ == "numpy.random"
  3123. and k not in unsupported_funcs
  3124. ):
  3125. return True
  3126. return False
  3127. rv = {}
  3128. for mod in NP_SUPPORTED_MODULES:
  3129. for k, v in mod.__dict__.items():
  3130. if is_supported(k, v, mod):
  3131. rv[id(v)] = f"{mod.__name__}.{k}"
  3132. return rv
  3133. @FunctionIdSet
  3134. def _builtin_constant_ids() -> dict[int, str]:
  3135. """
  3136. Collects constant builtins by eliminating callable items.
  3137. """
  3138. rv = {
  3139. id(v): f"builtins.{k}"
  3140. for k, v in builtins.__dict__.items()
  3141. if not k.startswith("_") and not callable(v)
  3142. }
  3143. return rv
  3144. _lazy_module_init: dict[str, list[Callable[[], None]]] = defaultdict(list)
  3145. def add_module_init_func(name: str, init_func: Callable[[], None]) -> None:
  3146. """Register a module without eagerly importing it"""
  3147. # If the module is already imported, eagerly run init
  3148. assert "." not in name, f"Expected a root module name, but got {name}"
  3149. assert name not in _lazy_module_init
  3150. _lazy_module_init[name].append(init_func)
  3151. def _maybe_init_lazy_module(obj: object) -> None:
  3152. module = getattr(obj, "__module__", None)
  3153. if module is None:
  3154. return
  3155. base_module = module.split(".")[0]
  3156. init_funcs = _lazy_module_init.pop(base_module, None)
  3157. if init_funcs is not None:
  3158. for fn in init_funcs:
  3159. fn()
  3160. def is_callable_allowed(obj: Any) -> bool:
  3161. _maybe_init_lazy_module(obj)
  3162. return id(obj) in _allowed_callable_ids
  3163. def is_nonstrict_trace_callable(obj: Any) -> bool:
  3164. _maybe_init_lazy_module(obj)
  3165. return id(obj) in _nonstrict_trace_callable_ids
  3166. def is_callable_disallowed(obj: Any) -> bool:
  3167. _maybe_init_lazy_module(obj)
  3168. return id(obj) in _disallowed_callable_ids
  3169. def is_forbidden(obj: Any) -> bool:
  3170. _maybe_init_lazy_module(obj)
  3171. return inspect.getattr_static(obj, "_dynamo_forbidden", False)
  3172. def is_builtin_callable(obj: Any) -> bool:
  3173. # See also torch/_dynamo/polyfills/loader.py, which removes items in _builtin_function_ids
  3174. return id(obj) in _builtin_function_ids
  3175. def is_builtin_constant(obj: Any) -> bool:
  3176. return id(obj) in _builtin_constant_ids
  3177. def is_polyfilled_callable(obj: Any) -> bool:
  3178. # See also @torch._dynamo.decorators.substitute_in_graph(...), which adds items in _polyfilled_function_ids
  3179. return id(obj) in _polyfilled_function_ids
  3180. def is_numpy(obj: Any) -> bool:
  3181. if np is None:
  3182. return False
  3183. return isinstance(obj, (np.ndarray, np.generic)) or id(obj) in _numpy_function_ids
  3184. def is_numpy_dtype(obj: Any) -> bool:
  3185. if np is None:
  3186. return False
  3187. return isinstance(obj, np.dtype)
  3188. def is_numpy_type_info(obj: Any) -> bool:
  3189. if np is None:
  3190. return False
  3191. return isinstance(obj, (np.finfo, np.iinfo))
  3192. BUILTIN_SKIPLIST = (
  3193. abc,
  3194. copy,
  3195. random,
  3196. traceback,
  3197. linecache,
  3198. )
  3199. # third party libraries skiplist is defined by str, because users may not use these libraries.
  3200. # we should use lazy import & skip in the future.
  3201. THIRDPARTY_SKIPLIST = (
  3202. "fx2trt_oss",
  3203. "hypothesis",
  3204. "networkx",
  3205. "numpy",
  3206. "onnx",
  3207. "onnxruntime",
  3208. "onnx_tf",
  3209. "pandas",
  3210. "sklearn",
  3211. "tabulate",
  3212. "tensorflow",
  3213. "tensorrt",
  3214. "torch2trt",
  3215. "tqdm",
  3216. "tree",
  3217. "tvm",
  3218. "xarray",
  3219. )
  3220. def _as_posix_path(path: str) -> str:
  3221. posix_path = Path(os.path.normpath(path)).as_posix()
  3222. # os.path.normpath and pathlib.Path remove trailing slash, so we need to add it back
  3223. if path.endswith((os.path.sep, "/")):
  3224. posix_path += "/"
  3225. return posix_path
  3226. def _strip_init_py(s: str) -> str:
  3227. suffix = "__init__.py"
  3228. s = s.removesuffix(suffix)
  3229. return _as_posix_path(s)
  3230. def _module_dir(m: types.ModuleType) -> Optional[str]:
  3231. # Protect against a module not exporting __file__ - this can happen for
  3232. # frozen modules, for example.
  3233. file = getattr(m, "__file__", None)
  3234. return file and _strip_init_py(file)
  3235. # These are legacy workarounds, don't add new modules to this list.
  3236. # Please use the MOD_INLINELIST instead to force inline functions under particular modules.
  3237. #
  3238. # NB: The only thing that is different about MOD_INLINELIST and LEGACY_MOD_INLINELIST
  3239. # is the behavior of a function f2 in the module when called by a function f1
  3240. # in a module in MOD_SKIPLIST (see MOD_SKIPLIST for more details)
  3241. #
  3242. # LEGACY_MOD_INLINELIST is the same thing as Dynamo's behavior on a module that
  3243. # is not in any *_INLINELIST or *_SKIPLIST.
  3244. # That being said, we prefer people to add things to MOD_INLINELIST over
  3245. # LEGACY_MOD_INLINELIST because it is less likely to break existing tests.
  3246. LEGACY_MOD_INLINELIST = {
  3247. "torch._dynamo.external_utils",
  3248. "torch._export.db.examples",
  3249. "torch._export.wrappers",
  3250. "torch._functorch.apis",
  3251. "torch._functorch.deprecated",
  3252. "torch.nn.attention.flex_attention",
  3253. "torch.ao.quantization.pt2e.export_utils",
  3254. "torch.ao.quantization.pt2e.qat_utils",
  3255. "torch.ao.quantization.pt2e.representation.rewrite",
  3256. "torch.ao.quantization.pt2e.utils",
  3257. "torch.ao.quantization.quantizer.xnnpack_quantizer",
  3258. "torch.export.unflatten",
  3259. }
  3260. if torch.distributed.is_available():
  3261. LEGACY_MOD_INLINELIST |= {
  3262. "torch.distributed.tensor._api",
  3263. "torch.distributed.tensor.device_mesh",
  3264. "torch.distributed.device_mesh",
  3265. "torch.distributed.algorithms._checkpoint.checkpoint_wrapper",
  3266. "torch.distributed.tensor.parallel._data_parallel_utils",
  3267. "torch.distributed.tensor.parallel._utils",
  3268. "torch.distributed.tensor.parallel.style",
  3269. # we have to add replicate to LEGACY_MOD_INLINELIST to ensure
  3270. # the forward_hook won't be ignored.
  3271. "torch.distributed._composable.replicate",
  3272. }
  3273. if not config.skip_fsdp_hooks:
  3274. LEGACY_MOD_INLINELIST.add("torch.distributed.fsdp._fully_shard")
  3275. # Force inline functions under these modules, even they are in *_SKIPLIST.
  3276. # We are using python module name instead of file or directory object to avoid circular dependency.
  3277. # Please keep this sorted alphabetically.
  3278. #
  3279. # Btw, it is not "ideal" for something to be in MOD_INLINELIST. If Dynamo
  3280. # fully supports a module, then the ideal case is that it is not in
  3281. # any *_INLINELIST or *_SKIPLIST: then, the behavior of Dynamo is that
  3282. # it will always inline into functions in the module.
  3283. MOD_INLINELIST = [
  3284. "torch._decomp",
  3285. "torch._dynamo._trace_wrapped_higher_order_op",
  3286. "torch._dynamo.compiled_autograd",
  3287. "torch._dynamo.comptime",
  3288. "torch._dynamo.polyfills",
  3289. "torch._dynamo.test_case",
  3290. "torch._functorch._aot_autograd.subclass_parametrization",
  3291. "torch._functorch.autograd_function",
  3292. "torch._functorch.eager_transforms",
  3293. "torch._functorch.functional_call",
  3294. "torch._functorch.pyfunctorch",
  3295. "torch._functorch.vmap",
  3296. "torch._inductor.test_operators",
  3297. "torch._library.autograd",
  3298. "torch._library.custom_ops",
  3299. "torch._ops",
  3300. "torch._prims",
  3301. "torch._refs",
  3302. "torch._tensor",
  3303. "torch.amp.autocast_mode",
  3304. "torch.ao.nn",
  3305. "torch.autograd.function",
  3306. "torch.backends.cuda",
  3307. "torch.cuda.amp.autocast_mode",
  3308. "torch.distributions",
  3309. "torch.export._tree_utils",
  3310. "torch.export._wrapper_utils",
  3311. "torch.fx._pytree",
  3312. "torch.fx._symbolic_trace",
  3313. "torch.fx.experimental.proxy_tensor",
  3314. "torch.fx.passes.shape_prop",
  3315. "torch.nn",
  3316. "torch.overrides",
  3317. "torch.random",
  3318. "torch.return_types",
  3319. "torch.sparse",
  3320. "torch.testing",
  3321. "torch.utils._content_store",
  3322. "torch.utils._contextlib",
  3323. "torch.utils._cxx_pytree",
  3324. "torch.utils._device",
  3325. "torch.utils._foreach_utils",
  3326. "torch.utils._python_dispatch",
  3327. "torch.utils._pytree",
  3328. "torch.utils.hooks",
  3329. ]
  3330. assert sorted(set(MOD_INLINELIST)) == MOD_INLINELIST
  3331. MOD_INLINELIST = set(MOD_INLINELIST)
  3332. if torch.distributed.is_available():
  3333. MOD_INLINELIST.add("torch.distributed")
  3334. if not config.skip_fsdp_hooks:
  3335. MOD_INLINELIST.add("torch.distributed.fsdp._fully_shard")
  3336. # By default, all functions under these modules are skipped.
  3337. # All the other knobs
  3338. # (torch_name_rule_map, MOD_INLINELIST, LEGACY_MOD_INLINELIST)
  3339. # take precedence over this list; e.g. if a function is in
  3340. # MOD_INLINELIST and MOD_SKIPLIST, then it will be inlined.
  3341. # See "A note on skip/inline rules" for more details.
  3342. #
  3343. # The skip is NOT recursive. If a function f1 in a module in MOD_SKIPLIST
  3344. # calls out to another function f2 in some other module, then Dynamo's
  3345. # behavior (skip/inline) depends on what we've marked f2 as:
  3346. # - if f2 is a function in a module in MOD_SKIPLIST, then we skip f2
  3347. # - if f2 is a function in a module in MOD_INLINELIST, then we skip f2
  3348. # - if f2 is a function in a module in LEGACY_MOD_INLINELIST, then we inline f2
  3349. # - if f2 is a function in a module not in any *_LIST, then we inline f2
  3350. MOD_SKIPLIST = [
  3351. "torch._VF",
  3352. "torch.__future__",
  3353. "torch.__init__",
  3354. "torch._awaits",
  3355. "torch._classes",
  3356. "torch._compile",
  3357. "torch._custom_op",
  3358. "torch._custom_ops",
  3359. "torch._decomp",
  3360. "torch._dispatch",
  3361. "torch._dynamo",
  3362. "torch._export",
  3363. "torch._functorch",
  3364. "torch._guards",
  3365. "torch._higher_order_ops.effects",
  3366. "torch._higher_order_ops.torchbind",
  3367. "torch._higher_order_ops.wrap",
  3368. "torch._inductor",
  3369. "torch._jit_internal",
  3370. "torch._lazy",
  3371. "torch._library",
  3372. "torch._linalg_utils",
  3373. "torch._lobpcg",
  3374. "torch._logging",
  3375. "torch._lowrank",
  3376. "torch._meta_registrations",
  3377. "torch._namedtensor_internals",
  3378. "torch._numpy",
  3379. "torch._ops",
  3380. "torch._prims",
  3381. "torch._prims_common",
  3382. "torch._python_dispatcher",
  3383. "torch._refs",
  3384. "torch._strobelight",
  3385. "torch._subclasses",
  3386. "torch._tensor",
  3387. "torch._tensor_str",
  3388. "torch._thread_safe_fork",
  3389. "torch._utils",
  3390. "torch._utils_internal",
  3391. "torch._vmap_internals",
  3392. "torch._weights_only_unpickler",
  3393. "torch.accelerator",
  3394. "torch.amp",
  3395. "torch.ao",
  3396. "torch.autograd",
  3397. "torch.backends",
  3398. "torch.compiler",
  3399. "torch.contrib",
  3400. "torch.cpu",
  3401. "torch.cuda",
  3402. "torch.distributed",
  3403. "torch.distributions",
  3404. "torch.export",
  3405. "torch.fb",
  3406. "torch.fft",
  3407. "torch.functional",
  3408. "torch.futures",
  3409. "torch.fx",
  3410. "torch.hub",
  3411. "torch.jit",
  3412. "torch.library",
  3413. "torch.linalg",
  3414. "torch.masked",
  3415. "torch.monitor",
  3416. "torch.mps",
  3417. "torch.mtia",
  3418. "torch.multiprocessing",
  3419. "torch.nested",
  3420. "torch.nn",
  3421. "torch.onnx",
  3422. "torch.overrides",
  3423. "torch.package",
  3424. "torch.profiler",
  3425. "torch.quantization",
  3426. "torch.quasirandom",
  3427. "torch.random",
  3428. "torch.serialization",
  3429. "torch.signal",
  3430. "torch.sparse",
  3431. "torch.special",
  3432. "torch.storage",
  3433. "torch.testing",
  3434. "torch.types",
  3435. "torch.utils",
  3436. "torch.xpu",
  3437. ]
  3438. assert sorted(set(MOD_SKIPLIST)) == MOD_SKIPLIST
  3439. MOD_SKIPLIST = set(MOD_SKIPLIST)
  3440. @functools.cache
  3441. def get_legacy_mod_inlinelist() -> set[str]:
  3442. torch_dir = _module_dir(torch)
  3443. if torch_dir is None:
  3444. return set()
  3445. inlinelist = {
  3446. _as_posix_path(torch_dir + m[len("torch.") :].replace(".", "/"))
  3447. for m in LEGACY_MOD_INLINELIST
  3448. }
  3449. return inlinelist
  3450. @functools.cache
  3451. def get_mod_inlinelist() -> set[str]:
  3452. torch_dir = _module_dir(torch)
  3453. if torch_dir is None:
  3454. return set()
  3455. inlinelist = {
  3456. _as_posix_path(torch_dir + m[len("torch.") :].replace(".", "/"))
  3457. for m in MOD_INLINELIST
  3458. }
  3459. return inlinelist
  3460. @functools.cache
  3461. def get_mod_skiplist() -> set[str]:
  3462. torch_dir = _module_dir(torch)
  3463. if torch_dir is None:
  3464. return set()
  3465. skiplist = {
  3466. _as_posix_path(torch_dir + m[len("torch.") :].replace(".", "/"))
  3467. for m in MOD_SKIPLIST
  3468. }
  3469. return skiplist
  3470. # skip some standard python builtin libs
  3471. SKIP_DIRS = [
  3472. "<frozen importlib",
  3473. "<frozen abc",
  3474. "<__array_function__ internals>",
  3475. _as_posix_path(_config_module.__file__),
  3476. "triton/backends",
  3477. ]
  3478. SKIP_DIRS.extend(map(_as_posix_path, filter(None, map(_module_dir, BUILTIN_SKIPLIST))))
  3479. SKIP_DIRS_RE = re.compile(r"match nothing^")
  3480. # Skip fbcode paths(including torch.package paths) containing
  3481. # one of the following strings.
  3482. FBCODE_SKIP_DIRS: set[str] = set()
  3483. FBCODE_SKIP_DIRS_RE = re.compile(f".*({'|'.join(map(re.escape, FBCODE_SKIP_DIRS))})")
  3484. # Remove this after fbcode is fully migrated to tracing through torchrec.
  3485. FBCODE_SKIP_TORCHREC_DIRS = {
  3486. "torchrec/distributed",
  3487. "torchrec/fb/distributed",
  3488. "caffe2/torch/fb/sparsenn/pooled_embeddings_modules.py",
  3489. }
  3490. FBCODE_SKIP_TORCHREC_DIRS_RE = re.compile(
  3491. f".*({'|'.join(re.escape(_as_posix_path(d)) for d in FBCODE_SKIP_TORCHREC_DIRS)})"
  3492. )
  3493. # TODO(yanboliang, anijain2305) - There are a few concerns that we should
  3494. # resolve
  3495. # 1) Audit if torchrec/distributed is even required in FBCODE_SKIPS_DIR
  3496. # 2) To inline just one file but skip others in a directory, we could use
  3497. # manual_torch_name_rule_map but this one is hard because FBCODE can add unusual
  3498. # names like torch_package.
  3499. # So, this is a stop gap solution till then.
  3500. FBCODE_INLINE_FILES_IN_SKIPPED_DIRS = {
  3501. "torchrec/distributed/types.py",
  3502. }
  3503. FBCODE_INLINE_FILES_IN_SKIPPED_DIRS_RE = re.compile(
  3504. f".*({'|'.join(re.escape(_as_posix_path(d)) for d in FBCODE_INLINE_FILES_IN_SKIPPED_DIRS)})"
  3505. )
  3506. # torch.optim is a special case,
  3507. # we usually want to inline it, but the directory
  3508. # structure does not match the module structure
  3509. # and we want to skip the functions in optim/lr_scheduler.py
  3510. # this has precedence over all other rules in check_file
  3511. FORCE_SKIP_FILES = {f"{_module_dir(torch)}optim/lr_scheduler.py"}
  3512. def _recompile_re() -> None:
  3513. global SKIP_DIRS_RE
  3514. SKIP_DIRS_RE = re.compile(
  3515. rf"^[^\s<]*({'|'.join(re.escape(_as_posix_path(d)) for d in SKIP_DIRS)})"
  3516. )
  3517. def add(import_name: str) -> None:
  3518. if isinstance(import_name, types.ModuleType):
  3519. return add(import_name.__name__)
  3520. assert isinstance(import_name, str)
  3521. from importlib.util import find_spec
  3522. module_spec = find_spec(import_name)
  3523. if not module_spec:
  3524. return
  3525. origin = module_spec.origin
  3526. if origin is None:
  3527. return
  3528. SKIP_DIRS.append(_strip_init_py(origin))
  3529. _recompile_re()
  3530. @dataclasses.dataclass
  3531. class SkipResult:
  3532. skipped: bool
  3533. reason: Optional[str]
  3534. def check_file(filename: Optional[str], is_inlined_call: bool = False) -> SkipResult:
  3535. """Should skip this file?"""
  3536. if filename is None:
  3537. return SkipResult(True, "filename is None")
  3538. filename = _as_posix_path(filename)
  3539. if filename in FORCE_SKIP_FILES:
  3540. return SkipResult(True, "FORCE_SKIP_FILES")
  3541. if any(filename.startswith(d) for d in get_legacy_mod_inlinelist()):
  3542. return SkipResult(
  3543. False,
  3544. "LEGACY_MOD_INLINELIST",
  3545. )
  3546. if is_inlined_call and is_torch_inline_allowed(filename):
  3547. return SkipResult(
  3548. False,
  3549. "MOD_INLINELIST",
  3550. )
  3551. if (
  3552. is_fbcode()
  3553. and FBCODE_SKIP_DIRS
  3554. and bool(FBCODE_SKIP_DIRS_RE.match(filename))
  3555. and not bool(FBCODE_INLINE_FILES_IN_SKIPPED_DIRS_RE.match(filename))
  3556. ):
  3557. return SkipResult(
  3558. True,
  3559. "FBCODE_SKIP_DIRS",
  3560. )
  3561. if (
  3562. is_fbcode()
  3563. and config.skip_torchrec
  3564. and FBCODE_SKIP_TORCHREC_DIRS
  3565. and bool(FBCODE_SKIP_TORCHREC_DIRS_RE.match(filename))
  3566. and not bool(FBCODE_INLINE_FILES_IN_SKIPPED_DIRS_RE.match(filename))
  3567. ):
  3568. return SkipResult(True, "FBCODE_SKIP_TORCHREC_DIRS")
  3569. unittest_dir = _module_dir(unittest)
  3570. if (
  3571. unittest_dir is not None
  3572. and filename.startswith(unittest_dir)
  3573. and not torch._dynamo.config.enable_trace_unittest
  3574. ):
  3575. return SkipResult(True, "unittest")
  3576. if bool(SKIP_DIRS_RE.match(filename)):
  3577. return SkipResult(True, "SKIP_DIRS")
  3578. if any(filename.startswith(d) for d in get_mod_skiplist()):
  3579. return SkipResult(True, "MOD_SKIPLIST")
  3580. return SkipResult(False, "inlined by default")
  3581. @dataclasses.dataclass
  3582. class FunctionInfo:
  3583. py_obj: Optional[object]
  3584. name: Optional[str]
  3585. filename: str
  3586. code: Optional[types.CodeType]
  3587. """
  3588. This is the main entry point to determine whether an object (function) should be inlined or skipped.
  3589. Let's illustrate the logic with an example:
  3590. @torch.compile
  3591. def f1(x, y):
  3592. ......
  3593. f2(x, y)
  3594. ......
  3595. def f2(x, y):
  3596. ......
  3597. f3(x, y)
  3598. ......
  3599. def f3(x, y):
  3600. ......
  3601. There are mainly three call sites of check/check_verbose:
  3602. * The compile region entrance (like function f1), the corresponding code is located at eval_frame.py.
  3603. * When tracing the recursively called functions (like function f2 and f3).
  3604. * Dynamo decides inline/skip every time it encounters a new recursively function call, and the call site
  3605. is in InliningInstructionTranslator.check_inlineable of symbolic_convert.py.
  3606. * If f2 is skipped by Dynamo, when evaluating the frame of f3, Dynamo need the inline/skip check again
  3607. and the call site is in catch_errors_wrapper.catch_errors of convert_frame.py.
  3608. * For global variables and function arguments, Dynamo needs to decide if they are wrapped as SkipFunctionVariable in builder.py.
  3609. `is_inlined_call` is used to indicate if the current function call is inlined (f2 is inlined call if it passes check)
  3610. or not (f3 is not inlined call if f2 is skipped). Inside of the `check_verbose` function, there are more rules
  3611. to be checked if this `is_inlined_call`.
  3612. The reason to have this flag is that if the upper level function call (e.g, f2) is skipped,
  3613. we don't want to inline the lower level function call (e.g, f3) by default.
  3614. """
  3615. def check_verbose(obj: Any, is_inlined_call: bool = False) -> SkipResult:
  3616. if isinstance(
  3617. obj,
  3618. (
  3619. UserFunctionVariable,
  3620. UserMethodVariable,
  3621. NestedUserFunctionVariable,
  3622. LocalGeneratorFunctionVariable,
  3623. LocalGeneratorObjectVariable,
  3624. ),
  3625. ):
  3626. try:
  3627. py_obj = obj.get_function()
  3628. except NotImplementedError:
  3629. py_obj = None
  3630. fi = FunctionInfo(py_obj, obj.get_name(), obj.get_filename(), obj.get_code())
  3631. elif isinstance(obj, types.CodeType):
  3632. fi = FunctionInfo(None, obj.co_name, obj.co_filename, obj)
  3633. elif isinstance(obj, (types.FunctionType, types.MethodType)):
  3634. filename = getfile(obj)
  3635. assert filename is not None
  3636. fi = FunctionInfo(
  3637. obj,
  3638. obj.__name__,
  3639. filename,
  3640. obj.__code__, # type: ignore[union-attr] # FIXME Add MethodType.__code__ to typeshed
  3641. )
  3642. else:
  3643. filename = getfile(obj)
  3644. assert filename is not None
  3645. fi = FunctionInfo(obj, None, filename, None)
  3646. # Consulte the central trace rules defined in torch._dynamo.trace_rules.
  3647. reasons: set[str] = set()
  3648. rule = lookup_inner(fi.py_obj, fi.name, fi.filename, is_inlined_call, reasons)
  3649. assert rule is not None
  3650. if issubclass(
  3651. rule,
  3652. (
  3653. UserFunctionVariable,
  3654. LocalGeneratorFunctionVariable,
  3655. PolyfilledFunctionVariable,
  3656. ),
  3657. ):
  3658. return SkipResult(
  3659. False,
  3660. f"inlined according trace_rules.lookup {reasons.pop()}",
  3661. )
  3662. elif issubclass(rule, TorchInGraphFunctionVariable):
  3663. return SkipResult(
  3664. False,
  3665. f"registered in torch_obj_rule {reasons.pop()}",
  3666. )
  3667. else:
  3668. assert rule == SkipFunctionVariable, rule
  3669. return SkipResult(
  3670. True,
  3671. f"skipped according trace_rules.lookup {reasons.pop()}",
  3672. )
  3673. def check(obj: Any, is_inlined_call: bool = False) -> bool:
  3674. return check_verbose(obj, is_inlined_call).skipped
  3675. # skip common third party libs
  3676. for _name in THIRDPARTY_SKIPLIST:
  3677. add(_name)
  3678. _recompile_re()
  3679. def is_torch_inline_allowed(filename: str) -> bool:
  3680. return any(filename.startswith(d) for d in get_mod_inlinelist())
  3681. @functools.cache
  3682. def dynamo_dir() -> Optional[str]:
  3683. import torch._dynamo
  3684. return _module_dir(torch._dynamo)
  3685. def is_torch(filename: str) -> bool:
  3686. dynamo_path = dynamo_dir()
  3687. if dynamo_path is not None and filename.startswith(dynamo_path):
  3688. return False
  3689. torch_path = _module_dir(torch)
  3690. return torch_path is not None and filename.startswith(torch_path)
  3691. """
  3692. Main entry point for looking up the trace rule (the Dynamo variable) for a given callable object.
  3693. """
  3694. def lookup_callable(obj: Callable[..., Any]) -> Optional[type[VariableTracker]]:
  3695. if not hashable(obj):
  3696. return None
  3697. # Custom allow/disallow in graph takes precedence over the general lookup.
  3698. if is_callable_disallowed(obj):
  3699. return SkipFunctionVariable
  3700. if is_callable_allowed(obj):
  3701. return TorchInGraphFunctionVariable
  3702. if is_polyfilled_callable(obj):
  3703. return PolyfilledFunctionVariable
  3704. if is_builtin_callable(obj):
  3705. return BuiltinVariable
  3706. return None
  3707. """
  3708. Main entry point for looking up the trace rule (the Dynamo variable) for a given function object.
  3709. E.g, the lookup result of `torch.sin` is `TorchInGraphFunctionVariable`.
  3710. """
  3711. def lookup(obj: Any) -> Optional[type[VariableTracker]]:
  3712. return lookup_inner(obj)
  3713. # also takes config.dont_skip_tracing into account
  3714. def lookup_inner(
  3715. obj: Any,
  3716. name: Optional[str] = None,
  3717. filename: Optional[str] = None,
  3718. is_direct_call: bool = True,
  3719. reasons: Union[None, set[str]] = None,
  3720. ) -> Optional[type[VariableTracker]]:
  3721. result = _lookup_inner(
  3722. obj,
  3723. name=name,
  3724. filename=filename,
  3725. is_direct_call=is_direct_call,
  3726. reasons=reasons,
  3727. )
  3728. # There are still some modules we should absolutely NOT trace into - e.g. most of torch._dynamo,
  3729. # as this can result in really weird tracing behaviors.
  3730. # Note that if a torch._dynamo function is already not skipped (e.g. functions in external_utils.py),
  3731. # then this branch does not apply.
  3732. if config.dont_skip_tracing and result is SkipFunctionVariable:
  3733. if filename is None:
  3734. filename = getfile(obj)
  3735. assert filename is not None
  3736. filename = _as_posix_path(filename)
  3737. torch_dir = _module_dir(torch)
  3738. if torch_dir is not None:
  3739. dynamo_path = _as_posix_path(torch_dir) + "_dynamo"
  3740. if filename.startswith(dynamo_path) and not filename.endswith(
  3741. "test_dont_skip_tracing_functions.py"
  3742. ):
  3743. return SkipFunctionVariable
  3744. if reasons is not None:
  3745. reasons.add(
  3746. "Attempted skip but we are ignoring skips due to torch._dynamo.config.dont_skip_tracing"
  3747. )
  3748. return UserFunctionVariable
  3749. return result
  3750. def _lookup_inner(
  3751. obj: Any,
  3752. name: Optional[str] = None,
  3753. filename: Optional[str] = None,
  3754. is_direct_call: bool = True,
  3755. reasons: Optional[set[str]] = None,
  3756. ) -> Optional[type[VariableTracker]]:
  3757. # Step 1: lookup obj's tracing rule in `torch_name_rule_map`.
  3758. # The rules defined in `torch_name_rule_map` mainly includes two parts:
  3759. # - Manually defined rules for any functions.
  3760. # - The list of torch in graph functions.
  3761. try:
  3762. can_hash = hashable(obj)
  3763. except Exception:
  3764. can_hash = False
  3765. if not can_hash:
  3766. if reasons is not None:
  3767. reasons.add("obj is not hashable")
  3768. return None
  3769. if obj is not None:
  3770. if is_aten_op_or_tensor_method(obj):
  3771. return TorchInGraphFunctionVariable
  3772. rule = get_torch_obj_rule_map().get(obj, None)
  3773. if rule is not None:
  3774. if reasons is not None:
  3775. reasons.add("get_torch_obj_rule_map")
  3776. return rule
  3777. elif name is not None and filename is not None and not is_direct_call:
  3778. if name.startswith(TORCH_DYNAMO_RESUME_IN_PREFIX):
  3779. rule = get_torch_obj_rule_map().get(
  3780. filename + "#" + TORCH_DYNAMO_RESUME_IN_PREFIX, None
  3781. )
  3782. else:
  3783. rule = get_torch_obj_rule_map().get(filename + "#" + name, None)
  3784. if rule is not None:
  3785. if reasons is not None:
  3786. reasons.add("get_torch_obj_rule_map")
  3787. return rule
  3788. elif name == "<listcomp>":
  3789. if reasons is not None:
  3790. reasons.add("inlining frame from list comprehension")
  3791. return UserFunctionVariable
  3792. # Step 2: lookup obj's tracing rule by function name.
  3793. if is_direct_call:
  3794. if name == "patched_init":
  3795. if reasons is not None:
  3796. reasons.add("func name is patched_init")
  3797. return SkipFunctionVariable
  3798. elif name == "__torch_function__" or (
  3799. obj and getattr(obj, "__name__", None) == "__torch_function__"
  3800. ):
  3801. if reasons is not None:
  3802. reasons.add("func name is __torch_function__")
  3803. return UserFunctionVariable
  3804. if not is_direct_call:
  3805. if name == "__getattr__":
  3806. # is_direct_call = False indicates that this is the top-level frame
  3807. # being traced (i.e., it is not inlined and not called from
  3808. # InliningInstructionTranslator). Tracing __getattr__ at the top
  3809. # level is unlikely because we inline it for
  3810. # UserDefinedObjectVariable. This scenario occurs only for
  3811. # UnspecializedNNModuleVariable, where Dynamo directly calls
  3812. # __getattr__ during trace time, generating LOAD_ATTR bytecode
  3813. # without going through the underlying __getattr__ data structures.
  3814. # When this optimized bytecode is executed, Dynamo is triggered
  3815. # again on the __getattr__ call. Therefore, we skip Dynamo tracing
  3816. # in this case.
  3817. if reasons is not None:
  3818. reasons.add(
  3819. "Tracing __getattr__ as the top level frame, unsuitable for tracing."
  3820. )
  3821. return SkipFunctionVariable
  3822. # Step 3: lookup obj's tracing rule by filename.
  3823. if filename is None:
  3824. filename = getfile(obj)
  3825. skip_result = check_file(filename, is_direct_call)
  3826. if reasons is not None and skip_result.reason is not None:
  3827. reasons.add(skip_result.reason)
  3828. if skip_result.skipped:
  3829. return SkipFunctionVariable
  3830. else:
  3831. return UserFunctionVariable
  3832. def clear_lru_cache() -> None:
  3833. torch._dynamo.trace_rules.get_torch_obj_rule_map.cache_clear()
  3834. torch._dynamo.trace_rules.get_tensor_method.cache_clear()
  3835. torch._dynamo.trace_rules.get_legacy_mod_inlinelist.cache_clear()
  3836. torch._dynamo.trace_rules.get_mod_inlinelist.cache_clear()
  3837. torch._dynamo.trace_rules.dynamo_dir.cache_clear()