§
    ìXÊj/   ã                   óf   — d 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„ Z G d	„ d
¦  «        ZdS )zFContains a logger to push training logs to the Hub, using Tensorboard.é    )ÚPathé   )ÚCommitScheduler)ÚEntryNotFoundError)Ú	ModelCard)Úexperimentalc                  ó‚   — 	 ddl m}  n6# t          $ r) 	 ddlm}  n# t          $ r t          d¦  «        d‚w xY wY nw xY w| S )zQLoad a SummaryWriter implementation only when an HFSummaryWriter is instantiated.r   ©ÚSummaryWriterzvYou must have `tensorboard` installed to use `HFSummaryWriter`. Please run `pip install --upgrade tensorboardX` first.N)ÚtensorboardXr   ÚImportErrorÚtorch.utils.tensorboardr
   s    úTC:\Projects\Historical\venv\Lib\site-packages\huggingface_hub/_tensorboard_logger.pyÚ_load_summary_writerr      s˜   € ð	Ø.Ð.Ð.Ð.Ð.Ð.Ð.øÝð ð ð ð	Ø=Ð=Ð=Ð=Ð=Ð=Ð=øÝð 	ð 	ð 	Ýð(ñô ð ðð	øøøð >Ð=ðøøøð Ðs   ‚	 ‰
<”š<›6¶<»<c                   óô   ‡ — e Zd ZdZedˆ fd„¦   «         Zddddddddddd	œ
d
ededz  deez  de	dedz  dedz  de	dz  dedz  de
e         ez  dz  de
e         ez  dz  dedz  fd„Zdefd„Zdd„Zd„ Zˆ xZS )ÚHFSummaryWritera�  
    Wrapper around the tensorboard's `SummaryWriter` to push training logs to the Hub.

    Data is logged locally and then pushed to the Hub asynchronously. Pushing data to the Hub is done in a separate
    thread to avoid blocking the training script. In particular, if the upload fails for any reason (e.g. a connection
    issue), the main script will not be interrupted. Data is automatically pushed to the Hub every `commit_every`
    minutes (default to every 5 minutes).

    > [!WARNING]
    > `HFSummaryWriter` is experimental. Its API is subject to change in the future without prior notice.

    Args:
        repo_id (`str`):
            The id of the repo to which the logs will be pushed.
        logdir (`str`, *optional*):
            The directory where the logs will be written. If not specified, a local directory will be created by the
            underlying `SummaryWriter` object.
        commit_every (`int` or `float`, *optional*):
            The frequency (in minutes) at which the logs will be pushed to the Hub. Defaults to 5 minutes.
        squash_history (`bool`, *optional*):
            Whether to squash the history of the repo after each commit. Defaults to `False`. Squashing commits is
            useful to avoid degraded performances on the repo when it grows too large.
        repo_type (`str`, *optional*):
            The type of the repo to which the logs will be pushed. Defaults to "model".
        repo_revision (`str`, *optional*):
            The revision of the repo to which the logs will be pushed. Defaults to "main".
        repo_private (`bool`, *optional*):
            Whether to make the repo private. If `None` (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists.
        path_in_repo (`str`, *optional*):
            The path to the folder in the repo where the logs will be pushed. Defaults to "tensorboard/".
        repo_allow_patterns (`list[str]` or `str`, *optional*):
            A list of patterns to include in the upload. Defaults to `"*.tfevents.*"`. Check out the
            [upload guide](https://huggingface.co/docs/huggingface_hub/guides/upload#upload-a-folder) for more details.
        repo_ignore_patterns (`list[str]` or `str`, *optional*):
            A list of patterns to exclude in the upload. Check out the
            [upload guide](https://huggingface.co/docs/huggingface_hub/guides/upload#upload-a-folder) for more details.
        token (`str`, *optional*):
            Authentication token. Will default to the stored token. See https://huggingface.co/settings/token for more
            details
        kwargs:
            Additional keyword arguments passed to `SummaryWriter`.

    Examples:
    ```diff
    # Taken from https://pytorch.org/docs/stable/tensorboard.html
    - from torch.utils.tensorboard import SummaryWriter
    + from huggingface_hub import HFSummaryWriter

    import numpy as np

    - writer = SummaryWriter()
    + writer = HFSummaryWriter(repo_id="username/my-trained-model")

    for n_iter in range(100):
        writer.add_scalar('Loss/train', np.random.random(), n_iter)
        writer.add_scalar('Loss/test', np.random.random(), n_iter)
        writer.add_scalar('Accuracy/train', np.random.random(), n_iter)
        writer.add_scalar('Accuracy/test', np.random.random(), n_iter)
    ```

    ```py
    >>> from huggingface_hub import HFSummaryWriter

    # Logs are automatically pushed every 15 minutes (5 by default) + when exiting the context manager
    >>> with HFSummaryWriter(repo_id="test_hf_logger", commit_every=15) as logger:
    ...     logger.add_scalar("a", 1)
    ...     logger.add_scalar("b", 2)
    ```
    Úreturnc                 óF   •— t          ¦   «                              | ¦  «        S ©N)ÚsuperÚ__new__)ÚclsÚargsÚkwargsÚ	__class__s      €r   r   zHFSummaryWriter.__new__n   s   ø€ å‰wŒw�Š˜sÑ#Ô#Ð#ó    Né   FÚtensorboardz*.tfevents.*)
ÚlogdirÚcommit_everyÚsquash_historyÚ	repo_typeÚrepo_revisionÚrepo_privateÚpath_in_repoÚrepo_allow_patternsÚrepo_ignore_patternsÚtokenÚrepo_idr   r    r!   r"   r#   r$   r%   r&   r'   r(   c       
         ó†  —  t          ¦   «         dd|i|¤Ž| _        | j        j        | _        t          | j        t          ¦  «        s-t          d| j        › dt          | j        ¦  «        › d�¦  «        ‚|�|dk    rt          | j        ¦  «        j        }n2| 	                    d¦  «        dz   t          | j        ¦  «        j        z   }t          | j        |||||||	|
||¬¦  «        | _        | j        j        | _        | j        j        | _        | j        j        | _        	 t!          j        | j        | j        ¬¦  «        }n# t$          $ r t!          d¦  «        }Y nw xY w|j                             d	g ¦  «        }d
|vrB|                     d
¦  «         ||j        d	<   |                     | j        | j        ¬¦  «         d S d S )Nr   z%`self.logdir` must be a string. Got 'z
' of type ú.Ú ú/)Úfolder_pathr%   r)   r"   ÚrevisionÚprivater(   Úallow_patternsÚignore_patternsÚeveryr!   )Úrepo_id_or_pathr"   Útagszhf-summary-writer)r)   r"   © )r   Ú_summary_writerr   Ú
isinstanceÚstrÚ
ValueErrorÚtyper   ÚnameÚstripr   Ú	schedulerr)   r"   r/   r#   r   Úloadr   ÚdataÚgetÚappendÚpush_to_hub)Úselfr)   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r   Úcardr5   s                  r   Ú__init__zHFSummaryWriter.__init__r   sâ  € ð"  6Õ3Ñ5Ô5ÐNÐN¸VÐNÀvÐNÐNˆÔØÔ*Ô1ˆŒõ ˜$œ+¥sÑ+Ô+ð 	rÝÐpÀTÄ[ÐpÐpÕ\`ÐaeÔalÑ\mÔ\mÐpÐpÐpÑqÔqÐqð Ð <°2Ò#5Ð#5Ý ¤Ñ,Ô,Ô1ˆLˆLà'×-Ò-¨cÑ2Ô2°SÑ8½4ÀÄÑ;LÔ;LÔ;QÑQˆLõ )ØœØ%ØØØ"Ø ØØ.Ø0ØØ)ð
ñ 
ô 
ˆŒð ”~Ô-ˆŒØœÔ1ˆŒØ!œ^Ô4ˆÔð	!Ý”>°$´,È$Ì.ÐYÑYÔYˆDˆDøÝ!ð 	!ð 	!ð 	!Ý˜R‘=”=ˆDˆDˆDð	!øøøàŒy�}Š}˜V RÑ(Ô(ˆØ dÐ*Ð*Ø�KŠKÐ+Ñ,Ô,Ð,Ø $ˆDŒI�fÑØ×Ò T¤\¸T¼^ÐÑLÔLÐLÐLÐLð +Ð*s   Ä  E ÅEÅEr<   c                 ó,   — t          | j        |¦  «        S )z;Forward the SummaryWriter API to the lazily-created writer.)Úgetattrr7   )rD   r<   s     r   Ú__getattr__zHFSummaryWriter.__getattr__¯   s   € å�tÔ+¨TÑ2Ô2Ð2r   c                 ó8   — | j                              ¦   «          | S r   )r7   Ú	__enter__)rD   s    r   rK   zHFSummaryWriter.__enter__³   s   € ØÔ×&Ò&Ñ(Ô(Ð(Øˆr   c                 ó˜   — | j                              |||¦  «         | j                             ¦   «         }|                     ¦   «          dS )zLPush to hub in a non-blocking way when exiting the logger's context manager.N)r7   Ú__exit__r>   ÚtriggerÚresult)rD   Úexc_typeÚexc_valÚexc_tbÚfutures        r   rM   zHFSummaryWriter.__exit__·   sA   € àÔ×%Ò% h°¸Ñ@Ô@Ð@Ø”×'Ò'Ñ)Ô)ˆØ�Š‰Œˆˆˆr   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r9   ÚintÚfloatÚboolÚlistrF   rI   rK   rM   Ú__classcell__)r   s   @r   r   r   '   s†  ø€ € € € € ðDð DðL ð$ð $ð $ð $ð $ñ „\ð$ð "Ø$%Ø$Ø $Ø$(Ø$(Ø#0Ø6DØ7;Ø ð;Mð ;Mð ;Màð;Mð �d‘
ð	;Mð
 ˜E‘kð;Mð ð;Mð ˜‘:ð;Mð ˜T‘zð;Mð ˜T‘kð;Mð ˜D‘jð;Mð " #œY¨™_¨tÑ3ð;Mð # 3œi¨#™o°Ñ4ð;Mð �T‰zð;Mð ;Mð ;Mð ;Mðz3 ð 3ð 3ð 3ð 3ðð ð ð ðð ð ð ð ð ð r   r   N)rW   Úpathlibr   Ú_commit_schedulerr   Úerrorsr   Úrepocardr   Úutilsr   r   r   r6   r   r   ú<module>rb      s³   ðð MÐ Là Ð Ð Ð Ð Ð à .Ð .Ð .Ð .Ð .Ð .Ø &Ð &Ð &Ð &Ð &Ð &Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ðð ð ðTð Tð Tð Tð Tñ Tô Tð Tð Tð Tr   