
    Vh                        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 d dl	m
Z
mZmZ d dlmZmZmZ d dlmZmZmZmZ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" d dl#m$Z$m%Z%m&Z&m'Z' d dl(m)Z) d dl*m+Z+ d Z,d Z- ej\                  ed       G d de             Z/e%e)eeeeeeeee+gZ0e$eee
gZ1e&egZ2e'egZ3e"eegZ4de5de6e    de7e6e       de5de8e5e6e    f   f
dZ9y)    N)MultiProcessTestCase)TEST_WITH_DEV_DBG_ASANfind_free_portIS_SANDCASTLE)CudaDdpComparisonTestDdpComparisonTestDdpUnderDistAutogradTest)CudaRemoteModuleTestRemoteModuleTestThreeWorkersRemoteModuleTest)DistAutogradTestCudaDistAutogradTestFaultyAgentDistAutogradTestTensorPipeAgentDistAutogradTestTensorPipeCudaDistAutogradTest)DistOptimizerTest)JitDistAutogradTest)
JitRpcTest)JitFaultyAgentRpcTest)RpcAgentTestFixture)FaultyAgentRpcTest)CudaRpcTestRpcTestTensorPipeAgentRpcTestTensorPipeAgentCudaRpcTest)ParameterServerTest)ReinforcementLearningRpcTestc                      t         j                  j                  dd       } | dk(  r8dt         j                  d<   t        t	                     t         j                  d<   y y )NRPC_INIT_WITH_TCP1z	127.0.0.1MASTER_ADDRMASTER_PORT)osenvirongetstrr   use_tcp_inits    ]/home/dcms/DCMS/lib/python3.12/site-packages/torch/testing/_internal/distributed/rpc_utils.py_check_and_set_tcp_initr*   :   sJ     ::>>"5t<Ls$/

=!$'(8$9

=!     c                      t         j                  j                  dd       } | dk(  r#t         j                  d= t         j                  d= y y )Nr   r    r!   r"   )r#   r$   r%   r'   s    r)   _check_and_unset_tcp_initr-   C   s<    ::>>"5t<LsJJ}%JJ}% r+   z<Skip ASAN as torch + multiprocessing spawn have known issuesc                   (     e Zd Z fdZ fdZ xZS )SpawnHelperc                 V    t         |           t                | j                          y N)supersetUpr*   _spawn_processesself	__class__s    r)   r3   zSpawnHelper.setUpW   s    !r+   c                 6    t                t        | 	          y r1   )r-   r2   tearDownr5   s    r)   r9   zSpawnHelper.tearDown\   s    !#r+   )__name__
__module____qualname__r3   r9   __classcell__)r7   s   @r)   r/   r/   S   s     
 r+   r/   prefixmixintestsmodule_namereturnc                     i }|D ]^  }t         r&t        r t        d| dt        j                         /|  |j
                   }t        |||t        fi       }||_        |||<   ` |S )aF  Mix in the classes needed to autogenerate the tests based on the params.

    Takes a series of test suites, each written against a "generic" agent (i.e.,
    derived from the abstract RpcAgentTestFixture class), as the `tests` args.
    Takes a concrete subclass of RpcAgentTestFixture, which specializes it for a
    certain agent, as the `mixin` arg. Produces all combinations of them.
    Returns a dictionary of class names to class type
    objects which can be inserted into the global namespace of the calling
    module. The name of each test will be a concatenation of the `prefix` arg
    and the original name of the test suite.
    The `module_name` should be the name of the calling module so
    that the classes can be fixed to make it look like they belong to it, which
    is necessary for pickling to work on them.
    zSkipping test zi on sandcastle for the following reason: Skip dev-asan as torch + multiprocessing spawn have known issues)file)	r   r   printsysstderrr:   typer/   r;   )r>   r?   r@   rA   ret
test_classnameclass_s           r)   generate_testsrM      s    ( 13C 

3  -S SY\YcYce *--./dZ<bA'D	
 Jr+   ):r#   rF   unittest*torch.testing._internal.common_distributedr   $torch.testing._internal.common_utilsr   r   r   @torch.testing._internal.distributed.ddp_under_dist_autograd_testr   r   r	   =torch.testing._internal.distributed.nn.api.remote_module_testr
   r   r   :torch.testing._internal.distributed.rpc.dist_autograd_testr   r   r   r   r   ;torch.testing._internal.distributed.rpc.dist_optimizer_testr   >torch.testing._internal.distributed.rpc.jit.dist_autograd_testr   4torch.testing._internal.distributed.rpc.jit.rpc_testr   ;torch.testing._internal.distributed.rpc.jit.rpc_test_faultyr   >torch.testing._internal.distributed.rpc.rpc_agent_test_fixturer   =torch.testing._internal.distributed.rpc.faulty_agent_rpc_testr   0torch.testing._internal.distributed.rpc.rpc_testr   r   r   r   Ftorch.testing._internal.distributed.rpc.examples.parameter_server_testr   Ptorch.testing._internal.distributed.rpc.examples.reinforcement_learning_rpc_testr   r*   r-   skipIfr/   GENERIC_TESTSGENERIC_CUDA_TESTSTENSORPIPE_TESTSTENSORPIPE_CUDA_TESTSFAULTY_AGENT_TESTSr&   rH   listdictrM    r+   r)   <module>rf      sm   
 
  K 
 
 
  L  g
:&  Z& "    	  # 
 "     #$  ()*  	 
 
#t'(
() r+   