L iA"ddlmZddlmZddlZddlmZddlmZmZm Z m Z m Z gdZ ddee eejfd efd Zd eefd Z dd edee eejfd dfd Zdeed dfdZde d dfdZde d dfdZddZddZd e fdZy))Iterable)UnionN)Tensor) _lazy_call _lazy_initcurrent_device device_countis_initialized) get_rng_stateget_rng_state_all set_rng_stateset_rng_state_all manual_seedmanual_seed_allseedseed_all initial_seeddevicereturnc8tt|trtj|}n&t|t rtjd|}|j }| t}tjj|}|jS)aRReturn 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: ``'cuda'`` (i.e., ``torch.device('cuda')``, the current CUDA device). .. warning:: This function eagerly initializes CUDA. cuda) r isinstancestrtorchrintindexr rdefault_generators get_state)ridxdefault_generators W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/cuda/random.pyr r suL&#f% FC ff- ,,C { 55c:  & & ((cbttDcgc] }t|}}|Scc}w)zQReturn a list of ByteTensor representing the random number states of all devices.)ranger r )iresultss r"r r .s,).|~)>?A}Q?G? N@s, new_statec|tsGtjj5j tj dddt trtjn&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: ``'cuda'`` (i.e., ``torch.device('cuda')``, the current CUDA device). ) memory_formatNrcj}| t}tjj|}|j yN)rr rrr set_state)r r!rr(s r"cbzset_rng_state..cbHs<ll ; "C!JJ99#>##I.r#) r r_C_DisableFuncTorchclonecontiguous_formatrrrrr)r(rr.s`` r"rr4s   XX ' ' ) O"e6M6MNI O&#f% FC ff-/rN! O Os !B22B; 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)r3r&states r"rrRs& j) 5eQ r#rc@tfd}t|dy)aSet the seed for generating random numbers for the current GPU. It's safe to call this function if CUDA 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 rrrr)r r!rs r"r.zmanual_seed..cbks.!JJ99#>%%d+r#T)rNrrrr.s` r"rr\s t9D, rr#c@tfd}t|dy)zSet the seed for generating random numbers on all GPUs. It's safe to call this function if CUDA is not available; in that case, it is silently ignored. Args: seed (int): The desired seed. cttD]0}tjj|}|j 2yr,)r%r rrrr)r&r!rs r"r.zmanual_seed_all..cb~s<|~& 0A % = =a @   ) )$ / 0r#T)rNr9r:s` r"rrss t9D0 rD!r#c d}t|y)atSet the seed for generating random numbers to a random number for the current GPU. It's safe to call this function if CUDA is not available; in that case, it is silently ignored. .. warning:: If you are working with a multi-GPU model, this function will only initialize the seed on one GPU. To initialize all GPUs, use :func:`seed_all`. crt}tjj|}|j yr,)r rrrrr r!s r"r.zseed..cbs+!JJ99#> r#Nrr.s r"rrs! rNr#c 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 CUDA is not available; in that case, it is silently ignored. cd}d}ttD]U}tjj|}|s#|j |j }d}E|j|Wy)NrFT)r%r rrrrrr) random_seedseededr&r!s r"r.zseed_all..cbsg |~& ;A % = =a @ !&&(/<<> !--k: ;r#Nr@rAs r"rrs ;rNr#ctt}tjj|}|j S)zyReturn the current random seed of the current GPU. .. warning:: This function eagerly initializes CUDA. )rr rrrrr?s r"rrs5 L  C 55c:  ) ) ++r#)r)rN)collections.abcrtypingrrrrrr r r __all__rrrr listr rrrrrrrr#r"rMs$ RR )%S%,, 67)V),4<@F$S#u||%;< < (6"2 t cd."#"$"&&, ,c ,r#