o
    iG                     @  sR   d dl mZ d dlZd dlZd dlmZ d dlmZmZ dd	d
Z	ddddZ
dS )    )annotationsN)Path)DictAnypath
str | PathreturnDict[str, Any]c                 C  s^   t | } | jddd}t|}W d   n1 sw   Y  t|ts-td|  d|S )zP
    Load a YAML configuration file into a dictionary suitable for argbind.
    rzutf-8)encodingNzConfiguration file z" must contain a top-level mapping.)r   openyaml	safe_load
isinstancedict
ValueError)r   fdata r   J/home/ubuntu/.local/lib/python3.10/site-packages/voxcpm/training/config.pyload_yaml_config	   s   
r   config_pathstr | Path | Nonec                 C  sb   t  }| du r
|S t| }t | t j|g d}W d   n1 s%w   Y  || |S )z
    Helper to unify CLI arguments and YAML configuration.

    Usage mirrors minicpm-audio:
        args = parse_args_with_config("conf/voxcpm/finetune.yml")
        with argbind.scope(args):
            ...
    N)	yaml_argsargv)argbind
parse_argsr   scopeupdate)r   cli_argsr   r   r   r   parse_args_with_config   s   	
r    )r   r   r   r	   )N)r   r   )
__future__r   r   r   pathlibr   typingr   r   r   r    r   r   r   r   <module>   s    
