trace_rules.py 155 KB

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