~L iddlZddlZddlmZddlZddlmZdejddfdZdejfdZ dejjfdZ de fd Z dd Zde fd Zd aej" ddefd Zy)N) Generator)default_generator new_statereturnc.tj|y)zSets the random number generator state. .. note:: This function only works for CPU. For CUDA, please use :func:`torch.manual_seed`, which works for both CPU and CUDA. Args: new_state (torch.ByteTensor): The desired state N)r set_state)rs R/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/random.py set_rng_stater s *c*tjS)zReturns the random number generator state as a `torch.ByteTensor`. .. note:: The returned state is for the default generator on CPU only. See also: :func:`torch.random.fork_rng`. )r get_stater r get_rng_staters  & & ((r ct|}ddl}|jjs|jj |ddl}|j js|j j|ddl}|jjs|jj |t|tj|S)aSets the seed for generating random numbers on all devices. Returns a `torch.Generator` object. Args: seed (int): The desired seed. Value must be within the inclusive range `[-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]`. Otherwise, a RuntimeError is raised. Negative inputs are remapped to positive values with the formula `0xffff_ffff_ffff_ffff + seed`. rN) int torch.cudacuda_is_in_bad_forkmanual_seed_all torch.mpsmps manual_seed torch.xpuxpu_seed_custom_devicerseedtorchs r rr s t9D :: % % ' ""4( 99 $ $ & d# 99 $ $ & !!$'  ( ( ..r ctj}ddl}|jj s|jj |ddl}|jj s|jj|ddl }|jj s|jj |t||S)zSets the seed for generating random numbers to a non-deterministic random number on all devices. Returns a 64 bit number used to seed the RNG. rN) rrrrrrrrrrrrrs r rr?s  ! ! #D :: % % ' ""4( 99 $ $ & d# 99 $ $ & !!$' Kr c|t|}tjj}t t|rt t|}d}d}t ||r1t ||r%t ||st |||y y d|d}|d|d|d|dz }t j|td y y ) zSets the seed to generate random numbers for custom device. Args: seed (int): The desired seed. See [Note: support the custom device with privateuse1] rrzSet seed for `z0` device does not take effect, please add API's `z` and `z` to `z` device module.) stacklevelN) rr_C_get_privateuse1_backend_namehasattrgetattrwarningswarn UserWarning)rcustom_backend_namecustom_device_mod_bad_fork_name_seed_all_namemessages r rrXs t9D((@@Bu)*#E+>?** $n 5' ~; >7,n=?:)>:4@@'':&;;klG >*'.1AH[G\\lm mG MM';1 =+r c*tjS)zReturns the initial seed for generating random numbers as a Python `long`. .. note:: The returned seed is for the default generator on CPU only. )r initial_seedrr r r1r1qs  ) ) ++r Fc#K|dk(rdytj|j}tt|d}|t d|ddz|sdy||j }|dkDrt s|jd|d|d |jd |jd |jd |jd |d|d|jd|d|d}tj|datt|}n t|}tj}|D cgc]} |j| } } dtj|t|| D]\} } |j| | ycc} w#tj|t|| D]\} } |j| | wxYww)az Forks the RNG, so that when you return, the RNG is reset to the state that it was previously in. Args: devices (iterable of Device IDs): devices for which to fork the RNG. CPU RNG state is always forked. By default, :meth:`fork_rng` operates on all devices, but will emit a warning if your machine has a lot of devices, since this function will run very slowly in that case. If you explicitly specify devices, this warning will be suppressed enabled (bool): if ``False``, the RNG is not forked. This is a convenience argument for easily disabling the context manager without having to delete it and unindent your Python code under it. device_type (str): device type str, default is `cuda`. As for supported device, see details in :ref:`accelerator` metaNztorch has no module of `z`, you should register z,a module by `torch._register_device_module`.z reports that you have z& available devices, and you have used z_ without explicitly specifying which devices are being used. For safety, we initialize *every* zA device by default, which can be quite slow if you have a lot of z5s. If you know that you are only making use of a few z' devices, set the environment variable z_VISIBLE_DEVICES or the 'z' keyword argument of z with the set of devices you are actually using. For example, if you are using CPU only, set device.upper()_VISIBLE_DEVICES= or devices=[]; if you are using device 0 only, set zb_VISIBLE_DEVICES=0 or devices=[0]. To initialize all devices and suppress this warning, set the 'z#' keyword argument to `range(torch.z.device_count())`.T)rdevicetyper' RuntimeError device_count_fork_rng_warned_alreadyupperr(r)listrangerr zip) devicesenabled_caller _devices_kw device_type device_mod num_devicesr/ cpu_rng_stater5device_rng_statesdevice_rng_states r fork_rngrH}s'2f ,,{+00K T2J&{m3J K< =     --/ ?#;$$&''>{mL!!( *55@5F5F5H4IJ66A6G6G6I5JK((3(9(9(;'< @  MM' "'+ $u[)*w-'')MHOPf11&9PP?  M*(+G5F(G ? $F$  $ $%5v > ? Q M*(+G5F(G ? $F$  $ $%5v > ?s+DFGFAG=GG)rN)NTrHr>r) contextlibr(collections.abcrrtorch._CrTensorr rr$rrrrr1r9contextmanagerrHrr r rNs% & +U\\ +d +)u||)/++/>c2>2,c,!     M?  M?M?r