
    #i4                        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l	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZmZ  ej4                  e      Ze G d de             Zy)    )annotationsN)Callable)	dataclassfield)Union)parse)TrainingArguments)__version__)ParallelMode)BatchSamplersDefaultBatchSamplerMultiDatasetBatchSamplersMultiDatasetDefaultBatchSamplerc                  ,    e Zd ZU dZg dZ edddi      Zded<    eej                  dd	i      Z
d
ed<    eej                  ddi      Zded<    eeddi      Zded<    eeddi      Zded<    ed ddi      Zded<    fdZ fdZ xZS )BaseTrainingArgumentsa  
    BaseTrainingArguments extends :class:`~transformers.TrainingArguments` with additional arguments
    specific to Sentence Transformers. See :class:`~transformers.TrainingArguments` for the complete list of
    available arguments.

    Args:
        output_dir (`str`):
            The output directory where the model checkpoints will be written.
        prompts (`Union[Dict[str, Dict[str, str]], Dict[str, str], str]`, *optional*):
            The prompts to use for each column in the training, evaluation and test datasets. Four formats are accepted:

            1. `str`: A single prompt to use for all columns in the datasets, regardless of whether the training/evaluation/test
               datasets are :class:`datasets.Dataset` or a :class:`datasets.DatasetDict`.
            2. `Dict[str, str]`: A dictionary mapping column names to prompts, regardless of whether the training/evaluation/test
               datasets are :class:`datasets.Dataset` or a :class:`datasets.DatasetDict`.
            3. `Dict[str, str]`: A dictionary mapping dataset names to prompts. This should only be used if your training/evaluation/test
               datasets are a :class:`datasets.DatasetDict` or a dictionary of :class:`datasets.Dataset`.
            4. `Dict[str, Dict[str, str]]`: A dictionary mapping dataset names to dictionaries mapping column names to
               prompts. This should only be used if your training/evaluation/test datasets are a
               :class:`datasets.DatasetDict` or a dictionary of :class:`datasets.Dataset`.

        batch_sampler (Union[:class:`~sentence_transformers.sentence_transformer.training_args.BatchSamplers`, `str`, :class:`~sentence_transformers.base.sampler.DefaultBatchSampler`, Callable[[...], :class:`~sentence_transformers.base.sampler.DefaultBatchSampler`]], *optional*):
            The batch sampler to use. See :class:`~sentence_transformers.sentence_transformer.training_args.BatchSamplers` for valid options.
            Defaults to ``BatchSamplers.BATCH_SAMPLER``.
        multi_dataset_batch_sampler (Union[:class:`~sentence_transformers.sentence_transformer.training_args.MultiDatasetBatchSamplers`, `str`, :class:`~sentence_transformers.base.sampler.MultiDatasetDefaultBatchSampler`, Callable[[...], :class:`~sentence_transformers.base.sampler.MultiDatasetDefaultBatchSampler`]], *optional*):
            The multi-dataset batch sampler to use. See :class:`~sentence_transformers.sentence_transformer.training_args.MultiDatasetBatchSamplers`
            for valid options. Defaults to ``MultiDatasetBatchSamplers.PROPORTIONAL``.
        router_mapping (`Dict[str, str] | Dict[str, Dict[str, str]]`, *optional*):
            A mapping of dataset column names to Router routes, like "query" or "document". This is used to specify
            which Router submodule to use for each dataset. Two formats are accepted:

            1. `Dict[str, str]`: A mapping of column names to routes.
            2. `Dict[str, Dict[str, str]]`: A mapping of dataset names to a mapping of column names to routes for
               multi-dataset training/evaluation.
        learning_rate_mapping (`Dict[str, float] | None`, *optional*):
            A mapping of parameter name regular expressions to learning rates. This allows you to set different
            learning rates for different parts of the model, e.g., `{'SparseStaticEmbedding\.*': 1e-3}` for the
            SparseStaticEmbedding module. This is useful when you want to fine-tune specific parts of the model
            with different learning rates.
    )accelerator_configfsdp_config	deepspeedgradient_checkpointing_kwargslr_scheduler_kwargslearning_rate_mappingpromptsrouter_mappingNhelpzThe prompts to use for each column in the datasets. Either 1) a single string prompt, 2) a mapping of column names to prompts, 3) a mapping of dataset names to prompts, or 4) a mapping of dataset names to a mapping of column names to prompts.)defaultmetadataz;Union[str, None, dict[str, str], dict[str, dict[str, str]]]r   zThe batch sampler to use.zRUnion[BatchSamplers, str, DefaultBatchSampler, Callable[..., DefaultBatchSampler]]batch_samplerz'The multi-dataset batch sampler to use.zvUnion[MultiDatasetBatchSamplers, str, MultiDatasetDefaultBatchSampler, Callable[..., MultiDatasetDefaultBatchSampler]]multi_dataset_batch_samplerzA mapping of dataset column names to Router routes, like "query" or "document". Either 1) a mapping of column names to routes or 2) a mapping of dataset names to a mapping of column names to routes for multi-dataset training/evaluation. )default_factoryr   r   zA mapping of parameter name regular expressions to learning rates. This allows you to set different learning rates for different parts of the model, e.g., {'SparseStaticEmbedding\.*': 1e-3} for the SparseStaticEmbedding module.z"Union[str, None, dict[str, float]]r   c                 @    t        t              t        d      k\  rd S dS )N5.0.0        )parse_versiontransformers_version     y/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/sentence_transformers/base/training_args.py<lambda>zBaseTrainingArguments.<lambda>u   s    6J(K}]dOe(e kn r&   zThis argument is deprecated and will be removed in the future. If you're on Transformers v5+, then you should use `warmup_steps` instead as it also works with float values.zfloat | Nonewarmup_ratioc                   t        t              t        d      k\  rI| j                  | j                  dk(  r| j                  | _        d | _        t        j                  d       nYt        | j                  t              r?d| j                  cxk  rdk  r*n n'| j                  dk(  r| j                  | _        d| _        t        | %          t        | j                  t              rt        | j                        n| j                  | _
        t        | j                  t              rt        | j                        n| j                  | _        t        | j                  t              r%	 t!        j"                  | j                        | _        | j&                  | j&                  ni | _        t        | j&                  t              r%	 t!        j"                  | j&                        | _        | j*                  | j*                  ni | _        t        | j*                  t              r%	 t!        j"                  | j*                        | _        d| _        d	| _        | j0                  t2        j4                  k(  r&| j6                  d
k7  rt        j                  d       y y | j0                  t2        j8                  k(  r9| j:                  s,| j6                  d
k7  rt        j                  d       d| _        y y y # t         j$                  $ r Y zw xY w# t         j$                  $ r t)        d      w xY w# t         j$                  $ r t)        d      w xY w)Nr!   r   a  The `warmup_ratio` argument is deprecated in Transformers v5+, and will also be removed from Sentence Transformers once support for Transformers v4 is dropped. Since you're using Transformers v5+, please use `warmup_steps` (as a float) to specify the warmup ratio instead.r"   g      ?zThe `learning_rate_mapping` argument must be a dictionary mapping parameter name regular expressions to learning rates. A stringified dictionary also works.zThe `router_mapping` argument must be a dictionary mapping dataset column names to Router routes, like 'query' or 'document'. A stringified dictionary also works.TFunusedzCurrently using DataParallel (DP) for multi-gpu training, while DistributedDataParallel (DDP) is recommended for faster training. See https://sbert.net/docs/sentence_transformer/training/distributed.html for more information.zWhen using DistributedDataParallel (DDP), it is recommended to set `dataloader_drop_last=True` to avoid hanging issues with an uneven last batch. Setting `dataloader_drop_last=True`.)r#   r$   r)   warmup_stepsloggerwarning
isinstancefloatsuper__post_init__r   strr   r   r   r   jsonloadsJSONDecodeErrorr   
ValueErrorr   prediction_loss_onlyddp_broadcast_buffersparallel_moder   NOT_DISTRIBUTED
output_dirDISTRIBUTEDdataloader_drop_last)self	__class__s    r'   r2   z#BaseTrainingArguments.__post_init__|   s    -.-2HH   ,1B1Ba1G$($5$5!$(!t $++U3d>O>O8URU8UZ^ZkZkorZr$($5$5!$%! 2<D<N<NPS1TM$,,-Z^ZlZl 	
 $::C@ &d&F&FG11 	( dllC(#zz$,,7 DHC]C]CiT%?%?oq"d00#6-1ZZ8R8R-S* 6:5H5H5Td11Z\d))3/&*jj1D1D&E# %)! &+"!=!== (*v + <#;#;;DD]D] (*; )-D% E^;U ''   ''  N  ''  W s*   ($K0 $L
 $$L, 0LL
L),Mc                h    t         |          }t        |d         r|d= t        |d         r|d= |S )Nr   r   )r1   to_dictcallable)r?   training_args_dictr@   s     r'   rB   zBaseTrainingArguments.to_dict   sD    "W_.&78"?3&'DEF"#@A!!r&   )__name__
__module____qualname____doc___VALID_DICT_FIELDSr   r   __annotations__r   BATCH_SAMPLERr   r   PROPORTIONALr   dictr   r   r)   r2   rB   __classcell__)r@   s   @r'   r   r      s   'Z	 LQ d
LGH  in++v?Z6[iMe 
 	)66&JsAt	   " 
 SX P
SNO  AF X
A=  "'n ]
"L, \-|" "r&   r   )
__future__r   r4   loggingcollections.abcr   dataclassesr   r   typingr   packaging.versionr   r#   transformersr	   TransformersTrainingArgumentsr
   r$   transformers.training_argsr   "sentence_transformers.base.samplerr   r   r   r   	getLoggerrE   r-   r   r%   r&   r'   <module>rZ      s`    "   $ (  4 K < 3  
		8	$ G"9 G" G"r&   