L iwddlmZddlmZddlZddlmZddlmZmZm Z m Z ddee e ejfdefd Zdeefd Z dd edee e ejfddfd Zd eeddfdZde ddfdZde ddfdZddZddZde fdZgdZy))Iterable)UnionN)Tensor) _lazy_call _lazy_initcurrent_device device_countdevicereturnc8tt|trtj|}n&t|t rtjd|}|j }| t}tjj|}|jS)aNReturn the random number generator state of the specified GPU as a ByteTensor. Args: device (torch.device or int, optional): The device to return the RNG state of. Default: ``'xpu'`` (i.e., ``torch.device('xpu')``, the current XPU device). .. warning:: This function eagerly initializes XPU. xpu) r isinstancestrtorchr intindexr rdefault_generators get_state)r idxdefault_generators V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/xpu/random.py get_rng_stater suL&#f% FC eV, ,,C { 44S9  & & ((cbttDcgc] }t|}}|Scc}w)zQReturn a list of ByteTensor representing the random number states of all devices.)ranger r)iresultss rget_rng_state_allr!s,).|~)>?A}Q?G? N@s, new_statechtjj5|jtjdddt t rtjn&t trtjdfd}t|y#1swYgxYw)a,Set the random number generator state of the specified GPU. Args: new_state (torch.ByteTensor): The desired state device (torch.device or int, optional): The device to set the RNG state. Default: ``'xpu'`` (i.e., ``torch.device('xpu')``, the current XPU device). ) memory_formatNrcj}| t}tjj|}|j yN)rr rrr set_state)rrr new_state_copys rcbzset_rng_state..cb8s<ll ; "C!II88=##N3r) r_C_DisableFuncTorchclonecontiguous_formatrrr rr)r r r'r&s ` @r set_rng_stater,'s  # # %P"u7N7NOP&#f% FC eV,4rNPPs !B((B1 new_statescBt|D]\}}t||y)zSet the random number generator state of all devices. Args: new_states (Iterable of torch.ByteTensor): The desired state for each device. N) enumerater,)r-rstates rset_rng_state_allr1Bs& j) 5eQ rseedc@tfd}t|dy)aSet the seed for generating random numbers for the current GPU. It's safe to call this function if XPU is not available; in that case, it is silently ignored. Args: seed (int): The desired seed. .. warning:: If you are working with a multi-GPU model, this function is insufficient to get determinism. To seed all GPUs, use :func:`manual_seed_all`. cvt}tjj|}|j yr$)r rrr manual_seed)rrr2s rr'zmanual_seed..cbZs.!II88=%%d+rT)r2Nrrr2r's` rr5r5Ls t9D, rrc@tfd}t|dy)zSet the seed for generating random numbers on all GPUs. It's safe to call this function if XPU is not available; in that case, it is silently ignored. Args: seed (int): The desired seed. cttD]0}tjj|}|j 2yr$)rr rrrr5)rrr2s rr'zmanual_seed_all..cbls<|~& 0A % < .cb~s+!II88= rNrr's rr2r2ts! rNrc d}t|y)zSet the seed for generating random numbers to a random number on all GPUs. It's safe to call this function if XPU is not available; in that case, it is silently ignored. cd}d}ttD]U}tjj|}|s#|j |j }d}E|j|Wy)NrFT)rr rrrr2 initial_seedr5) random_seedseededrrs rr'zseed_all..cbsg |~& ;A % < !--k: ;rNr?r@s rr:r:s ;rNrctt}tjj|}|j S)zxReturn the current random seed of the current GPU. .. warning:: This function eagerly initializes XPU. )rr rrrrCr>s rrCrCs5 L  C 44S9  ) ) ++r) rrr,r1r5r;r2r:rC)r)r N)collections.abcrtypingrrrrrr r rrr rlistrr,r1r5r;r2r:rC__all__rrrMs$ BB)%S%,, 67)F),4<@E$S#u||%;< 6 (6"2 t cd,"#"$"$$* ,c , r