o
    }oi                     @   s   U d dl mZ d dlmZ dZeed< dZeed< dZdZ	eed	< d
Z
eed< dZdeeef defddZdeeef defddZdeeef defddZdS )    )Path)UnionweightsWEIGHTS_PATHcontextCONTEXT_PATHzadapter_metadata.json
hf_weightsHF_WEIGHTS_PATH
hf_adapterHF_ADAPTER_PATHzadapter_config.jsonbase_dirreturnc                 C   s~   ddl m} ddlm}m} || r| }|| } nt| } | jd |kr*| | } t| |r=| jjd |kr=| j| | _| S )a  Appends a given suffix to a base directory path only if it is not already present.

    This function takes a base directory (either a string or Path) and ensures that
    the suffix is appended to the path. If the base directory is an AdapterPath instance,
    it also appends the suffix to the AdapterPath's base_model_path if the suffix
    is not already part of that path.

    Args:
        base_dir (Union[str, Path]): The base directory or path object.
        suffix (str): The suffix to append to the base directory.

    Returns:
        Path: The updated path object with the suffix appended if it was not already present.
    r   AdapterPathimport_multistorageclientis_multistorageclient_url)	nemo.lightning.resumer   nemo.utils.msc_utilsr   r   r   parts
isinstancebase_model_path)r   suffixr   r   r   msc r   M/home/ubuntu/.local/lib/python3.10/site-packages/nemo/lightning/ckpt_utils.pyidempotent_path_append   s   r   filepathc                 C   s   t | d}t|tS )zjGiven an input checkpoint filepath, clean it using `ckpt_to_dir` and then return the context subdirectory.)r   )ckpt_to_dirr   r   )r   r   r   r   r   ckpt_to_context_subdir=   s   

r    c                 C   s   ddl m} ddlm}m} t| |r| S || r"| }|| } nt| } | jdks3| | jd } | jdks@J d|  d| 	| j
}|S )zPTL considers checkpoints as .ckpt files.
    This method removes the extension and returns a path
    to be used as a directory for distributed checkpoints
    r   r   r   z.ckptz
filepath: z must have .ckpt extension)r   r   r   r   r   r   r   r   with_suffix	with_namestem)r   r   r   r   r   checkpoint_dirr   r   r   r   C   s   

r   N)pathlibr   typingr   r   str__annotations__r   ADAPTER_META_FILENAMEr	   r   HF_ADAPTER_CONFIG_FILENAMEr   r    r   r   r   r   r   <module>   s   