
    Vh |                     V   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZ d dlmZmZmZmZ d dlZd dlZd dlmc mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z  d d	l!m"Z"m#Z#m$Z$ d
e%fdZ&dejN                  de(fdZ)dddddejT                  jV                  de,edf   de-e%ef   de(dee.   dee.   defdZ/dddddejT                  jV                  de,edf   de-e%ef   de(dee.   dee.   ddfdZ0dddddejT                  jV                  de,edf   de-e%ef   de(dee.   dee.   ddfdZ1dddddejT                  jV                  de,edf   de-e%ef   de(de(dee.   dee.   defdZ2dedefdZ3e/e0e1 ejh                  e2d        ejh                  e2d       d!Z5d"Z6g d#Z7e7d$gz   Z8dde7fd%ed&e9e%   d'ee%   d(ee-e%ef      d)e9e%   ddfd*Z:d+ Z;d,Z<d'e%ddfd-Z=d.d/d)e9e%   d%eddfd0Z>de(fd1Z? ej                         ZAdeA_B        d2 ZC G d3 d4e       ZDdFd5ZE	 dGe7dddd6deejT                  jV                  ejT                  j                  ef   de,edf   dee-e%ef      d)ee%ee%   f   d7e(dee.   dee.   de-e%e%f   fd8ZG G d9 d:eH      ZIdd;d<e%dejT                  jV                  de,edf   de-e%ef   d=e(d>e(de%fd?ZJdejT                  j                  dejT                  jV                  fd@ZKdAddBZLe-e%e-e%e-e%e%f   f   f   ZMdCZNdDe6 ZO G dE d/      ZPy)H    N)Sequence)AnyCallableOptionalUnion)clone_input)CustomOpDef)SchemaCheckMode)get_file_path_2)TorchFunctionMode)aot_autograd_checkautograd_registration_check
fake_checkreasonc                     d }|S )Nc                     d| _         | S )NT)"_torch_dont_generate_opcheck_tests)funs    ^/home/dcms/DCMS/lib/python3.12/site-packages/torch/testing/_internal/optests/generate_tests.pyinnerz'dontGenerateOpCheckTests.<locals>.inner    s    15.
     )r   r   s     r   dontGenerateOpCheckTestsr      s     Lr   tensorreturnc                 r    | j                   ryt        j                  j                  j	                  |       ryy)NTF)is_metatorch_subclassesfake_tensoris_fake)r   s    r   is_abstractr"   '   s,    ~~$$,,V4r   T)copy_inputsrtolatolopargs.kwargsr#   r$   r%   c                    |rt        ||f      \  }}t        j                  t        j                  t
        ||f      ry t               5   | |i |}|cd d d        S # 1 sw Y   y xY wN)deepcopy_tensorspytreetree_any_onlyr   Tensorr"   r
   )r&   r'   r(   r#   r$   r%   results          r   safe_schema_checkr0   /   sc     'v7fELL+f~F		 T$V$  s   	
AA&c                    t        j                  t        j                  t        ||f      ry |rt        ||f      \  }}t        j                  t        j                  d ||f      sy t        | ||      S )Nc                     | j                   S r*   )requires_grad)xs    r   <lambda>z2safe_autograd_registration_check.<locals>.<lambda>P   s
     r   )r,   r-   r   r.   r"   r+   r   r&   r'   r(   r#   r$   r%   s         r    safe_autograd_registration_checkr7   A   sh     ELL+f~F'v7f/$ 	&r488r   c                    t        j                  t        j                  t        ||f      ry |rt        ||f      \  }}t        | ||      S r*   )r,   r-   r   r.   r"   r+   r   r6   s         r   safe_fake_checkr9   V   sE     ELL+f~F'v7fb$''r   dynamicc                &    t        j                  t        j                  t        ||f      ry  fd}|r3|r1t        j                  t        j                  j                  ||      }nt        j                  j                  }t        ||||d|      S )Nc                      t        j                  t        j                  t        j                  | |f      \  } } | i |S r*   )r,   tree_map_onlyr   r.   clone)r'   r(   r&   s     r   funcz%safe_aot_autograd_check.<locals>.funcu   s7    ++ELL%++f~Vf4"6""r   r$   r%   auto)check_gradientsassert_equals_fn)
r,   r-   r   r.   r"   	functoolspartialtestingassert_closer   )	r&   r'   r(   r:   r#   r$   r%   r?   rC   s	   `        r   safe_aot_autograd_checkrH   f   s     ELL+f~F# $,,MM&&T
 !==55) r   inputsc                 T    t        j                  t        j                  t        |       S r*   )r,   r=   r   r.   r   )rI   s    r   r+   r+      s    k6BBr   F)r:   )test_schematest_autograd_registrationtest_faketensortest_aot_dispatch_statictest_aot_dispatch_dynamiczThttps://docs.google.com/document/d/1Pj5HRZvdOq3xpFpbEjUZp2hBovhy7Wnxw14m6lF2154/edit)rK   rL   rM   rO   rN   testcase
namespacesfailures_dict_pathadditional_decorators
test_utilsc           	          i t               D cg c]*  }|j                  d      rt        t         |            r|, }}_t	        j
                         j                  }t	        j                  |      d   }t        t        j                  j                  |      d      t        j                  t                     t        |        t!                fd}	|D 
ci c]  }
|
t"        |
    }}
|D ]$  }|j%                         D ]  \  }} |	|||        & t'                yc c}w c c}
w )a  Given an existing TestCase, use the existing tests to generate
    additional validation tests for custom operators.

    For {all existing tests in the TestCase} x {all test utils},
    we will generate one new test. The new test runs a TorchFunctionMode
    that intercepts ``op(*args, **kwargs)`` calls and invokes
    ``test_util(op, *args, **kwargs)``, where ``op`` is an operator.

    The test_util that we support are in ALL_TEST_UTILS. They are:
    - test_schema: This runs SchemaCheckMode.
    - test_autograd_registration: This runs autograd_registration_check.
    - test_faketensor: This runs CrossRefFakeMode.
    - test_aot_dispatch_static: This runs aot_autograd_check, which:
        checks that the outputs (and gradients, if they are computable)
        are the same under eager-mode PyTorch and using AOTAutograd.
    - test_aot_dispatch_dynamic: Same as aot_dispatch_static, but
        runs AOTAutograd using dynamic shapes instead of static shapes.

    The generated test will have name ``{test_util}__{original_name}``.
    For example, if there is a method named ``test_cumsum``, then
    we will generate a ``test_schema__test_cumsum``,
    ``test_faketensor__test_cumsum``, etc.

    For more details, see https://docs.google.com/document/d/1Pj5HRZvdOq3xpFpbEjUZp2hBovhy7Wnxw14m6lF2154/edit

    Args:
        testcase: The testcase we will modify and generate additional tests for.
        namespaces: We will only intercept calls to custom operators with these
                    namespaces.
        failures_dict_path: See ``validate_failures_dict_structure`` for more details
        test_utils: a list of test_utils to generate. Example: ["test_schema", "test_faketensor"]
    Ntest_r   zfailures_dict.jsoncreate_filec                 4   t        |       t        dd      ry dz   | z   t        j                        fd       }|j                  j	                  d      x}rdd l}d}|D ]+  }t        ||j                        s|j                  dk(  s*d}- |rg }|D ]  }t        ||j                        ru|j                  d	k(  rf|j                  \  }	}
|j                  rJ d
       |	dk7  r?|j                  |j                  j                  |	t        t        |
            f             |j                  |        ||j                  d<   v r   D ]
  } ||      } t!              rt#        d d d d      t%        |       y )Nr   F__c            	          t        
	j                   d       5   | i |}d d d        |S # 1 sw Y   S xY w)N.)OpCheckMode__name__)r'   r(   r/   failures_dictrR   methodrQ   new_method_nameprefixrP   testers      r   
new_methodzDgenerate_opcheck_tests.<locals>.construct_method.<locals>.new_method   s_    $$%Q&78" 1  001 M1 Ms   	4>
pytestmarkr   opcheck_only_oneTparametrizeNYIdevicezTried to autogenerate z but z already has method named z4. Please rename the original method on the TestCase.)getattrrD   wraps__dict__getpytest
isinstanceMarknamer'   r(   appendmarkrg   nextiterhasattrRuntimeErrorsetattr)attrrb   rc   rd   re   rn   rf   rs   new_pytestmarkargnames	argvaluesdecr`   ra   rS   r_   rR   rQ   rP   s    ``         @@r   construct_methodz0generate_opcheck_tests.<locals>.construct_method   s   4(6?G 4-$.		 
	 
	 
!
	 $,,00>>:>  %" ,dFKK0TYYBT5T'+$,  !#& 0D!$4m9S.2ii+)#';;55 $x/*11 & 7 7$,tDO/D.F!"
 %"))$/0 5C
##L133,_= - _
- 8_-((9xj I$$3#4 5*+ 
 	/:6r   )dir
startswithcallablerj   inspectcurrentframef_backgetframeinfor   ospathdirnameFailuresDictloadshould_update_failures_dict validate_failures_dict_structure!validate_failures_dict_formattingALL_TEST_UTILSitemsgenerate_tag_tests)rP   rQ   rR   rS   rT   mtest_methods
prev_framefilenamer~   rq   ry   rb   rc   r_   s   ````          @r   generate_opcheck_testsr      sU   N $ " X<< Xgh.B%C 	
L 
 ! ))+22
''
3A6,GGOOH%';
 !%%(C(E & M %]JI%&8997 97v :DD$t,,DJD 3(..0 	3NFFT662	33 x0EFg\ Es   /D7-D<c                    d }|j                   j                         D ]  \  }}|j                         D cg c]  \  }}d|vr
|d   dk(  r| }}}t        |      dkD  }	 |||	|      }
|j                  dd      j                  dd      }d	|z   }||v r||   D ]
  } ||
      }
 t	        | |      rt        d
| d      t        | ||
        y c c}}w )Nc                       fd}|S )Nc                 (   	 t         j                  j                  j                        }t         j                  j                  |j                  v }|sy sy t        d d d      # t        $ r}t        j                  d       |d }~ww xY w)NzCan't import operator zop 'za' was tagged with torch.Tag.pt2_compliant_tag but it failed some of the generated opcheck tests (z?). This may lead to silent correctness issues, please fix this.)r   _libraryutils	lookup_opAttributeErrorunittestSkipTestTagpt2_compliant_tagtagsAssertionError)selfr&   eop_marked_as_compliantdefinitely_not_pt2_compliantqualnamexfailed_testss       r   r   z8generate_tag_tests.<locals>.generate_test.<locals>.inner3  s    T^^))33H= &+YY%@%@BGG%K")/ xj !!? ##$  " T''*@
(KLRSSTs   )A* *	B3BBr   )r   r   r   r   s   ``` r   generate_testz)generate_tag_tests.<locals>.generate_test2  s    	$ r   rN   statusxfailr   ::_r\   test_pt2_compliant_tag_zTried to generate a test named z, but it exists already. This could be because of a name collision (where we generated two tests with the same name), or where we generated a test with the same name as an existing test.)datar   lenreplacerv   rw   rx   )rP   r_   rS   r   r   	test_dictteststatus_dictr   r   	generatedmangled_qualname	test_name	decorators                 r   r   r   1  s#   *  -11779 0) &/__%6
!k *5H%0 
 
 (+='9A'=$!(,H-X	 $++D#6>>sCH-0@@	 --29= 1	%i0	1 8Y'1) =K L  	)Y/;0
s   C)r   skipxsuccessc                    t        |       5 }|j                         }d d d        t        j                  |       }|j	                  d      }|k(  ry t               r&t        j                  |       }|j                          y |j                  d      }|j                  d      }t        j                  ||      }dj                  |      }t        d| d      # 1 sw Y   xY w)NT)to_str    
z

Expected the failures dict to be formatted a certain way. Please see the above diff; you can correct this either manually or by re-running the test with PYTORCH_OPCHECK_ACCEPT=1)openreadr   r   _saver   save
splitlinesdifflibunified_diffjoinrw   )rR   fpactualr_   expecteddiffs         r   r   r   j  s    	 	! R %%&89M""$"/H"$$))*<=""1%Hq!F1D774=D

TF # 	$  s   CC#failure_dictr   c                   
 | j                   } | j                         D ],  }|j                         D ]  \  }}t        |j	                               t        ddh      k7  rt        d      |d   }|t        vrt        d| dt               |j                  d      \  }
t        
fd|D              st        d| d	|       |D ]}  }
j                  |      s
t        |      d
z   d }	t        j                  dd|	      }	|j                  |k7  rMt        ||	      rZt        d| d| d|	 d|	 d|j                   d        / y)a  Validates the failures dict.

    The failure dict looks something like the following.
    It maps operator name (qualname) to a list of autogenerated tests.
    Each autogenerated test may have a check for the operator (if the operator is
    called by the test); the dictionary specifies if we should skip the check,
    or if we expect some check to fail.

    {
        "fbgemm::split_lengths": {
            "test_schema__test_split_lengths": {
                "comment": "you can put whatever you want into the comment section",
                "status": "xfail",
            }
            "test_schema__test_split_lengths_empty": {
                "comment": "",
                "status": "skip",
            },
        },
        "fbgemm::gather_lengths": {
            "test_schema__test_gather_lengths": {
                "comment": "",
                "status": "skip",
            },
        },
    }

    commentr   zGin failures_dict, expected sub-dict to have keys 'comment' and 'status'zIn failures_dict, got status=z but it needs to be in r\   c              3   @   K   | ]  }j                  |        y wr*   )r   ).0r   actual_test_names     r   	<genexpr>z3validate_failures_dict_structure.<locals>.<genexpr>  s     PT'2248Ps   zIn failures_dict, test name 'z' should begin with one of    Nz\[.*\]r   z!In failures dict, got test name 'z#'. We parsed this as running test 'z' on 'z', but z! does not exist on the TestCase 'z*]. Maybe you need to change the test name?)r   valuesr   setkeysrw   TEST_OPTIONSsplitanyr   r   resubr^   rv   )r   rT   rP   test_to_optionr   r   test_option
test_classr   base_test_namer   s             @r   r   r     s   >  $$L&--/ $2$8$8$: 	 Iy9>>#$Y,A(BB"]  $H-K,."3K=@WXdWef  ,5??3+?(J(PZPP"3I;>YZdYef  # '2248!1#d)a-/!B!#	2~!F$$
28^4"7	{ C%%)F&0@%&&GHYHYGZ [>? 	r   c                  Z    d} | t         j                  v xr t         j                  |    dk(  S )NPYTORCH_OPCHECK_ACCEPT1r   environ)keys    r   r   r     s(    
"C"**7CC!77r   c                  "    t         j                  S r*   )_is_inside_opcheck_modevaluer   r   r   is_inside_opcheck_moder     s    "(((r   c                   h     e Zd ZdZdee   dededddedefd	Zdd
Z fdZ	 fdZ
d ZddZ xZS )r]   z
    For a given test, OpCheckMode intercepts calls to operators and runs
    test_util(op, args, kwargs) for each intercepted (op, args, kwargs).
    rQ   test_util_name	test_utilr_   r   r   rR   c                 f    || _         || _        || _        || _        || _        || _        i | _        y r*   )rQ   r   r   r   r_   rR   seen_ops_to_errors)r   rQ   r   r   r_   r   rR   s          r   __init__zOpCheckMode.__init__  s?     % #," +"4 #%r   c                    | j                   j                         D ]  }| j                  j                  || j                        }t        | j                   |         dk(  sEt               r*| j                  j                  || j                  dd       n4|dk(  r/t        d| d| j                   d| j                   d	t                g }| j                   j                         D ][  }| j                  j                  || j                        }|dk7  r/t        | j                   |         dk(  rK|j                  |       ] |sy t               r/|D ])  }| j                  j                  || j                  d       + y | j                   |d      d   \  }}}}t        | j                  |||t               
      }t        d| j                   d| dt         d|       |)Nr   r   r   r   r   z8generate_opcheck_tests: Unexpected success for operator z	 on test z. This may mean that you have fixed this test failure. Please rerun the test with PYTORCH_OPCHECK_ACCEPT=1 to automatically update the test runner or manually remove the expected failure in the failure dict at zFor more details, see )	save_dataz,Test generated by `generate_opcheck_tests`, z, failed on operators z. This usually means that the operators are not implemented correctly and may lead to silently incorrect behavior. Set PYTORCH_OPCHECK_PRINT_BETTER_REPRO=1 for a standalone repro, or please see zX for more recommendations. To reproduce this problem locally, try to run the following:
)r   r   r_   
get_statusr   r   r   
set_statusOpCheckErrorrR   GDOCrr   generate_repror   should_print_better_repro)	r   r   option
failed_opsr&   exr'   r(   repro_commands	            r   maybe_raise_errors_on_exitz&OpCheckMode.maybe_raise_errors_on_exit  s   //446 	H''228T^^LF4**845:.0&&11 $..*b 2  (*V'j	$..1A BG
  $6674#f&
 
 )	* 
//446 	(H''228T^^LF#4**845:h'	( &(  K""--b$..'JK  $66z!}EaHBf&T6=V=X
 :4>>:J K##-, / f MMZO]	
 		r   c                     t         j                  | _        t        j                  j                  dd      | _        dt         _        dt        j                  d<   t        |    |i |S )NTORCHDYNAMO_DISABLEr   Tr   )	r   r   prev_is_opcheck_moder   r   rm   prev_dynamo_disablesuper	__enter__)r   r'   r(   	__class__s      r   r  zOpCheckMode.__enter__)  sV    $;$A$A!#%::>>2G#L (,%,/

()w $1&11r   c                    | j                   t        _        | j                  t        j
                  d<   	 | j                          t               r| j                  j                          t        | ,  |i |}|S # t        | ,  |i |}w xY w)Nr   )r   r   r   r  r   r   r   r   r_   r   r  __exit__)r   r'   r(   r/   r  s       r   r  zOpCheckMode.__exit__0  s    (,(A(A%,0,D,D

()	7++-*,""'')W%t6v6F W%t6v6Fs   4A: :Bc                     	 | j                  |||d       y # t        j                  j                  j                  $ r Y y w xY w)NF)r#   )r   r   r   r    UnsupportedFakeTensorException)r   r&   r'   r(   s       r   run_test_utilzOpCheckMode.run_test_util;  sA    	NN2tVN?  ,,KK 	
 	s    'AAc                    |r|ni }t        |t        j                  j                  t        j                  j                  f      s ||i |S t        j
                  j                         s<t        j
                  j                         st        j                  j                         r ||i |S t        |t        j                  j                        rt        |      }|j                         }|j                  d      d   }|| j                  vr ||i |S t        ||f      \  }} ||i |}	| j                  j!                  || j"                        }
|
dk(  s|
dk(  r3	 || j$                  vrg | j$                  |<   | j'                  |||       |	S |
dk(  r	 |	S # t(        $ rZ}t+               r#| j$                  |   j-                  ||||f       n"| j$                  |   j-                  ||d d f       Y d }~|	S d }~ww xY w)Nr   r   r   r   r   )ro   r   _opsOpOverloadPacket
OpOverloadjit
is_tracingis_scripting_dynamois_compiling resolve_unique_overload_or_throwrq   r   rQ   r+   r_   r   r   r   r	  	Exceptionr   rr   )r   r?   typesr'   r(   r   nsargs_ckwargs_cr/   r   r   s               r   __torch_function__zOpCheckMode.__torch_function__E  s   !r $!<!<ejj>S>S TU(((II  "yy%%'}}))+((( dEJJ7783D9D99;^^D!!$T__$(((+T6N;t&v&##..xHZ6W#4U4#:#::8:D++H5""4:  v  U,.++H5<<b$f=UV++H5<<b$d=ST Us   !0F 	G>$AG99G>r   N)r   N)r^   
__module____qualname____doc__liststrr   r   r   r  r  r	  r  __classcell__)r  s   @r   r]   r]     se    
%I% % 	%
 &% %  %66p2	'r   r]   c                  j    d} | t         j                  vryt         j                  |    }|dk(  xs |dk(  S )a  If set, the tests generated by `generate_opcheck_tests` will print a
    repro command on failure.

    In order to print the repro command, we need to save some tensors to disk.
    These will be saved under the following directory:
    {tempfile.gettempdir()}/pytorch_opcheck_safe_to_delete/.

    Although this is a temp folder, it will usually not automatically get cleaned
    up, so you'll need to manually delete it.
    "PYTORCH_OPCHECK_PRINT_BETTER_REPROFr   r   r   )r   r   s     r   r   r   o  s8     /C
"**JJsOEC<%5A:%r   )rT   raise_exceptionr$   r%   r#  c          	      4   |du |du z  rt        d      |i }t        | t              r| j                  } t        | t        j
                  j                        rt        |       } t        | t        j
                  j                        st        dt        |              |dk(  rt        t        j                               }t        |t              r|f}t        |t        t        f      r,t        |      j!                  t        j                               s-t        d| dt        t        j                                d      i }|D ]  }t        |   }		  |	| ||||       d	||<     |S # t"        $ r$}
|rt%        d
| d|
 d      |
|
||<   Y d}
~
Kd}
~
ww xY w)z'See torch.library.opcheck for docstringNzHopcheck(op, ...): if you specify one of rtol/atol, you must specify bothzeopcheck(op, ...): op must be instance of torch._ops.OpOverload, e.g. torch.ops.aten.sin.default, got ALLzopcheck(op, ..., test_utils=z'), expected test_utils to be subset of z but it was notr@   SUCCESSzopcheck(op, ...): z failed with z (scroll up for stack trace))
ValueErrorro   r	   _opoverloadr   r  r  r  r  typetupler   r   r  r  r   issubsetr  r   )r&   r'   r(   rT   r#  r$   r%   results_dictr   rc   r   s              r   opcheckr-    s    	&V
 	
 ~"k"^^"ejj112-b1b%**//0448H:?
 	
 U>..01
*c" ]
j5$-0J8P8P9 *:, 7$^%8%8%:;<OM
 	

 L )		*		)2tV$T:&/L#	)   	)"(= E2 3  ')L#	)s   E**	F3FFc                       e Zd Zy)r   N)r^   r  r  r   r   r   r   r     s    r   r   )dry_runr   r   r/  c                6   |rt         j                   j                         }t        j                  j	                  t        j                         d      }t         j                   j                  |      dz  }t        j                  j	                  |d| d      }	|s/t        j                  |d       t        j                  ||f|	       d|	 d}
nd	}
|j                  j                  j                  d
      \  }}|j                  }d| d| d| d|
 d|  d}|S )Npytorch_opcheck_safe_to_deletei repro_z.ptT)exist_okzargs, kwargs = torch.load("z")z# If you rerun your test with PYTORCH_OPCHECK_PRINT_BETTER_REPRO=1
# we will fill them in same (args, kwargs) as in your test
args = ()  # args to the operator
kwargs = {}  # kwargs to the operatorr   aJ  # =========================================================
# BEGIN REPRO SCRIPT
# =========================================================
import torch
from torch.testing._internal.optests import opcheck

# Make sure you have loaded the library that contains the op
# via an import or torch.ops.load_library(...)
op = torch.ops.r\   z

z'
opcheck(op, args, kwargs, test_utils="z")
# =========================================================
# END REPRO SCRIPT
# =========================================================
)datetimenowr   r   r   tempfile
gettempdir	timestampmakedirsr   r   _schemarq   r   _overloadname)r   r&   r'   r(   r   r/  r5  r   unix_timestampfilepathargs_kwargsr  rq   overloadr   s                  r   r   r     s    ##%ww||H//13ST!**44S9FB77<<~.>c&BCKKt,JJf~x03H:R@4 	 zz$$T*HBH QtfAhZ 0- 115 7H	I " r   c           	      8   t         j                  j                  | j                        }t	        |      dk7  r3t        d| j                   d|D cg c]  }|j                   c}       |d   j                  }|dk(  r| j                  S t        | |      S c c}w )Nr   zSopcheck can only test operators without overloads. Got the following overloads for z: r   r   )	r   _C_jit_get_schemas_for_operator_qualified_op_namer   rw   overload_namedefaultrj   )r&   all_schemasschemarD  s       r   r  r    s     ((889N9NOK
;1//1/D/D.ER3>?$$?@B
 	
  N00Mzz2}%% @s   Br   )indent	sort_keysr   zsThis is a dict containing failures for tests autogenerated by generate_opcheck_tests. For more details, please see c            
           e Zd ZdedefdZedddd       Zddee   fdZ	dd
Z
dededefdZd	ddedededee   fdZy	)r   r   r   c                      || _         || _        y r*   )r   r   )r   r   r   s      r   r   zFailuresDict.__init__  s    		r   FrW   r   c                   |rAt         j                  j                  |       s"t        | i       }t        j	                          |S t        |       5 }|j                         }|j                         dk(  rt        i t        d}n-t        j                  |      }d|v sJ d|v r|d   t        k(  sJ d d d        t        | d         S # 1 sw Y   xY w)Nr   _descriptionr   _versionr   rO  )r   r   existsr   r   r   r   stripDESCRIPTIONVERSIONjsonloads)r   rX   r/   r   contentsdcts         r   r   zFailuresDict.load  s    rww~~d3!$+FM$Z 	H2wwyH~~2%$/ ' jj*}$}!S(S_-GGG	H D#f+..	H 	Hs   A CCc                     t         | j                  t        d}t        j                  |fi t
        dz   }|r|S t        | j                  d      5 }|j                  |       d d d        y # 1 sw Y   y xY w)NrM  r   w)	rR  r   rS  rT  dumpsDUMP_OPTIONSr   r   write)r   r   to_dump
serializedr   s        r   r   zFailuresDict._save&  sk    'II
 ZZ8<84?
$))S! 	!RHHZ 	!	!s   A++A4Nc                 "    | j                         S r*   )r   )r   s    r   r   zFailuresDict.save5  s    zz|r   r   r   c                 X    || j                   vry| j                   |   }||vry||   d   S )Nr   r   r   )r   r   r   rW  s       r   r   zFailuresDict.get_status8  s9    499$ii!C9~h''r   r   r   r   c                    || j                   vri | j                   |<   | j                   |   }||vrd dd||<   |dk(  r||= y |||   d<   |	|||   d<   y y )Nr   )r   r   r   r   r   ra  )r   r   r   r   r   rW  s         r   r   zFailuresDict.set_status@  sx     499$"$DIIhii!C(,<C	NZI'-C	N8$",3Iy) #r   )r   r   )Fr  )r^   r  r  r  FailuresDictDatar   staticmethodr   r   r   r   r   r   r   r   r   r   r     s    S (8  "' / /&Xc] (3 (3 (3 ( "&44 4 	4 #4r   r  r*   )Qr4  r   rD   r   rT  r   r   r6  	threadingr   collections.abcr   typingr   r   r   r   r   torch._dynamotorch.utils._pytreer   _pytreer,   torch._dynamo.utilsr   torch._library.custom_opsr	   #torch._subclasses.schema_check_moder
   torch._utils_internalr   torch.overridesr   torch.testing._internal.optestsr   r   r   r  r   r.   boolr"   r  r  r*  dictfloatr0   r7   r9   rH   r+   rE   r   r   DEFAULT_TEST_UTILSDEPRECATED_DEFAULT_TEST_UTILSr  r   r   r   r   r   r   localr   r   r   r]   r   r  r-  r  r   r   r  r[  rc  rS  rR  r   r   r   r   <module>rw     sw        	 	    $ 1 1   $ $ + 1 ? 1 - S      


S/ cN
  5/ 5/ 	.   9

9
S/9 cN9
 9 5/9 5/9 
94   (

(
S/( cN(
 ( 5/( 5/( 
(,   "

"
S/" cN" 	" " 5/" 5/" 	"JCS CS C %"B& 1	 1 1! "3!2!2" ^  !36 !  )-;?.|G|GS	|G !|G $Dh$78	|G
 S	|G 
|G~30l -# $ .? ?.23i?CF?	?D8T 8
 *)//+  %  )\# \~&* (,5
 -?   5ejj##UZZ%@%@+MN5
S/5 T#s(^$5
 c8C=()5 5 5/5 5/5 
#s(^5p	9 	 .
.

. S/. cN	. . . 	.b&

##&
ZZ&" $/ T#tCH~"5667  $$(6+ G4 G4r   