+
    –°³j@&  ã                   óî   € ^ RI t ^ RIt^ RIHt ^ RIHt ^ RIHtHtH	t	 ^ RI
HtHtHtHt ^ RIHt . ROt]! R
R7       ! R R4      4       t ! R R] P&                  4      t ! R R	] P&                  4      tR# )é    N)Ú	dataclass)ÚAny)ÚMetadataÚMetadataIndexÚStorageMeta)ÚLoadPlanÚLoadPlannerÚSavePlanÚSavePlanner)ÚFutureÚWriteResultÚStorageWriterÚStorageReaderT)Úfrozenc                   ó,   a € ] tR t^t o V 3R ltRtV tR# )r   c                ó>   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   S[;R&   # )é   ÚindexÚsize_in_bytesÚstorage_data)r   Úintr   )ÚformatÚ__classdict__s   "€Úe/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/distributed/checkpoint/storage.pyÚ__annotate__ÚWriteResult.__annotate__   s*   ø‡ ‚ áÑñ ñ Ññ	 ñ
 Ñò ó    © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r   s   @r   r   r      s   ø‡ ‡ „ r   c                   ó”  a € ] tR t^t o Rt]P                  RV 3R lR ll4       t]P                  V 3R lR l4       t]P                  V 3R lR l4       t	]P                  V 3R	 lR
 l4       t
]P                  V 3R lR l4       t]P                  V 3R lR l4       t]]P                  V 3R lR l4       4       tV 3R lR ltRtV tR# )r   a  
Interface used by ``save_state_dict`` to write to storage.

One StorageWriter instance acts as both the coordinator and the follower
in a distributed checkpoint. As part of initialization, each instance
is told its role.

A subclass should expect the following sequence of calls.

0) (all ranks) set checkpoint_id if users pass a valid checkpoint_id.
1) (all ranks) set_up_storage_writer()
2) (all ranks) prepare_local_plan()
3) (coordinator) prepare_global_plan()
4) (all ranks) write_data()
5) (coordinator) finish()
Nc                óV   <€ V ^8„  d   QhRS[ S[P                  ,          R,          RR/# ©r   Úcheckpoint_idNÚreturn©ÚstrÚosÚPathLike)r   r   s   "€r   r   ÚStorageWriter.__annotate__.   ó)   ø€ ÷ ñ ¡3©¯©Õ#4°tÕ#;ð Àtñ r   c                ó   € R# )aI  
Calls to indicates a brand new checkpoint write is going to happen.
A checkpoint_id may be present if users set the checkpoint_id for
this checkpoint write. The meaning of the checkpoint_id is
storage-dependent. It can be a path to a folder/file or a key for
a key-value storage.

Args:
    checkpoint_id (Union[str, os.PathLike, None]):
        The ID of this checkpoint instance. The meaning of the checkpoint_id
        depends on the storage. It can be a path to a folder or to a file.
        It can also be a key if the storage is a key-value store.
        (Default: ``None``)
Nr   ©Úselfr*   s   &&r   ÚresetÚStorageWriter.reset-   ó   € ñ  	r   c                ó0   <€ V ^8„  d   QhRS[ RS[RS[RR/# )r   Úis_coordinatorÚargsÚkwargsr+   N)Úboolr   )r   r   s   "€r   r   r0   @   s-   ø€ ÷ 	ñ 	Ù"ð	Ù+.ð	Ù:=ð	à	ñ	r   c                ó   € R# )z‰
Initialize this instance.

Args:
    is_coordinator (bool): Whether this instance is responsible for coordinating
      the checkpoint.
Nr   )r4   r9   r:   r;   s   &&*,r   Úset_up_storage_writerÚ#StorageWriter.set_up_storage_writer?   ó   ‚ r   c                ó&   <€ V ^8„  d   QhRS[ RS[ /# ©r   Úplanr+   )r
   )r   r   s   "€r   r   r0   L   ó   ø€ ÷ ñ ¡xð ±Hñ r   c                ó   € R# )aI  
Perform storage-specific local planning.

While this method can produce a completely different plan, the recommended
way is to store storage specific data in SavePlan::storage_data.

Args:
    plan (SavePlan): The local plan from the ``SavePlanner`` in use.

Returns:
    A transformed ``SavePlan`` after storage local planning
Nr   ©r4   rC   s   &&r   Úprepare_local_planÚ StorageWriter.prepare_local_planK   r@   r   c                óF   <€ V ^8„  d   QhRS[ S[,          RS[ S[,          /# ©r   Úplansr+   )Úlistr
   )r   r   s   "€r   r   r0   [   ó#   ø€ ÷ ñ ©©h­ð ¹DÁ½Nñ r   c                ó   € R# )a„  
Perform centralized planning of storage.

This method is only called on the coordinator instance.

While this method can produce a completely different plan, the preferred
way is to store storage specific data in SavePlan::storage_data.

Args:
    plans: A list of ``SavePlan`` instances, one for each rank.

Returns:
    A list of transformed ``SavePlan`` after storage global planning
Nr   ©r4   rK   s   &&r   Úprepare_global_planÚ!StorageWriter.prepare_global_planZ   r@   r   c                óL   <€ V ^8„  d   QhRS[ RS[RS[S[S[,          ,          /# )r   rC   Úplannerr+   )r
   r   r   rL   r   )r   r   s   "€r   r   r0   l   s/   ø€ ÷ ñ ÙðÙ'2ðá	‘‘[Õ!Õ	"ñr   c                ó   € R# )a²  
Write all items from ``plan`` using ``planner`` to resolve the data.

A subclass should call ``SavePlanner::resolve_data`` on each item
from the plan to get access to the underlying object to write.

Subclasses should lazily call `resolve_data` as it can allocate memory.
In case of tensors, make following assumptions:

- They might be on any device, including not matching the one on ``WriteItem::tensor_data``
- They might be views or not contiguous. Only the projection needs to be saved.

Args:
    plan (SavePlan): The save plan to execute.
    planner (SavePlanner): Planner object to be used to resolve items to data.

Returns:
    A future that completes to a list of WriteResult
Nr   ©r4   rC   rS   s   &&&r   Ú
write_dataÚStorageWriter.write_datak   r@   r   c                óJ   <€ V ^8„  d   QhRS[ RS[S[S[,          ,          RR/# )r   ÚmetadataÚresultsr+   N)r   rL   r   )r   r   s   "€r   r   r0   „   s,   ø€ ÷ ñ ™xð ±$±t¹KÕ7HÕ2Ið Èdñ r   c                ó   € R# )am  
Write the metadata and marks the current checkpoint as successful.

The actual format/schema used for serializing `metadata` is an
implementation detail. The only requirement is that it's recoverable
in to the same object graph.

Args:
    metadata (Metadata): metadata for the new checkpoint
    results: A list of WriteResults from all ranks.

Returns:
    None
Nr   )r4   rY   rZ   s   &&&r   ÚfinishÚStorageWriter.finishƒ   r@   r   c                óJ   <€ V ^8„  d   QhRS[ S[P                  ,          RS[/# ©r   r*   r+   ©r-   r.   r/   r<   )r   r   s   "€r   r   r0   –   ó$   ø€ ÷ ñ ±3¹¿¹Õ3Dð Éñ r   c                ó   € R# ©zu
Check if the given checkpoint_id is supported by the storage. This allows
us to enable automatic storage selection.
Nr   ©Úclsr*   s   &&r   Úvalidate_checkpoint_idÚ$StorageWriter.validate_checkpoint_id”   ó   € ñ 	r   c                ó.   <€ V ^8„  d   QhRS[ R,          /# )r   r+   N)r   )r   r   s   "€r   r   r0   �   s   ø€ ÷ ñ ™k¨DÕ0ñ r   c                ó   € R# )a  
Return the storage-specific metadata. This is used to store additional information
in a checkpoint that can be useful for providing request-level observability. StorageMeta
is passed to the ``SavePlanner`` during save calls. Returns None by default.

TODO: provide an example
Nr   )r4   s   &r   Ústorage_metaÚStorageWriter.storage_meta�   s   € ñ r   r   ©N)r   r    r!   r"   Ú__doc__ÚabcÚabstractmethodr5   r>   rG   rP   rV   r\   Úclassmethodrf   rk   r$   r%   r&   s   @r   r   r      s×   ø‡ € ñð" 	×Ñ÷ñ ó ðð" 	×Ñ÷	ó ð	ð 	×Ñ÷ó ðð 	×Ñ÷ó ðð  	×Ñ÷ó ðð. 	×Ñ÷ó ðð  Ø×Ñ÷ó ó ð÷ö r   c                   ó‚  a € ] tR t^¨t o Rt]P                  RV 3R lR ll4       t]P                  V 3R lR l4       t]P                  V 3R lR l4       t	]P                  V 3R	 lR
 l4       t
]P                  V 3R lR l4       t]P                  V 3R lR l4       t]]P                  V 3R lR l4       4       tRtV tR# )r   a$  
Interface used by ``load_state_dict`` to read from storage.

One StorageReader instance acts as both the coordinator and the follower
in a distributed checkpoint. As part of initialization, each instance
is told its role.

A subclass should expect the following sequence of calls by ``load_state_dict``:

0) (all ranks) set checkpoint_id if users pass a valid checkpoint_id.
1) (all ranks) read_metadata()
2) (all ranks) set_up_storage_reader()
3) (all ranks) prepare_local_plan()
4) (coordinator) prepare_global_plan()
5) (all ranks) read_data()
Nc                óV   <€ V ^8„  d   QhRS[ S[P                  ,          R,          RR/# r)   r,   )r   r   s   "€r   r   ÚStorageReader.__annotate__»   r1   r   c                ó   € R# )aQ  
Calls to indicates a brand new checkpoint read is going to happen.
A checkpoint_id may be present if users set the checkpoint_id for
this checkpoint read. The meaning of the checkpoint_id is
storage-dependent. It can be a path to a folder/file or a key for
a key-value storage.

Args:
    checkpoint_id (Union[str, os.PathLike, None]):
        The ID of this checkpoint instance. The meaning of the checkpoint_id
        depends on the storage. It can be a path to a folder or to a file.
        It can also be a key if the storage is more like a key-value store.
        (Default: ``None``)
Nr   r3   s   &&r   r5   ÚStorageReader.resetº   r7   r   c                ó,   <€ V ^8„  d   QhRS[ RS[ RS[/# )r   r:   r;   r+   )r   r   )r   r   s   "€r   r   rt   Í   s"   ø€ ÷ ñ ¡3ð ±#ð ¹(ñ r   c                ó   € R# )zo
Read the checkpoint metadata.

Returns:
    The metadata object associated with the checkpoint being loaded.

Nr   )r4   r:   r;   s   &*,r   Úread_metadataÚStorageReader.read_metadataÌ   r@   r   c          
      ó6   <€ V ^8„  d   QhRS[ RS[RS[RS[RR/# )r   rY   r9   r:   r;   r+   N)r   r<   r   )r   r   s   "€r   r   rt   ×   s5   ø€ ÷ 
ñ 
Ù ð
Ù26ð
Ù?Bð
ÙNQð
à	ñ
r   c                ó   € R# )z¾
Initialize this instance.

Args:
    metadata (Metadata): The metadata schema to use.
    is_coordinator (bool): Whether this instance is responsible for coordinating
      the checkpoint.
Nr   )r4   rY   r9   r:   r;   s   &&&*,r   Úset_up_storage_readerÚ#StorageReader.set_up_storage_readerÖ   r@   r   c                ó&   <€ V ^8„  d   QhRS[ RS[ /# rB   )r   )r   r   s   "€r   r   rt   ä   rD   r   c                ó   € R# )aF  
Perform storage-specific local planning.

While this method can produce a completely different plan, the recommended
way is to store storage specific data in LoadPlan::storage_data.

Args:
    plan (LoadPlan): The local plan from the ``LoadPlan`` in use.

Returns:
    A transformed ``LoadPlan`` after storage local planning
Nr   rF   s   &&r   rG   Ú StorageReader.prepare_local_planã   r@   r   c                óF   <€ V ^8„  d   QhRS[ S[,          RS[ S[,          /# rJ   )rL   r   )r   r   s   "€r   r   rt   ó   rM   r   c                ó   € R# )aŒ  
Perform centralized planning of storage loading.

This method is only called on the coordinator instance.

While this method can produce a completely different plan, the preferred
way is to store storage specific data in LoadPlan::storage_data.

Args:
    plans: A list of ``LoadPlan`` instances, one for each rank.

Returns:
    A list of transformed ``LoadPlan`` after storage global planning
Nr   rO   s   &&r   rP   Ú!StorageReader.prepare_global_planò   r@   r   c                ó:   <€ V ^8„  d   QhRS[ RS[RS[R,          /# )r   rC   rS   r+   N)r   r	   r   )r   r   s   "€r   r   rt     s&   ø€ ÷ ñ ™hð ±ð ÁÈÅñ r   c                ó   € R# )aC  
Read all items from ``plan`` using ``planner`` to resolve the data.

A subclass should call ``LoadPlanner::load_bytes`` to deserialize a BytesIO
object into the right place.

A subclass should call ``LoadPlanner::resolve_tensor`` to get access to the
tensors that in should load data into.

It's the StorageLayer responsibility to properly schedule any cross device copies
required.

Args:
    plan (LoadPlan): The local plan to execute on
    planner (LoadPlanner): The planner object to use to resolve items.

Returns:
    A future that completes once all reads are finished.
Nr   rU   s   &&&r   Ú	read_dataÚStorageReader.read_data  r@   r   c                óJ   <€ V ^8„  d   QhRS[ S[P                  ,          RS[/# r_   r`   )r   r   s   "€r   r   rt     ra   r   c                ó   € R# rc   r   rd   s   &&r   rf   Ú$StorageReader.validate_checkpoint_id  rh   r   r   rm   )r   r    r!   r"   rn   ro   rp   r5   ry   r}   rG   rP   r‡   rq   rf   r$   r%   r&   s   @r   r   r   ¨   sÍ   ø‡ € ñð" 	×Ñ÷ñ ó ðð" 	×Ñ÷ó ðð 	×Ñ÷
ó ð
ð 	×Ñ÷ó ðð 	×Ñ÷ó ðð  	×Ñ÷ó ðð* Ø×Ñ÷ó ó ör   )r   r   r   )ro   r.   Údataclassesr   Útypingr   Ú%torch.distributed.checkpoint.metadatar   r   r   Ú$torch.distributed.checkpoint.plannerr   r	   r
   r   Útorch.futuresr   Ú__all__r   ÚABCr   r   r   r   r   Ú<module>r“      sp   ðÛ 
Û 	Ý !Ý ç VÑ V÷ó õ !ò <€ñ �$Ô÷ð ó ðôJ�C—G‘Gô JôZx�C—G‘Gö xr   