o
    wi:                     @   sp   d dl Z d dlmZ d dlmZmZmZ d dlmZ dee	ef fddZ
dee	ef d	ee	ef fd
dZdS )    N)Path)AnyDictUnion)maybe_cast_to_type	quant_cfgc                 C   s   |   D ]C\}}|dkrdd |  D }|| |< n|dv r*t|tr*t|| |< qt|tr4t| qt|trG|D ]}t|trFt| q;qdS )zStandardize the quantization configuration loaded from a JSON file to
    ensure compatibility with modelopt. Modifiy the input dictionary in place.

    Args:
        quant_cfg (Dict[str, Any]): The quantization config dictionary to standardize.
    block_sizesc                 S   s   i | ]
\}}t |t|qS  )r   int).0kvr	   r	   m/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/nemo/collections/llm/modelopt/quantization/utils.py
<dictcomp>   s    z+standardize_json_config.<locals>.<dictcomp>>   num_bits
scale_bitsN)items
isinstancelisttupledictstandardize_json_config)r   keyvaluexr	   r	   r   r      s   




r   cfg_pathreturnc                 C   s@   t | d}t|}W d   n1 sw   Y  t| |S )zLoad quantization configuration from a JSON file and adjust for
    modelopt standards if necessary.

    Args:
        cfg_path (str): Path to the quantization config JSON file.

    Returns:
        dict: The loaded quantization configuration.
    rN)openjsonloadr   )r   fr   r	   r	   r   load_quant_cfg,   s
   
r"   )r   pathlibr   typingr   r   r   nemo.utils.cast_utilsr   strr   r"   r	   r	   r	   r   <module>   s   &