CoolFace
Apppublic

xdecoder/Instruct-X-Decoder

sourceHugging Faceafl-3.0updated 3y agoView on Hugging Face
163likes
arguments.cpython-38.pyc38 linesDownload Raw Back to __pycache__
1U

2E$�c��@sVddlZddlZddlZddlZe�e�Zdd�Zdd�Zdd�Z	dd	�Z3d4d�ZdS)�NcCs�t|t�std��|��D]�\}}|�d�}|}|dd�D].}||krPi||<||}t|t�s<td��q<|�|d�}|||d<|rt�d|�d|�d||d���qdS)	zs5    Load the key, value pairs from config_dict to opt, overriding existing values in opt6    if there is any.7    z"Config must be a Python dictionary�.N�����z0Overriding key needs to be inside a Python dict.z8Overrided z from z to )	�9isinstance�dict�	TypeError�items�split�AssertionError�get�logger�warning)�opt�config_dict�k�vZk_parts�pointerZk_partZ	ori_value�r�(/data/arXiv/demo/Demo/utils/arguments.py�load_config_dict_to_opt	s1011rc	Cs4i}t|dd��}t�|�}W5QRXt||�|S)z�12    Load opt from the config files, settings in later files can override those in previous files.13 14    Args:15        conf_files: config file path16 17    Returns:18        dict: a dictionary of opt settings19    �utf-8��encoding)�open�yaml�	safe_loadr)�	conf_filer
�frrrr�load_opt_from_config_filess202122rcs�tjdd�}|jddd�|jdddd	�|jd23ddd
�|jddtjd�|sX|��n|�|��t�j�}�jr�d��j�}t	�24d|���t�|�}t
||��j�r�t�j�ddks�td���fdd�tt�j�d�D�}�fdd�tt�j�d�D�}dd�|D�}g}|D]F}|�d�}|��}	t|�dk�rP|	|�d�}	�q0|�t|	���qdd�t|||�D�}t
||��j��D]\}}25|26dk	�r�|27||<�q�|�fS)Nz7MainzTrain: Pretrain or fine-tune models for NLP tasks.)�description�commandz*Command: train/evaluate/train-and-evaluate)�helpz--conf_filesTz)Path(s) to the MainzTrain config file(s).)�requiredr z--config_overrides�*aOverride parameters on config with a json style string, e.g. {"<PARAM_NAME_1>": <PARAM_VALUE_1>, "<PARAM_GROUP_2>.<PARAM_SUBGROUP_2>.<PARAM_2>": <PARAM_VALUE_2>}. A key with "." updates the object in the corresponding nested dict. Remember to escape " in command line.)�nargsr z--overridesz9arguments that used to overide the config file in cmdline)r r#� zCommand line config overrides: �rz5overides arguments is not paired, required: key valuecsg|]}�j|d�qS)r%��	overrides��.0�idx�Zcmdline_argsrr�28<listcomp>Dsz$load_opt_command.<locals>.<listcomp>csg|]}�j|dd�qS)r%�r&r(r+rrr,EscSs8g|]0}t|�dd��dkr0|�dd��dd�n|�qS)r$���false�False)�len�replace)r)�valrrrr,FsrcSsi|]\}}}|||��qSrr)r)�x�y�zrrr�29<dictcomp>Psz$load_opt_command.<locals>.<dictcomp>)�argparse�ArgumentParser�add_argument�	REMAINDER�30parse_argsr�31conf_filesZconfig_overrides�joinrr�json�loadsrr'r2r	�ranger�copy�pop�append�type�zip�__dict__r)�args�parserr
Zconfig_overrides_stringr�keys�vals�types�key�eler4rr+r�load_opt_command1s<323334  353637rPc	Cs.t|ddd��}tj||dd�W5QRXdS)N�wrr�)�indent)rr@�dump�r
rrrrr�save_opt_to_json[srVc	Cs*t|ddd��}t�||�W5QRXdS)NrQrr)rrrTrUrrr�save_opt_to_yaml`srW)rr@r9�logging�	getLogger�__name__rrrrPrVrWrrrr�<module>s38*