o
    }oi                     @   s   d dl mZmZmZmZ d dlmZmZ G dd deZG dd deZ	G dd deZ
G d	d
 d
eZG dd deZG dd deZdS )    )AnyDictOptionalUnion)	BaseModelFieldc                   @   s   e Zd ZU dZedddZeed< edddZeed< ed	d
dZ	eed< eddddZ
ee ed< eddddZee ed< dS )ApiEndpointzG
    Represents evaluation Standard API target.api_endpoint object
    zUrl of the modelz#http://0.0.0.0:8080/v1/completions/descriptiondefaulturlzName of the model in APItriton_modelmodel_idz,The type of the target (chat or completions)completionstypezPath for nemo 2.0 checkpointNTThis parameter is deprecated and not used for evaluations with NVIDIA Evals Factory.r
   r   
deprecatednemo_checkpoint_pathzTHTTP port that was used for the PyTriton server in the deploy method. Default: 8000.i@  nemo_triton_http_port)__name__
__module____qualname____doc__r   r   str__annotations__r   r   r   r   r   int r   r   W/home/ubuntu/.local/lib/python3.10/site-packages/nemo/collections/llm/evaluation/api.pyr      s   
 r   c                   @   s$   e Zd ZU dZeddZeed< dS )EvaluationTargetz:
    Represents evaluation Standard API target object
    z&Api endpoint to be used for evaluationr
   api_endpointN)r   r   r   r   r   r!   r   r   r   r   r   r   r   (   s   
 r   c                       s  e Zd ZU dZedddZeed< edddZeed< edd	dZ	e
eeef  ed
< edd	ddZe
e ed< edd	dZe
e ed< edd	dZe
e ed< edddZe
e ed< edd	dZe
e ed< edddZe
e ed< ededZe
eeef  ed< eddddZe
e ed < ed!dddZe
e ed"< ed#d$ddZe
e ed%< ed&d'ddZeed(<  fd)d*Z  ZS )+ConfigParamszA
    Represents evaluation Standard API config.params object
    z5Limits to the top tokens within a certain probabilityr   r	   top_pzPTemp of 0 indicates greedy decoding, where the token with highest prob is chosentemperaturez=Limit evaluation to `limit` samples. Default: use all samplesNlimit_samplesz6Number of examples in few-shot context. Default: None.zThis parameter is deprecated and not used for evaluations with NVIDIA Evals Factory. In order to specify few-shot please use extra.num_fewshot.r   num_fewshotzmax tokens to generatemax_new_tokenszNumber of REST request retriesmax_retriesz4Number of parallel requests to be sent to the server   parallelismzName of the tasktaskzREST response timeouti,  request_timeoutzJFramework specific parameters to be used for evaluation (e.g. num_fewshot))r
   default_factoryextraz batch size to use for evaluationr   
batch_sizez<Limits to a certain number (K) of the top tokens to considertop_kzBwhether a special bos token should be added when encoding a stringFadd_bosz-Number of iterations for bootstrap statisticsi bootstrap_itersc                    s.   t  jdi | d| jvrd| jd< dS dS )z
        WAR for default tokenizer coming from a gated repo in nvidia-lm-eval==25.03.
        The tokenizer is not used for generation tasks so should be set to None
        	tokenizerNr   )super__init__r.   )selfdata	__class__r   r   r5   c   s   
zConfigParams.__init__)r   r   r   r   r   r#   floatr   r$   r%   r   r   r   r&   r'   r(   r*   r+   r   r,   dictr.   r   r   r/   r0   r1   boolr2   r5   __classcell__r   r   r8   r   r"   0   s^   
 r"   c                   @   sj   e Zd ZU dZedddZeed< edddZe	e
e  ed< ed	d
Zeed< ede dZeed< dS )EvaluationConfigz:
    Represents evaluation Standard API config object
    zDirectory to output the resultsresultsr	   
output_dirz1Supported endpoint types like chat or completionsNsupported_endpoint_typeszName/type of the taskr    r   z$Parameters to be used for evaluationparams)r   r   r   r   r   r@   r   r   rA   r   listr   r"   rB   r   r   r   r   r>   m   s   
 r>   c                   @   s   e Zd ZU dZedeeef ddfddZe	ddZ
eed	< e	d
ddZee ed< e	dddZeed< e	dddZeed< e	dddZee ed< e	dddZedB ed< e	dddZedB ed< dS )AdapterConfigzcAdapter is a mechanism for hooking into the chain of requests/responses btw benchmark and endpoint.
run_configreturnzAdapterConfig | Nonec                 C   sl   |  di  di  ddrdS |  di  di  d}|s!dS |  di  di  dd|d	< t|S )
zFactory. Shall return `None` if the adapter_config is not passed, or validate the schema.

        Args:
            run_config: is the main dict of a configuration run, see `api_dataclasses`.
        targetr!   streamFNadapter_configr    endpoint_type)getrD   model_validate)rE   rI   r   r   r   get_validated_config}   s    
z"AdapterConfig.get_validated_configz*The URL where the model endpoint is servedr    api_urlzWLocal port to use for the adapter server. If `None` (default) will choose any free portNr	   
local_portzMWhether to use the clean-reasoning-tokens adapter. See `end_reasoning_token`.Fuse_reasoningz0Token that singifies the end of reasoning outputz</think>end_reasoning_tokenz=A custom system prompt to replace original one (if not None).custom_system_promptzUMaximum number of responses to log. Set to 0 to disable. If None, all will be logged.   max_logged_responseszTMaximum number of requests to log. Set to 0 to disable. If None, all will be logged.max_logged_requests)r   r   r   r   staticmethodr;   r   r   rN   r   rO   r   rP   r   r   rQ   r<   rR   rS   rU   rV   r   r   r   r   rD   z   s>   
 rD   c                   @   s   e Zd ZdZdS )MisconfigurationErrorzG
    Exception raised when evaluation is not correctly configured.
    N)r   r   r   r   r   r   r   r   rX      s    rX   N)typingr   r   r   r   pydanticr   r   r   r   r"   r>   rD   	ExceptionrX   r   r   r   r   <module>   s   =9