
    [Th              	          % S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	J
r
Jr  S SKJr  S SKJrJr  S SKJr  S SKJrJrJrJrJrJrJrJr  S SKrS SKJr  S SKJ r   S S	K!J"r"J#r#  S S
K$J%r%  \RL                  " \'5      r(S\)4S jr*S\)4S jr+S\)4S jr, " S S\5      r-\" S5      r. " S S5      r/S\)4S jr0\0" 5       (       a  SS/r1OS/r1 " S S\5      r2\1SSS.SS0SS0SS00 0 S.0 0 0 0 SS0S./S S!/S S!/\%" 5       /S".r3\4\5\6\   4   \7S#'   \\5\8\   \/\4   r9 " S$ S%\5      r: " S& S'5      r;\;" 5       r<\=\5S(4   r> " S) S*5      r?\4\5\4   r@\/ \)4   rA\/ \A4   rB0 S+S_S,\<_S-\<_S.\<_S/\<_S0\<_S1\<_S2\<_S3\<_S4\<_S5\<_S6\<_S7\<_S8\<_S9\<_S:\<_S;\<_0 S<\<_S=\<_S>\<_S?\<_S@\<_SA\<_SB\<_SC\<_SD\<_SE\<_SF\<_SG\<_SH\<_SI\<_SJ\<_SK\<_SL\<_E\<\<\<\<\<\<\<SM.E\<\<\<\<SN.SO.rC\4\5\@4   \7SP'    " SQ SR5      rD SWSS\EST\?SU\5SS4SV jjrFg)X    N)KeysViewSequence)Enum)partialwraps)	FrameType)AnyCallableget_args
get_originLiteralOptionalTypeVarUnion)CustomGraphPass)BaseSchedulerNode)_ConfigEntryConfigModule)
OrderedSetreturnc                 0    XL =(       d    [        U 5      UL $ )a:  
Determines if type_hint is comp_type. There are some type annotations that this doesn't work for.
I think it's because some Type annotations are Type Objects and some are Special Forms, but not sure.
There's definite room for improvement to make this more general for someone who deeply understands
Python types.
)r   )	type_hint	comp_types     N/var/www/auris/envauris/lib/python3.13/site-packages/torch/_inductor/fuzzer.pyis_typer   #   s     !GZ	%:i%GG    c                 ^    [        U 5      nU[        L a  [        U 5      n[        S5      U;   $ g)z
Special case of is_type.
NF)r   r   r   type)r   originargss      r   is_optional_typer!   -   s1     	"F	"DzT!!r   c                      U R                   S:H  $ )z
Special Case of is_type.
r
   )__name__)r   s    r   is_callable_typer$   :   s     ++r   c                   z    \ rS rSrSrS\R                  R                  R                  SS4S jr	S\
\   4S jrSrg)		DummyPassA   z)
A Dummy pass to be used by ConfigFuzzer
graphr   Nc                     g N )selfr(   s     r   __call__DummyPass.__call__F       r   c                     g r*   r+   r,   s    r   uuidDummyPass.uuidI   r/   r   r+   )r#   
__module____qualname____firstlineno____doc__torchfxr(   Graphr-   r   r	   r2   __static_attributes__r+   r   r   r&   r&   A   s8    ehhnn22 t hsm r   r&   Tc                   Z   \ rS rSr% Sr\R                   \" 5       \R                  R                  R                  R                   \R                  R                  R                  5       \R                   \" S5      0r\\\4   \S'   \S\\   S\\   4S j5       r\S\\   S\4S j5       rS	rg)
TypeExemplarsP   z>
This class returns examples of a Type, given its class name.
NTYPE_EXEMPLARStr   c                 V    [         R                  R                  U R                  S5      $ )z
Return an example of a class.
N)r>   r@   getr#   rA   s    r   exampleTypeExemplars.example[   s!    
 ++//

DAAr   c                 <    U R                   [        R                  ;   $ r*   )r#   r>   r@   rD   s    r   containsTypeExemplars.containsb   s    zz]9999r   r+   )r#   r4   r5   r6   r7   r   r&   r8   r9   r(   r:   r   r@   dictstrr	   __annotations__staticmethodr   r<   r   rE   boolrH   r;   r+   r   r   r>   r>   P   s    
 	  )+%%uxx~~';';'=""$5d$;&NDcN  B47 Bx{ B B :DG : : :r   r>   c                  R     [         R                  " S5        g! [         a     gf = f)z"checks if we have halide availablehalideTF)	importlibimport_moduleModuleNotFoundErrorr+   r   r   check_halide_importrT   g   s*    ) s    
&&tritonrP   c                   >    \ rS rSrSrSrSrSrSrSr	Sr
S	\4S
 jrSrg)Statusv   z0
The Status return value enum for Config Fuzzer
skippedpassedfailed_compilefailed_run_compile_exceptionfailed_run_eager_exceptionfailed_run_returnr   c                     U [         R                  :H  =(       dG    U [         R                  :H  =(       d-    U [         R                  :H  =(       d    U [         R                  :H  $ )zE
Convenience method to check whether these status represent failure.
)rW   FAILED_COMPILEFAILED_RUN_EAGER_EXCEPTIONFAILED_RUN_COMPILE_EXCEPTIONFAILED_RUN_RETURNr1   s    r   failingStatus.failing   sR    
 F))) 0v8880v:::0 v///		
r   r+   N)r#   r4   r5   r6   r7   SKIPPEDPASSEDr`   rb   ra   rc   rN   rd   r;   r+   r   r   rW   rW   v   s8    
 GF%N#A != ,	
 	
r   rW   T)shape_broadcast_batch_linearfuse_nodes_with_same_usersfuse_nodes_with_same_parentF)batch_linear_post_gradbatch_aten_mulbatch_aten_sigmoidbatch_aten_addnormalization_aten_passunbind_stack_aten_passrequire_fbgemm)rn   rl   batch_aten_subbatch_aten_divgroup_linearpad_mmmixed_mm)cuda_backendpost_grad_fusion_optionsautoheuristic_collectautoheuristic_usetraceable_tensor_subclassesTYPE_OVERRIDESc                   j    \ rS rSrSrSrSr\S\S\	S\
\   S\S	\4
S
 j5       r\SS S	\4S j5       rSrg)SamplingMethod   a  
This class handles the process of assigning concrete values to type annotations. So a type annotation of
```python
foo: Optional[int] = None
```
Will be assigned an int if the dispatch function gets TOGGLE, or a 50/50 split between an int and None if it gets
RANDOM.
TOGGLERANDOMrandom_sample
field_namer   defaultr   c                 H  ^ ^^^ T[         ;   a  [        R                  " [         T   5      $ U[        :X  a&  T (       a  [        R                  " SS/5      $ U(       + $ U[        :X  a  [        R
                  " SS5      $ U[        :X  a  [        R                  " SS5      $ U[        :X  ak  [        R                  [        R                  -   [        R                  -   mSR                  U4S j[        [        R
                  " SS5      5       5       5      $ [        U[         5      (       a  [#        US	[%        U5      (       a  ['        US   5      /O['        S
5      /5      S   n[%        U5      S:  a  US   OS
n[        [        R
                  " SS5      5       Vs/ s H  n[(        R+                  T TXE5      PM     sn$ [        U[,        5      (       a  [!        U5      n[#        US	[%        U5      (       a  ['        US   5      /O['        S
5      /5      S   n[%        U5      S:  a  US   OS
n[        [        R
                  " SS5      5       Vs1 s H  n[(        R+                  T TXE5      iM     sn$ [        U[.        5      (       a  [!        U5      n[#        US	[%        U5      (       a  ['        US   5      /O['        S
5      /5      S   n[%        U5      S:  a  US   OS
n[/        [        [        R
                  " SS5      5       Vs/ s H  n[(        R+                  T TXE5      PM     sn5      $ [        U[0        5      (       Ga  [#        US	Ub@  [%        U5      (       a0  [3        [&        [5        [7        UR9                  5       5      5      5      O['        S
5      ['        S
5      45      u  pUbB  [%        UR9                  5       5      S:  a%  [5        [7        UR9                  5       5      5      u  pOSu  p[        [        R
                  " SS5      5       Vs0 s H0  n[(        R+                  T TX5      [(        R+                  T TX5      _M2     sn$ [        U[:        5      (       a   [%        UR<                  5      S:  d   e T (       a!  [        R                  " UR<                  5      nOA[        R                  " UR<                   Vs/ s H  o['        U5      :w  d  M  UPM     sn5      n U" 5       n[(        R+                  T TX5      $ [        U[D        5      (       aI  [#        US	[E        [3        [&        U5      5      5      n[G        X5      n[E        [3        UU 4S jU5      5      $ [        U[H        5      (       aj   T (       a   [        R                  " UR<                  5      $ UR<                   Vs/ s H  oU:w  d  M
  UPM     nnU(       a  [        R                  " U5      $ U$ [K        U5      (       a`   UR<                  S   nT (       a-  [        R                  " S
[(        R+                  T TXC5      /5      $ Uc  [(        R+                  T TUS
5      $ g
U['        S
5      L a  g
[M        U5      (       a2   [!        UR<                  5      S   m[O        S 5      UU U4S j5       nU$ [P        RS                  U5      (       a  [P        RU                  U5      $ U[V        :X  a
  US:X  d  S$ S$ [A        SU S35      es  snf s  snf s  snf s  snf ! [>         a  n[A        S5      UeS
nAff = fs  snf ! [B         a    S
n GNMf = fs  snf ! [>         a  n[A        S5      UeS
nAff = f! [>         a  n[A        S5      UeS
nAff = f! [>         a  n[A        S5      UeS
nAff = f)z3
Generates a value of a type based on the setting.
TFr      c              3   P   >#    U  H  n[         R                  " T5      v   M     g 7fr*   )randomchoice).0_
characterss     r   	<genexpr>:SamplingMethod._generate_value_for_type.<locals>.<genexpr>   s!      3Oaj))3Os   #&      __args__N   )NNzUnion type with no argsc                 @   > [         R                  TTU S   U S   5      $ )Nr   r   r~   _generate_value_for_type)xr   r   s    r   <lambda>9SamplingMethod._generate_value_for_type.<locals>.<lambda>7  s!    nEE%z1Q41r   zLiteral type with no argszOptional type with no argszCallable type with no argsc                      g r*   r+   )r    kwargss     r   r   r   f  s    4r   c                  4   > [         R                  TTTS 5      $ r*   r   )r    r   r   r   return_types     r   dummy_function?SamplingMethod._generate_value_for_type.<locals>.dummy_functionf  s    %>>!:{D r      zUnable to process type z. PRs welcome :)),r|   r   r   rN   intrandintfloatuniformrK   stringascii_lettersdigitspunctuationjoinranger   listgetattrlenr   r~   r   setr   rJ   mapnextiteritemsr   r   AttributeError
ValueError	Exceptiontuplezipr   r!   r$   r   r>   rH   rE   r	   )r   r   r   r   	elem_typenew_defaultr   	indexablekey_type
value_typedefault_keydefault_valerrnew_typerA   r    zippedchoicesr   r   r   s   ``                 @@r   r   'SamplingMethod._generate_value_for_type   s    '==
!;<<3@6==$/Q'kQ# >>!T**%>>!T**#--=@R@RRJ77 3829N3O   Y%%&)'llgaj!"d 	I
 ),Gq(8'!*dK
 v~~a34	 5A 77!:y 5	  Y$$WI(+Gil#$4:, 	I
 +.g,*:)A,K
 v~~a34	 5A 77!:y 5	  Y
++WI(+Gil#$4:, 	I
 +.g,*:)A,K
 #6>>!Q#78	 9 #;;%z9 9	  Y%%#*'CLL D$tGMMO4564j$t*-$ H "s7==?';a'?+/W]]_0E+F([+5( v~~a34 5A 77!:x!::!:z
 5  Y&&E9--.222 !==););<!== ) 2 2I 214=6HQ 2I#&j
 "::z8  Y&&c$()D
 'F 	  Y((
G !==););<<*3*<*<M*<QWq*<GM%}}W55& i((H%..q1	 }}&??):y  ?)BB%z9d   $t*$i((H"9#5#56r: /0 1
 "!##I.. ((33##qL1/a/6ykAQRSSc& " E !:;DE J  #"#6 N
 " G !<=3FG
 " H !=>CGH. " H !=>CGHs   ![;!\ !\7\
'\ 	\-\--\2 ?&]
 &]
 4	]]]
 &]
 9]( 8^ 
\*\%%\*2]]]
 

]%]  ]%(
^2]>>^
^!^^!smc                     U [         R                  :X  a  [        [         R                  S5      $ U [         R                  :X  a  [        [         R                  S5      $ [        SU  35      e)zb
Returns a function that will generate values from a type, based on the SamplingMethod passed in.
TFzmalformed sampling method: )r~   r   r   r   r   r   )r   s    r   dispatchSamplingMethod.dispatcht  sY    
 &&&>BBDII>(((>BBEJJ:2$?@@r   r+   N)r#   r4   r5   r6   r7   r   r   rM   rN   rK   r   r	   r   SamplingTyper   r;   r+   r   r   r~   r~      s     FFoToT),oT9=coTMPoT	oT oTb 	A% 	A, 	A 	Ar   r~   c                       \ rS rSrSrSrg)Defaulti  zn
Singleton default object that will cause the ConfigFuzzer to always use the default value set in the config.
r+   N)r#   r4   r5   r6   r7   r;   r+   r   r   r   r     s    r   r   .c                       \ rS rSr% Sr\\\4   \S'   S\	4S jr
SS jrS\4S jrS\4S	 jrS
\S\SS4S jrS
\S\\   4S jrS\\   4S jrSrg)
ResultTypei  zX
The mapping of the combo strings to the result status after running the config fuzzer.
_valsr   c                 "    SU R                    S3$ )NzResultType[]r   r1   s    r   __repr__ResultType.__repr__  s    TZZL**r   Nc                     0 U l         g r*   r   r1   s    r   __init__ResultType.__init__  s	    
r   c                 ,    [        U R                  5      $ r*   )r   r   r1   s    r   __len__ResultType.__len__  s    4::r   c                     [        U R                  5      nU R                  R                  5        H  nU[        R                  :X  d  M  US-  nM      U$ )z9
Returns how many combos actually ran (weren't skipped).
r   )r   r   valuesrW   rf   )r,   retstatuss      r   num_ranResultType.num_ran  sD     $**ojj'')F'q * 
r   combor   c                 H    [        [        U5      5      nX R                  U'   g r*   )r   sortedr   )r,   r   r   s      r   r   ResultType.set  s    fUm$"

5r   c                 b    [        [        U5      5      nU R                  R                  US 5      $ r*   )r   r   r   rC   )r,   r   s     r   lookupResultType.lookup  s%    fUm$zz~~eT**r   c                 6    U R                   R                  5       $ r*   )r   keysr1   s    r   r   ResultType.keys  s    zz  r   r   r   N)r#   r4   r5   r6   r7   rJ   	ComboTyperW   rL   rK   r   r   r   r   r   r   r   r   r   r   r;   r+   r   r   r   r     s     	6!""+# +  # #F #t #+I +(6*: +!hy) !r   r   force_disable_cacheszcpp.cxxTYPE_CHECKINGmax_autotune_pointwisemax_autotune_gemmmax_autotune_gemm_backendsmax_autotune_conv_backendsmax_autotune_gemm_search_space+max_autotune_subproc_result_timeout_seconds-max_autotune_subproc_graceful_timeout_seconds.max_autotune_subproc_terminate_timeout_secondszaot_inductor.presetsz	cuda.archzcuda.versionzcuda.cutlass_dirzcuda.cuda_cxxz	rocm.archzrocm.ck_supported_archzrocm.ck_dirzrocm.rocm_home"check_stack_no_cycles_TESTING_ONLYsleep_sec_TESTING_ONLYz#triton.inject_relu_bug_TESTING_ONLY reorder_for_compute_comm_overlapenabled_metric_tablesztriton.debug_sync_graphztriton.debug_sync_kernelprofile_bandwidth_regexdisable_cpp_codegenztrace.save_real_tensorspre_grad_fusion_optionsexternal_matmulz'test_configs.autotune_choice_name_regexz'test_configs.autotune_choice_desc_regex)z'cpp.enable_floating_point_contract_flagpost_grad_custom_pre_passpost_grad_custom_post_pass'reorder_for_compute_comm_overlap_passesjoint_custom_post_passjoint_custom_pre_passpre_grad_custom_pass)r{   !compiled_autograd_kwargs_overridefail_on_recompile_limit_hitsuppress_errors)ztorch._inductor.configztorch._dynamo.configMODULE_DEFAULTSc                      \ rS rSr% Sr\\S'   \\S'   S\R                  S4S\
S\S	\S\\   S
\S\4S jjrS\4S jrS\S\SS4S jrS.S jrS\4S jrS\\   S\4S jrS\S\SS4S jrS\S\4S jrS\S\S\4S jrS/S\S\S\4S jjrS0S \SS4S! jjrS0S \SS4S" jjrS#\S$\\    SS4S% jr!S\S\S\4S& jr"S1S'\S(\#S\$\   4S) jjr%S\S*\S\\   4S+ jr&S\S*\$\'\\4      S\\   4S, jr(S-r)g)2ConfigFuzzeri  a  
This tool makes it easy to search through config state-space with a minimal reproduction or test, either for
  debugging or just bug hunting.
It has two entry points:
 - bisect, which randomly flips configs and tries to find the minimal reproduction upon failure.
 - fuzz_n_tuple, which tries every combination of n configs. This grows quickly as a function of n, so beware.
bisect is recommended, but fuzz_n_tuple can give you peace of mind that a new config will compose with
  every other config.

The main interface is a function factory that will return Callables to be torch.compiled. This function factory
  should return a test function when it's called. Said test function returns a boolean, which determines whether
  the ConfigFuzzer considers it a successful run or not. Throwing an exception from within the function will be
  considered a failure as well.

# Example usage:

```python
import torch._inductor.config as cfg


def create_simple_test_model_gpu() -> FactoryOutputType:
    batch_size = 32
    seq_length = 50
    hidden_size = 768

    def test_fn() -> bool:
        inp = torch.randn(batch_size, seq_length, hidden_size, device="cuda")
        weight = torch.randn(hidden_size, hidden_size, device="cuda")
        matmul_output = inp @ weight
        final_output = torch.nn.LayerNorm(hidden_size, device="cuda")(matmul_output)
        return True

    return test_fn


fuzzer = ConfigFuzzer(cfg, create_simple_test_model_gpu, seed=2)

# Test every pair of configs:
results = fuzzer.fuzz_n_tuple(n, max_combinations=10000000)

visualize_results(n, results)

# Test random configs with bisection:
ret = fuzzer.bisect(num_attempts=10)

# reproduce a failing config
fuzzer.reproduce(
    [{"triton.autotune_pointwise": ..., "coordinate_descent_tuning": ...}]
)
```

The list of known failures on inductor config are:
cpp_wrapper, triton_debug_sync_graph
cpp_wrapper, triton_debug_sync_kernel
cpp_wrapper, disable_cpp_codegen
combo_kernels, benchmark_combo_kernel, profile_bandwidth, profile_bandwidth_regex
trace.enabled, trace.save_real_tensors
sampler   Ni  config_moduletest_model_fn_factoryseedr   test_timeoutc                    [         R                  S:  a  [        R                  S5        gX0l        X`l        0 U l        Xl        X l        U R                  R                  U l
        [        R                  U5      U l        UcL  U R                  R                  [        ;   a#  [        U R                  R                     U l        g[#        S5      eX@l        g)a  
Args:
    config_module: The module containing the configs to fuzz
    test_model_fn_factory: Function that returns a test model, which runs and returns True if successful, or
      the outputs if they should be compared with eager
    seed: Randomness seed.
    default: Default values for the config. Inductor has preset based on know failures.
    sm: How type value samples are generated, default TOGGLE.
    test_timeout: max time a test can take.
)r   
   z$Only python 3.10 and later supportedNz"No default passed to ConfigFuzzer.)sysversion_infologerrorr  r  detailed_resultsr  r  _configfieldsr~   r   r
  r#   r  r   r   )r,   r  r  r  r   r   r  s          r   r   ConfigFuzzer.__init__<  s    & g%II<=	(AC*%:"/3/A/A/I/I$--b1?!!**o=.t/A/A/J/JK !EFF"Lr   r   c           	      p    SU R                    SU R                   SU R                   SU R                   S3	$ )NzConfigFuzzer(config_module=z, test_model_fn_factor=z, seed=z
, default=))r  r  r  r   r1   s    r   r   ConfigFuzzer.__repr__b  sH    )$*<*<)= >$$($>$>#?wtyykQ[\`\h\h[iijl	
r   r   valuec                 0    [        U R                  X5        g)z!Set a config value in the module.N)setattrr  )r,   r   r  s      r   _set_configConfigFuzzer._set_configh  s    ""J6r   c                     U R                   R                  5        H   u  pU R                  XR                  5        M"     g)z*Reset all configs to their default values.N)r  r   r  r   )r,   r   	field_objs      r   _reset_configsConfigFuzzer._reset_configsl  s0    %)[[%6%6%8!JZ):):; &9r   c                     U R                   R                  5        VVs0 s H*  u  pX[        :w  a  UOU R                  U   R                   _M,     nnnU$ s  snnf )z%creates a new config from the default)r   r   DEFAULTr  )r,   namevalr   s       r   
new_configConfigFuzzer.new_configq  sY     "\\//1
1	 #T[[->-F-FF1 	 
 
	
s   1Aconfigsc                 N    [        5       nU H  nU R                  X25        M     U$ )z#entrypoint to reproduce any failurer   _reproduce_single_helper)r,   r+  resultsconfs       r   	reproduceConfigFuzzer.reproducey  s&    ,D))$8 r   r0  r/  c                     [        SU 35        U R                  5       nUR                  U5        U R                  X#5        [        SU SUR	                  [        UR                  5       5      5       35        g )NzStarting repro of z
Status of z:
)printr)  updatetest_configr   r   r   )r,   r0  r/  r)  s       r   r.  %ConfigFuzzer._reproduce_single_helper  sd    "4&)*__&
$-
4&GNN53E$F#GHIr   configc                 <    [        5       nU R                  X5        U$ r*   r-  )r,   r8  r/  s      r   reproduce_singleConfigFuzzer.reproduce_single  s    ,%%f6r   r   c                    [        U5        UR                  U5      =n(       a  U$ U R                  5       nSnU H[  nXd;   a  SnUR                  S5      (       a  SnU R                  U   nU R                  XgR                  UR                  5      nXU'   M]     U(       a0  UR                  U[        R                  5        [        R                  $ U R                  X5      $ )NFTr   )r4  r   r)  
startswithr  r
  r   r   r   rW   rf   r6  )	r,   r/  r   str8  skipr   fieldr  s	            r   _fuzz_helperConfigFuzzer._fuzz_helper  s    e&&2&I"J#$$S))KK
+EKK
,<,<emmLE!&:   KKv~~.>>!00r   nmax_combinationsc                 `   [        5       n[        SU SU R                   35        [        R                  " U R                  5        [        R
                  " U R                  U5       HC  nU R                  X45      nU[        R                  :w  d  M*  US-  nUS::  d  M7  [        S5          U$    U$ )zp
Test every combination of n configs.

returns a dict of this shape: {(config-1, config-2... config-n): status}
z	Starting z-tuple testing with seed r   r   z"Reached maximum combinations limit)
r   r4  r  r   	itertoolscombinationsr  rA  rW   rf   )r,   rC  rD  r/  r   r>  s         r   fuzz_n_tupleConfigFuzzer.fuzz_n_tuple  s     ,	!5dii[ABDII++DKK;E""72BV^^# A% #q(>? < r   filenamec                     [        US5       n[        R                  " U R                  U R                  S.U5        SSS5        g! , (       d  f       g= f)z'Save the current fuzzer state to a filewb)r/  r  N)openpickledumpr/  r  )r,   rJ  fs      r   
save_stateConfigFuzzer.save_state  s;    (D!QKK LLd>S>STVW "!!s   /A
Ac                     [        US5       n[        R                  " U5      nUS   U l        UR	                  S0 5      U l        SSS5        g! , (       d  f       g= f)zLoad fuzzer state from a filerbr/  r  N)rM  rN  loadr/  rC   r  )r,   rJ  rP  states       r   
load_stateConfigFuzzer.load_state  sG    (D!QKKNE +DL$)II.@"$ED! "!!s   8A
Asignumframec                     [        S5      e)NzTest execution timed out)TimeoutError)r,   rY  rZ  s      r   timeout_handlerConfigFuzzer.timeout_handler  s    566r   c           
        ^ ^^^^^^ [         R                   " [         R                  T R                  5      m[         R                  " T R                  5        [        ST 35        [        TR                  5       5      mTR                  T5      =n(       a'  [         R                   " [         R                  T5        U$ SU4S jjmS[        S[        [        [        4   4U4S jjmS[        S[        S	[        S[        [           S[        4
UUUUUU 4S
 jjn[         R"                  R%                  5         T R'                  5         TR)                  5        H  u  pVT R+                  XV5        M     T R-                  5       n U" 5          T R-                  5       n	[         R0                  " U	SS9n
 U
" 5       nU(       d  U" S[        R6                  SS5      $ U" S[        R8                  SS5      $ ! [         a#  nU" S[        R.                  SU5      s SnA$ SnAff = f! [         a#  nU" S[        R2                  SU5      s SnA$ SnAff = f! [         a#  nU" S[        R4                  SU5      s SnA$ SnAff = f)zJ
Tests a config by calling the function produced by the factory function.
zTesting config r   Nc                  X   > TR                  5        H  u  p[        U  SU 35        M     g )Nz = )r   r4  )r@  r  r8  s     r   print_config.ConfigFuzzer.test_config.<locals>.print_config  s(     &s5'*+ !/r   excc                 d   > [        U 5      [        R                  " 5       TR                  5       S.$ )N)	exception	tracebackr8  )rK   rf  
format_exccopy)rc  r8  s    r   get_error_info0ConfigFuzzer.test_config.<locals>.get_error_info  s)     X&113 ++- r   messagereturn_statusprint_tracebackc                   > [         R                   " [         R                  T5        [        U  S35        T" 5         U(       a  T" U5      T	R                  T'   U(       a  [        R
                  " 5         TR                  TU5        U$ )Nz with config combination:)signalSIGALRMr4  r  rf  	print_excr   )
rk  rl  rm  rc  config_tupleri  original_handlerra  r/  r,   s
       r   handle_return/ConfigFuzzer.test_config.<locals>.handle_return  sh     MM&..*:;WI678N6DS6I%%l3##%KKm4  r   zEager exceptionTinductor)backendzException compilingzException running compiledzFunction returned FalseFzFunction succeededr   )ro  rp  r]  alarmr  r4  r   r   r   r   rJ   rK   r	   rW   rN   r   r8   _dynamoresetr#  r   r  r  ra   compiler`   rb   rc   rg   )r,   r/  r8  r   rt  r'  r  test_model_fnrc  test_model_fn2compcompile_resultrr  ri  rs  ra  s   ```         @@@@r   r6  ConfigFuzzer.test_config  s%    "==9M9MNT&&'x()V[[]+....3.MM&..*:;J	,		 	d38n 		!	!!	! "	! )$		!
 	! 	!" 	!<<>KDT) * 224	O	!779N==DD	!VN  )6+C+CUD  !!5v}}eTRR?  	 !6#D#DdC 	  	 %v'<'<dC 	  	 ,33	 	sZ   G/ 	%H /I /
H9HHH
I)III
I<I71I<7I<num_attemptspc                 6   [        SU R                   SU 35        [        R                  " U R                  5        U R                  5         [	        5       n/ n[        U5       GH1  n[        SUS-    SU 35        U R                  5       nU R                  R                  5        Hq  u  pxXv;  d  M  UR                  S5      (       a  M$  SU;  d  M,  [        R                  " 5       U:  d  MG  U R                  XxR                  UR                  5      n	XU'   Ms     U R                  X65      n
U
[        [        R                   [        R"                  /5      ;  d  M  U R%                  X65      =n(       d  GM  [        SU 35        UR'                  U5        GM4     U$ )	z;
Test configs and bisect to minimal failing configuration.
z-Starting random testing with bisection, seed z, and p zRandom attempt r   /r   TESTING_ONLYzMinimum failing config: )r4  r  r   r#  r   r   r)  r  r   r=  r
  r   r   r6  r   rW   rg   rf   _bisect_failing_configappend)r,   r  r  r/  r   attemptr8  r   config_entryr  r   minimal_failing_configs               r   bisectConfigFuzzer.bisect  sd    	=dii[QRPSTUDII, "\*GOGaK=,@A__&F,0KK,=,=,?(
,&11#66&j8!+ KK"$;$;\=Q=QE */:& -@ %%g6FZ(GHH-1-H-H. )   45K4LMNJJ56/ +2 
r   failing_configc                 T    U R                  U[        UR                  5       5      5      $ r*   )_bisect_failing_config_helperr   r   )r,   r/  r  s      r   r  #ConfigFuzzer._bisect_failing_config@  s%     11'4@T@T@V;WXXr   c                   ^ ^ [        SU 35        U(       d  gS[        [        [        [        4      S[
        4UU 4S jjn[        U5      S::  a(  U" U5      R                  5       (       a  [        U5      $ S$ [        R                  " U5        [        U5      S-  nUSU nX$S nU" U5      R                  5       (       a  T R                  TU5      $ U" U5      R                  5       (       a  T R                  TU5      $ [        U5      S:  a  [        U5      S	-  nXG-   nX'S n	U" U	5      R                  5       (       a  T R                  TU	5      $ USU U-   n
U" U
5      R                  5       (       a  T R                  TU
5      $ XRSU -   nU" U5      R                  5       (       a  T R                  TU5      $ X(S nU" U5      R                  5       (       a  T R                  TU5      $ [        [        U5      5       HX  n[        U5       VVs/ s H  u  pX:w  d  M  UPM     nnnU" U5      R                  5       (       d  MF  T R                  TU5      s  $    [        U5      $ s  snnf )
z
Bisect a failing configuration to find minimal set of configs that cause failure.

Splits it into halves, then fourths, then tries dropping configs one-by-one.
zbisecting config: Nr   r   c                 B   > [        U 5      nTR                  TU5      nU$ r*   )rJ   r6  )r   dresultr/  r,   s      r   test8ConfigFuzzer._bisect_failing_config_helper.<locals>.testR  s#    QA%%gq1FMr   r   r         )r4  r   r   rK   r	   rW   r   rd   rJ   r   shuffler  r   	enumerate)r,   r/  r  r  mid
first_halfsecond_halflowhighquart1quart2quart3quart4ijr   new_lists   ``               r   r  *ConfigFuzzer._bisect_failing_config_helperE  sO    	">"234	DsCx) 	f 	 	
 ~!#+/+?+G+G+I+I4'StS~&.!Q&#DS)
$T*
##%%55gzJJ$$&&55g{KK~!#n%*C9D#D)FF|##%%99'6JJ#DS)K7FF|##%%99'6JJ$"77FF|##%%99'6JJ#E*FF|##%%99'6JJs>*+A&/&?J&?da16&?HJH~%%''99'8LL ,
 N##	 Ks   I' I')	r  r   r  r  r/  r
  r  r  r  r   )r   )zfuzzer_state.pkl)d   g      ?)*r#   r4   r5   r6   r7   r   rL   
ConfigTyper~   r   r   FactoryTyper   r   r   rK   r   r	   r  r#  r)  r   r   r1  r.  r:  r   rW   rA  rH  rQ  rW  r   r]  r6  r   r   r  r  r   r  r;   r+   r   r   r	  r	    s   9v  )-+22 $##$#  +$# 	$#
 *%$# $# $#L
# 
7c 7# 7$ 7<
J *!5 * JZ J* JQU Jz j 
1J 1y 1V 10c S J (3  F3 F F7c 7(92E 7$ 7PS: PSz PSf PSd#3 # #jAQ #JY!Y3=Y	*	Y
4$!4$37c3h3H4$	*	4$r   r	  rC  r/  rJ  c                 n   U S:X  d   e[        U5      S:  d   e[        0 5      nUR                  5        H+  nUR                  US   5        UR                  US   5        M-     [	        U5      nSnUS-  nU H  nSR                  U5      nUSU S3-  nM     US	-  nU H  n	US
U	 S3-  nU H  nUR                  X45      n
SnSnU
[        R                  :X  a  SnSnOU
[        R                  :X  a  SnSnOhU
[        R                  :X  a  SnSnOOU
[        R                  :X  a  SnSnO6U
[        R                  :X  a  SnSnOU
[        R                  :X  a  SnSnOSnSnUSU SU S3-  nM     US-  nM     US-  n[        US5       nUR                  U5        SSS5        g! , (       d  f       g= f)zh
Creates an HTML document representing the results of running the fuzzer with fuzz_n_tuple, with n = 2.
r   r   r   a  
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title> Fuzzer Visualization</title>
        <style>
            table {
                border-collapse: collapse;
                width: 50%;
                margin: 20px auto;
            }
            th, td {
                border: 1px solid #ddd;
                padding: 8px;
                text-align: center;
            }
            th {
                background-color: #f2f2f2;
            }
            .skipped {
                background-color: yellow;
            }
            .passed {
                background-color: green;
                color: white;
            }
            .failed {
                background-color: red;
                color: white;
            }
        </style>
    </head>
    <body>
        <h2 style="text-align: center;">Fuzzer Visualization</h2>
        <table>
        <thead>
    z<tr><th>\</th>z<br>z<th>z</th>z</tr></thead><tbody>z<tr><th>r   rY   -rZ   OfailedeERCz<td class="z">z</td>z</tr>z?
        </tbody>
        </table>
    </body>
    </html>
    wN)r   r   r   addr   r   r   rW   rf   rg   ra   rb   rc   r`   rM  write)rC  r/  rJ  	input_setkey
input_listhtml_contentcol_namecolrow_namestatus_enumstatus_class
status_valfiles                 r   visualize_resultsr  |  s    6M6w<!!+BI||~c!fc!f  	"J&LP %%Lkk(#$se5))  **L (8*E22"H!..()=>KLJfnn,( 
-' 
 A AA' 
 C CC' 
 8 88' 
 5 55' 
( 
k,r*UKKL7 #8 	= @   L 
h	

<  
		s   F&&
F4)zresults.html)GrQ   rF  loggingrN  r   ro  r   r  rf  collections.abcr   r   enumr   	functoolsr   r   typesr   typingr	   r
   r   r   r   r   r   r   r8   !torch._inductor.custom_graph_passr   torch._inductor.schedulerr   torch.utils._config_moduler   r   torch.utils._ordered_setr   	getLoggerr#   r  rN   r   r!   r$   r&   r<   r>   rT   CUDA_BACKENDrW   r|   rJ   rK   r   rL   r   r   r~   r   r&  r   r   r   r  FactoryOutputTyper  r  r	  r   r  r+   r   r   <module>r     s          
  .  $ 	 	 	  = 7 A / !HT H
4 
,4 ,	 	 CL: :.T  h'L:L
T 
F ! 15.2'  =eD#@$"G<dC')&(
	
 !   -t4	
!( '
3"J/$.L>1(S$s)^$ 4 d3i-s23IAT IAX  ) #s(O	#! #!N #s(^
RX& r,,-"**7* 	* 	!'	*
 	W* 	%g* 	%g* 	)'* 	6w* 	8* 	9'* 	* 	W* 	* 	G*  	!*" 	W#*$ 	!'%*& 	w'*( 	')** 	-g+*, 	!'-*. 	.w/*0 	+G1*2 	 3*4 	"75*6 	#G7*8 	"79*: 	w;*< 	"7=*> 	"7?*@ 	7A*B 	27C*D 	27E*F 4;%,&-3:")!( 'S*X (/-4'."	Y2*c:o& 2j|$ |$@ 2@h!
h!h!+.h!	h!r   