o
    vi
                     @   s<   d Z ddlmZ ddlmZ d
dededB defdd	ZdS )zS
Checkpoint utilities for Cosmos Policy, including HuggingFace checkpoint loading.
    )hf_hub_download)logNcheckpoint_path	cache_dirreturnc           	      C   s   |  drI| tdd }|dd}t|dkr!td|  d|\}}}| d| }td| d|  t|||d	}td
|  |S | S )a  
    Resolve checkpoint path, downloading from HuggingFace if needed.

    Supports:
    - Local paths: /path/to/checkpoint.pth
    - S3 paths: s3://bucket/path/to/checkpoint.pth
    - HuggingFace paths: hf://org/repo-name/path/to/file.pth

    Args:
        checkpoint_path: Path to checkpoint file
        cache_dir: Optional cache directory for HuggingFace downloads

    Returns:
        Resolved local path to checkpoint

    Examples:
        >>> # HuggingFace download
        >>> path = resolve_checkpoint_path("hf://nvidia/Cosmos-Predict2-2B-Video2World/tokenizer/tokenizer.pth")

        >>> # S3 or local path (passed through unchanged)
        >>> path = resolve_checkpoint_path("s3://bucket/checkpoint.pth")
        >>> path = resolve_checkpoint_path("/local/path/checkpoint.pth")
    zhf://N/      z!Invalid HuggingFace path format: z2. Expected format: hf://org/repo-name/path/to/filez)Downloading checkpoint from HuggingFace: )repo_idfilenamer   zDownloaded checkpoint to: )
startswithlensplit
ValueErrorr   infor   success)	r   r   hf_pathpartsorg	repo_namer   r
   
local_path r   J/data/cameron/vidgen/cosmos-policy/cosmos_policy/utils/checkpoint_utils.pyresolve_checkpoint_path   s$   


r   )N)__doc__huggingface_hubr   #cosmos_policy._src.imaginaire.utilsr   strr   r   r   r   r   <module>   s    