Ë
      çi¼  ã                   óº   — d dl Z d dlZd dlmZmZ d dl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  e j(                  e«      Z G d
„ de«      Zy)é    N)ÚAnyÚOptional)Úapply_to_collection)ÚRequirementCache)Úoverride)Ú_XLA_AVAILABLE)ÚTorchCheckpointIO)Úget_filesystem)Ú_PATHc            
       ód   ‡ — e Zd ZdZdededdfˆ fd„Zeddeeef   de	d	e
e   ddfd
„«       Zˆ xZS )ÚXLACheckpointIOz¶CheckpointIO that utilizes ``xm.save`` to save checkpoints for TPU training strategies.

    .. warning::  This is an :ref:`experimental <versioning:Experimental API>` feature.

    ÚargsÚkwargsÚreturnNc                 ó`   •— t         st        t        t         «      «      ‚t        ‰| �  |i |¤Ž y ©N)r   ÚModuleNotFoundErrorÚstrÚsuperÚ__init__)Úselfr   r   Ú	__class__s      €út/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/lightning_fabric/plugins/io/xla.pyr   zXLACheckpointIO.__init__&   s(   ø€ ÝÜ%¤c¬.Ó&9Ó:Ð:Ü‰Ñ˜$Ð) &Ó)ó    Ú
checkpointÚpathÚstorage_optionsc                 ó´  — |�#t        d| j                  j                  › d�«      ‚t        |«      }|j	                  t
        j                  j                  |«      d¬«       t        d«      r#ddl	m
}m}m} t        |||f|j                  «      }ddlmc m} |j%                  |d¬	«      }	t&        j)                  d
|› �«       t+        j,                  |	|«       y)a|  Save model/training states as a checkpoint file through state-dump and file-write.

        Args:
            checkpoint: dict containing model and trainer state
            path: write-target path
            storage_options: not used in ``XLACheckpointIO.save_checkpoint``

        Raises:
            TypeError:
                If ``storage_options`` arg is passed in

        Nze`Trainer.save_checkpoint(..., storage_options=...)` with `storage_options` arg is not supported for `za`. Please implement your custom `CheckpointIO` to define how you'd like to use `storage_options`.T)Úexist_okÚ	omegaconfr   )Ú
DictConfigÚ
ListConfigÚ	OmegaConf)ÚconvertzSaving checkpoint: )Ú	TypeErrorr   Ú__name__r
   ÚmakedirsÚosr   Údirnamer   r    r!   r"   r#   r   Úto_containerÚtorch_xla.core.xla_modelÚcoreÚ	xla_modelÚ_maybe_convert_to_cpuÚlogÚdebugÚtorchÚsave)
r   r   r   r   Úfsr!   r"   r#   ÚxmÚcpu_datas
             r   Úsave_checkpointzXLACheckpointIO.save_checkpoint+   sÇ   € ð Ð&Üð*Ø*.¯.©.×*AÑ*AÐ)Bð CFðFóð ô
 ˜DÓ!ˆØ
�‰”B—G‘G—O‘O DÓ)°DˆÔ9Ü˜KÔ(çCÑCä,¨Z¸*ÀjÐ9QÐS\×SiÑSiÓjˆJß-Ð-à×+Ñ+¨JÀÐ+ÓEˆÜ�	‰	Ð'¨ vÐ.Ô/Ü�
‰
�8˜TÕ"r   r   )r&   Ú
__module__Ú__qualname__Ú__doc__r   r   r   Údictr   r   r   r6   Ú__classcell__)r   s   @r   r   r      sb   ø„ ñð*˜cð *¨Sð *°Tõ *ð
 ñ#¨$¨s°C¨x©.ð #Àð #ÐX`ÐadÑXeð #Ðquò #ó ô#r   r   )Úloggingr(   Útypingr   r   r1   Ú#lightning_utilities.core.apply_funcr   Ú lightning_utilities.core.importsr   Útyping_extensionsr   Ú!lightning_fabric.accelerators.xlar   Ú$lightning_fabric.plugins.io.torch_ior	   Ú#lightning_fabric.utilities.cloud_ior
   Ú lightning_fabric.utilities.typesr   Ú	getLoggerr&   r/   r   © r   r   Ú<module>rG      sG   ðó Û 	ß  ã Ý CÝ =Ý &å <Ý BÝ >Ý 2à€g×Ñ˜Ó!€ô+#Ð'õ +#r   