+
    $Lj8                     d   ^ RI t ^ RIHt ^ RIHt ^ RIt^ RIt^ RIH	t	 ^RI
HtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHt ]! RR4      '       d   ^ RI H!t! M^ RI"H!t! ]! 4       '       d
   ^ RI#H$u H%t& ^R	I'H(t( ^R
I)H*t* ](! ]+4      t,RR R llt-RR lt.RR R llt/RR R llt0R# )    N)Path)Optional)
load_model)
MODEL_NAMEOPTIMIZER_NAMERNG_STATE_NAMESAFE_MODEL_NAMESAFE_WEIGHTS_NAMESAMPLER_NAMESCALER_NAMESCHEDULER_NAMEWEIGHTS_NAMEget_pretty_nameis_cuda_availableis_hpu_availableis_mlu_availableis_musa_availableis_neuron_availableis_sdaa_availableis_torch_versionis_torch_xla_availableis_xpu_availableloadsavez>=z2.4.0)
GradScaler)
get_logger)PartialStatec                    V ^8  d   QhR\         R\        \        ,          R\        R\        R\        R\        R\        R\        \
        ,          R	\        R
\        /
# )   
output_dirmodel_states
optimizers
schedulersdataloadersprocess_indexstepscalersave_on_each_nodesafe_serialization)strlistdictintr   r   bool)formats   "D/app/.local/lib/python3.14/site-packages/accelerate/checkpointing.py__annotate__r1   ?   s     u uut*u u 	u
 u u u Z u u u    c
                
   \        V 4      p \        V4       Fl  w  rV	'       g   \        M\        pV
^ 8  d   VP	                  RRV
 R24      pV P                  V4      p\        WWR7       \        P                  RV 24       Kn  	  \        V4       Fi  w  rVP                  4       pV
^ 8X  d
   \         R2M\         RV
 R2pV P                  V4      p\        VVVRR7       \        P                  RV 24       Kk  	  \        V4       Fj  w  p
pVP                  4       pV
^ 8X  d
   \         R2M\         RV
 R2pV P                  V4      p\        VVVRR7       \        P                  RV 24       Kl  	  \        V4       F  w  p
pV
^ 8X  d
   \         R2M\         RV
 R2pV P                  V4      p^R	IHpHp \!        VP"                  V4      '       d2   VP%                  4       p\!        VV4      '       d   \        VVVRR7       \'        VR
R4      '       dH   V
^ 8X  d   RMRV
 R2pV P                  V4      pVP                  4       p\(        P                  ! VV4       \        P                  RV
 RV 24       EK   	  VeU   VP                  4       pV P                  \*        4      p\(        P                  ! VV4       \        P                  RV 24       / p\,         RV R2pVVR&   \.        P0                  ! 4       VR&   \2        P.                  P5                  4       VR&   \(        P6                  ! 4       VR&   \9        4       '       d"   \(        P:                  P=                  4       VR&   \?        4       '       d#   \(        P@                  P=                  4       VR&   Mc\C        4       '       d#   \(        PD                  P=                  4       VR&   M1\G        4       '       d"   \(        PH                  P=                  4       VR&   \K        4       '       d"   \(        PL                  P=                  4       VR&   \O        4       '       d"   \(        PP                  P=                  4       VR&   \S        4       '       d"   \(        PT                  P=                  4       VR&   \W        4       '       d   \X        P6                  ! 4       VR&   V P                  V4      p \(        P                  ! VV 4       \        P                  RV  24       V # )a  
Saves the current states of the models, optimizers, scaler, and RNG generators to a given directory.

<Tip>

If `safe_serialization` is `True`, models will be saved with `safetensors` while the rest are saved using native
`pickle`.

</Tip>

Args:
    output_dir (`str` or `os.PathLike`):
        The name of the folder to save all relevant weights and states.
    model_states (`List[torch.nn.Module]`):
        A list of model states
    optimizers (`List[torch.optim.Optimizer]`):
        A list of optimizer instances
    schedulers (`List[torch.optim.lr_scheduler._LRScheduler]`):
        A list of learning rate schedulers
    dataloaders (`List[torch.utils.data.DataLoader]`):
        A list of dataloader instances to save their sampler states
    process_index (`int`):
        The current process index in the Accelerator state
    step (`int`):
        The current step in the internal step tracker
    scaler (`torch.amp.GradScaler`, *optional*):
        An optional gradient scaler instance to save;
    save_on_each_node (`bool`, *optional*):
        Whether to save on every node, or only the main node.
    safe_serialization (`bool`, *optional*, defaults to `True`):
        Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
._)r(   r)   zModel weights saved in .binFzOptimizer state saved in zScheduler state saved in IterableDatasetShardSeedableRandomSampleruse_stateful_dataloaderdl_state_dict.bindl_state_dict_zSampler state for dataloader z
 saved in zGradient scaler state saved in .pklr&   random_statenumpy_random_seedtorch_manual_seedtorch_xpu_manual_seedtorch_mlu_manual_seedtorch_sdaa_manual_seedtorch_musa_manual_seedtorch_hpu_manual_seedtorch_neuron_manual_seedtorch_cuda_manual_seedxm_seedzRandom states saved in )-r   	enumerater   r
   replacejoinpathr   loggerinfo
state_dictr   r   r   data_loaderr8   r9   
isinstancedatasetget_samplergetattrtorchr   r   randomgetstatenp	get_stateget_rng_stater   xpuget_rng_state_allr   mlur   sdaar   musar   hpur   neuronr   cudar   xm)!r    r!   r"   r#   r$   r%   r&   r'   r(   r)   istateweights_nameoutput_model_fileoptoptimizer_nameoutput_optimizer_file	schedulerscheduler_nameoutput_scheduler_file
dataloadersampler_nameoutput_sampler_filer8   r9   samplerdataloader_state_dict_name!output_dataloader_state_dict_filerN   output_scaler_filestatesstates_nameoutput_states_files!   &&&&&&&&&&                       r0   save_accelerator_staterw   ?   sh   X j!Jl++=|CTq5'//q1X>L&//=U9Jr-.?-@AB , J' 45FN+40>BRRSTUSVVZ@[ * 3 3N CU)=Nchi/0E/FGH ( "*-9$$&45FN+40>BRRSTUSVVZ@[ * 3 3N CU)=Nchi/0E/FGH . #;/:01Q,t,|nAaSPT<U(11,?Lj((*>?? ,,.G'#899W1EVkpq:8%@@@AQ)<n]^\__cLd&0:0C0CD^0_-#..0JJJz#DE3A3jAT@UVW 0$ !!#'00=

5,-56H5IJKF#$Am_D9KF6N#__.F>"$))"5"5"7F"'"5"5"7F*/))*E*E*G&'*/))*E*E*G&'			+0::+G+G+I'(			+0::+G+G+I'(*/))*E*E*G&'-2\\-K-K-M)*+0::+G+G+I'(,,.y#,,[9	JJv)*
KK)*<)=>?r2   c	                   \        4       p
VR$9  d   \        R4      hVf   RpMVR8X  d   \        4       P                  pVf   / p\	        V 4      p \        V4       F  w  rV^ 8  d   RV 2MRpV P                  \         V R24      pVP                  4       '       d   \        W3R\        V4      /V	B  K\  V P                  \         V R24      p\        WR	7      pVP                  ! V3/ V	B  K  	  \        P                  R
4       \        V4       FX  w  ppV^ 8X  d
   \          R2M\          RV R2pV P                  V4      p\        V3RV/VB pW+,          P                  V4       KZ  	  \        P                  R4       \        V4       FP  w  ppV^ 8X  d
   \"         R2M\"         RV R2pV P                  V4      p\        V3/ VB pVP                  V4       KR  	  \        P                  R4       \        V4       F  w  ppV^ 8X  d
   \$         R2M\$         RV R2pV P                  V4      p^RIHpHp \-        VP.                  V4      '       d=   VP1                  4       p\-        VV4      '       d   VP3                  \        V4      4      p\5        VRR4      '       g   K  V^ 8X  d   RMRV R2pV P                  V4      pVP                  4       '       g   K  \        V3/ VB pVP                  V4       EK   	  \        P                  R4       VeG   V P                  \6        4      p \        V 4      p!VP                  V!4       \        P                  R4        \        V P                  \8         RV R24      4      p"RV"9   d   V"R,          V
R&   \:        P<                  ! V"R,          4       \>        P:                  PA                  V"R,          4       \B        PD                  ! V"R,          4       \G        4       '       d'   \B        PH                  PK                  V"R,          4       \M        4       '       d)   \B        PN                  PK                  V"R,          4       EM\Q        4       '       d(   \B        PR                  PK                  V"R,          4       M\U        4       '       d(   \B        PV                  PK                  V"R,          4       M\Y        4       '       d(   \B        PZ                  PK                  V"R,          4       M]\]        4       '       d(   \B        P^                  PK                  V"R,          4       M&\B        P`                  PK                  V"R ,          4       \c        4       '       d   \d        PD                  ! V"R!,          4       \        P                  R"4       V
#   \f         d    \        P                  R#4        T
# i ; i)%a  
Loads states of the models, optimizers, scaler, and RNG generators from a given directory.

Args:
    input_dir (`str` or `os.PathLike`):
        The name of the folder to load all relevant weights and states.
    models (`List[torch.nn.Module]`):
        A list of model instances
    optimizers (`List[torch.optim.Optimizer]`):
        A list of optimizer instances
    schedulers (`List[torch.optim.lr_scheduler._LRScheduler]`):
        A list of learning rate schedulers
    dataloaders (`List[torch.utils.data.DataLoader]`):
        A list of dataloader instances used in your program
    process_index (`int`):
        The current process index in the Accelerator state
    scaler (`torch.amp.GradScaler`, *optional*):
        An optional *GradScaler* instance to load
    map_location (`str`, *optional*):
        What device to load the optimizer state onto. Should be one of either "cpu" or "on_device".
    load_kwargs (`dict`, *optional*):
        Additional arguments that can be passed to the `load` function.
    load_model_func_kwargs (`dict`, *optional*):
        Additional arguments that can be passed to the model's `load_state_dict` method.

Returns:
    `dict`: Contains the `Accelerator` attributes to override while loading the state.
cpu	on_devicezaUnsupported optimizer map location passed, please choose one of `None`, `'cpu'`, or `'on_device'`r5    z.safetensorsdevicer6   )map_locationz%All model weights loaded successfullyr}   z(All optimizer states loaded successfullyz(All scheduler states loaded successfullyr7   r:   Fr;   r<   z1All dataloader sampler states loaded successfullyz$GradScaler state loaded successfullyr=   r&   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   z%All random states loaded successfullyzCould not load random states)Nry   rz   )4r,   	TypeErrorr   r|   r   rI   rK   r	   existsr   r*   r   r   load_state_dictrL   rM   r   r   r   rO   r8   r9   rP   rQ   rR   set_samplerrS   r   r   rU   setstaterW   	set_staterT   set_rng_stater   rZ   set_rng_state_allr   r\   r   r]   r   r^   r   r_   r   r`   ra   r   rb   	Exception)#	input_dirmodelsr"   r#   r$   r%   r'   r}   load_kwargsload_model_func_kwargsoverride_attributesrc   modelendinginput_model_filerN   rg   rh   input_optimizer_fileoptimizer_staterj   rk   input_scheduler_filescheduler_staterm   rn   input_sampler_filer8   r9   rp   rq    input_dataloader_state_dict_fileinput_scaler_filescaler_statert   s#   &&&&&&&&&,                         r0   load_accelerator_stater      s   R &55o
 	
 		$#~,,YIf%E1QCr$--0A&.VW""$$ucs<7HcLbc  )11ZL2MN.JJ!!*G0FG & KK78 J'345FN+40>BRRSTUSVVZ@[(11.A3^,^R]^%%o6	 (
 KK:; "*-945FN+40>BRRSTUSVVZ@[(11.A3C{C!!/2	 .
 KK:;";/:01Q,t,|nAaSPT<U&//=Lj((*>?? ,,.G'#899$006H1IJ:8%@@@AQ)<n]^\__cLd&/8/A/AB\/],/6688!"BRkR
**:6 0  KKCD %..{;-.|,:;4i((N+;1]O4)PQRV*0.'~./
		F#678F#678II''/F(GHII''/F(GH  JJ((0H)IJ  JJ((0H)IJII''/F(GH ""LL**62L+MNJJ((0H)IJ!##VI./;<   4234s   &I	V1 1 WWc                0    V ^8  d   QhR\         R\        /# )r   indexr(   )r-   r.   )r/   s   "r0   r1   r1   C  s     O O OD Or2   c                    \        V4      RV R2,          p\        P                  R\        V 4       RV 24       \	        V P                  4       WCR7       R# )zD
Saves the state of `obj` to `{path}/custom_checkpoint_{index}.pkl`
custom_checkpoint_r=   zSaving the state of z to )r(   N)r   rL   rM   r   r   rN   )objpathr   r(   save_locations   &&&& r0   save_custom_stater   C  sM    
 J#5eWD!AAM
KK&s';&<DPQ	=Nr2   c                $    V ^8  d   QhR\         /# )r   r   )r-   )r/   s   "r0   r1   r1   M  s     U U Ur2   c                    V RV R2p\         P                  R\        V 4       RV 24       V P                  \	        VRRR7      4       R# )	z
Loads the state of `obj` at `{path}/custom_checkpoint_{index}.pkl`. Will always set `weights_only=False` when
loading the state.
z/custom_checkpoint_r=   zLoading the state of z from ry   F)r}   weights_onlyN)rL   rM   r   r   r   )r   r   r   load_locations   &&& r0   load_custom_stater   M  sN    
 f/wd;M
KK'(<'=VM?ST]USTr2   )NFT)NNN)r   F)r   )1rU   pathlibr   typingr   numpyrW   rT   safetensors.torchr   utilsr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	torch.ampr   torch.cuda.amptorch_xla.core.xla_modelcore	xla_modelrb   loggingr   rd   r   __name__rL   rw   r   r   r    r2   r0   <module>r      s         (     2 D'""$)))   
H	upIXOU Ur2   