§
    Ý˜ºh÷8  ã                   óÂ   — d dl Z d dlmZmZ d dlmZ ddlmZ ddlm	Z	m
Z
mZmZ  ej        e¦  «        Z e
¦   «         r
d dlZddlmZ e G d„ d	e¦  «        ¦   «         ZdS )
é    N)Ú	dataclassÚfield)ÚOptionalé   )ÚTrainingArguments)Úcached_propertyÚis_tf_availableÚloggingÚrequires_backends)Úkerasc                   óÎ  — e Zd ZU dZdZ edddi¬¦  «        Zee         e	d<    edddi¬¦  «        Z
ee         e	d	<    eddd
i¬¦  «        Zee         e	d<    edddi¬¦  «        Zee	d<    edddi¬¦  «        Zee	d<   ededef         fd„¦   «         Zedd„¦   «         Zedefd„¦   «         Zed„ ¦   «         Zedefd„¦   «         Zedefd„¦   «         Zedefd„¦   «         ZdS )ÚTFTrainingArgumentsaû!  
    TrainingArguments is the subset of the arguments we use in our example scripts **which relate to the training loop
    itself**.

    Using [`HfArgumentParser`] we can turn this class into
    [argparse](https://docs.python.org/3/library/argparse#module-argparse) arguments that can be specified on the
    command line.

    Parameters:
        output_dir (`str`):
            The output directory where the model predictions and checkpoints will be written.
        overwrite_output_dir (`bool`, *optional*, defaults to `False`):
            If `True`, overwrite the content of the output directory. Use this to continue training if `output_dir`
            points to a checkpoint directory.
        do_train (`bool`, *optional*, defaults to `False`):
            Whether to run training or not. This argument is not directly used by [`Trainer`], it's intended to be used
            by your training/evaluation scripts instead. See the [example
            scripts](https://github.com/huggingface/transformers/tree/main/examples) for more details.
        do_eval (`bool`, *optional*):
            Whether to run evaluation on the validation set or not. Will be set to `True` if `eval_strategy` is
            different from `"no"`. This argument is not directly used by [`Trainer`], it's intended to be used by your
            training/evaluation scripts instead. See the [example
            scripts](https://github.com/huggingface/transformers/tree/main/examples) for more details.
        do_predict (`bool`, *optional*, defaults to `False`):
            Whether to run predictions on the test set or not. This argument is not directly used by [`Trainer`], it's
            intended to be used by your training/evaluation scripts instead. See the [example
            scripts](https://github.com/huggingface/transformers/tree/main/examples) for more details.
        eval_strategy (`str` or [`~trainer_utils.IntervalStrategy`], *optional*, defaults to `"no"`):
            The evaluation strategy to adopt during training. Possible values are:

                - `"no"`: No evaluation is done during training.
                - `"steps"`: Evaluation is done (and logged) every `eval_steps`.
                - `"epoch"`: Evaluation is done at the end of each epoch.

        per_device_train_batch_size (`int`, *optional*, defaults to 8):
            The batch size per GPU/TPU core/CPU for training.
        per_device_eval_batch_size (`int`, *optional*, defaults to 8):
            The batch size per GPU/TPU core/CPU for evaluation.
        gradient_accumulation_steps (`int`, *optional*, defaults to 1):
            Number of updates steps to accumulate the gradients for, before performing a backward/update pass.

            <Tip warning={true}>

            When using gradient accumulation, one step is counted as one step with backward pass. Therefore, logging,
            evaluation, save will be conducted every `gradient_accumulation_steps * xxx_step` training examples.

            </Tip>

        learning_rate (`float`, *optional*, defaults to 5e-5):
            The initial learning rate for Adam.
        weight_decay (`float`, *optional*, defaults to 0):
            The weight decay to apply (if not zero).
        adam_beta1 (`float`, *optional*, defaults to 0.9):
            The beta1 hyperparameter for the Adam optimizer.
        adam_beta2 (`float`, *optional*, defaults to 0.999):
            The beta2 hyperparameter for the Adam optimizer.
        adam_epsilon (`float`, *optional*, defaults to 1e-8):
            The epsilon hyperparameter for the Adam optimizer.
        max_grad_norm (`float`, *optional*, defaults to 1.0):
            Maximum gradient norm (for gradient clipping).
        num_train_epochs(`float`, *optional*, defaults to 3.0):
            Total number of training epochs to perform.
        max_steps (`int`, *optional*, defaults to -1):
            If set to a positive number, the total number of training steps to perform. Overrides `num_train_epochs`.
            For a finite dataset, training is reiterated through the dataset (if all data is exhausted) until
            `max_steps` is reached.
        warmup_ratio (`float`, *optional*, defaults to 0.0):
            Ratio of total training steps used for a linear warmup from 0 to `learning_rate`.
        warmup_steps (`int`, *optional*, defaults to 0):
            Number of steps used for a linear warmup from 0 to `learning_rate`. Overrides any effect of `warmup_ratio`.
        logging_dir (`str`, *optional*):
            [TensorBoard](https://www.tensorflow.org/tensorboard) log directory. Will default to
            *runs/**CURRENT_DATETIME_HOSTNAME***.
        logging_strategy (`str` or [`~trainer_utils.IntervalStrategy`], *optional*, defaults to `"steps"`):
            The logging strategy to adopt during training. Possible values are:

                - `"no"`: No logging is done during training.
                - `"epoch"`: Logging is done at the end of each epoch.
                - `"steps"`: Logging is done every `logging_steps`.

        logging_first_step (`bool`, *optional*, defaults to `False`):
            Whether to log and evaluate the first `global_step` or not.
        logging_steps (`int`, *optional*, defaults to 500):
            Number of update steps between two logs if `logging_strategy="steps"`.
        save_strategy (`str` or [`~trainer_utils.SaveStrategy`], *optional*, defaults to `"steps"`):
            The checkpoint save strategy to adopt during training. Possible values are:

                - `"no"`: No save is done during training.
                - `"epoch"`: Save is done at the end of each epoch.
                - `"steps"`: Save is done every `save_steps`.

        save_steps (`int`, *optional*, defaults to 500):
            Number of updates steps before two checkpoint saves if `save_strategy="steps"`.
        save_total_limit (`int`, *optional*):
            If a value is passed, will limit the total amount of checkpoints. Deletes the older checkpoints in
            `output_dir`.
        no_cuda (`bool`, *optional*, defaults to `False`):
            Whether to not use CUDA even when it is available or not.
        seed (`int`, *optional*, defaults to 42):
            Random seed that will be set at the beginning of training.
        fp16 (`bool`, *optional*, defaults to `False`):
            Whether to use 16-bit (mixed) precision training (through NVIDIA Apex) instead of 32-bit training.
        fp16_opt_level (`str`, *optional*, defaults to 'O1'):
            For `fp16` training, Apex AMP optimization level selected in ['O0', 'O1', 'O2', and 'O3']. See details on
            the [Apex documentation](https://nvidia.github.io/apex/amp).
        local_rank (`int`, *optional*, defaults to -1):
            During distributed training, the rank of the process.
        tpu_num_cores (`int`, *optional*):
            When training on TPU, the number of TPU cores (automatically passed by launcher script).
        debug (`bool`, *optional*, defaults to `False`):
            Whether to activate the trace to record computation graphs and profiling information or not.
        dataloader_drop_last (`bool`, *optional*, defaults to `False`):
            Whether to drop the last incomplete batch (if the length of the dataset is not divisible by the batch size)
            or not.
        eval_steps (`int`, *optional*, defaults to 1000):
            Number of update steps before two evaluations.
        past_index (`int`, *optional*, defaults to -1):
            Some models like [TransformerXL](../model_doc/transformerxl) or :doc*XLNet <../model_doc/xlnet>* can make
            use of the past hidden states for their predictions. If this argument is set to a positive int, the
            `Trainer` will use the corresponding output (usually index 2) as the past state and feed it to the model at
            the next training step under the keyword argument `mems`.
        tpu_name (`str`, *optional*):
            The name of the TPU the process is running on.
        tpu_zone (`str`, *optional*):
            The zone of the TPU the process is running on. If not specified, we will attempt to automatically detect
            from metadata.
        gcp_project (`str`, *optional*):
            Google Cloud Project name for the Cloud TPU-enabled project. If not specified, we will attempt to
            automatically detect from metadata.
        run_name (`str`, *optional*):
            A descriptor for the run. Notably used for trackio, wandb, mlflow, comet and swanlab logging.
        xla (`bool`, *optional*):
            Whether to activate the XLA compilation or not.
    ÚtfNÚhelpzName of TPU)ÚdefaultÚmetadataÚtpu_namezZone of TPUÚtpu_zonez!Name of Cloud TPU-enabled projectÚgcp_projectg      ð?z,Power for the Polynomial decay LR scheduler.Ú
poly_powerFz.Whether to activate the XLA compilation or notÚxlaÚreturnútf.distribute.Strategyc                 óÈ  — t          | dg¦  «         t                               d¦  «         t          j                             d¦  «        }| j        rt          j         	                    d¦  «         | j
        r"t          j                             d¬¦  «        }�nÈ	 | j        r7t          j        j                             | j        | j        | j        ¬¦  «        }n#t          j        j                             ¦   «         }n1# t$          $ r$ | j        rt'          d| j        › d	�¦  «        ‚d }Y nw xY w|r‰| j        rt          j         	                    d
¦  «         t          j                             |¦  «         t          j        j                             |¦  «         t          j                             |¦  «        }n©t3          |¦  «        dk    r!t          j                             d¬¦  «        }nut3          |¦  «        dk    r!t          j                             d¬¦  «        }nAt3          |¦  «        dk    rt          j                             ¦   «         }nt%          d¦  «        ‚|S )Nr   zTensorflow: setting up strategyÚGPUÚmixed_float16z/cpu:0)Údevice)ÚzoneÚprojectzCouldn't connect to TPU ú!Úmixed_bfloat16r   r   z/gpu:0zJCannot find the proper strategy, please check your environment properties.)r   ÚloggerÚinfor   ÚconfigÚlist_physical_devicesÚfp16r   Úmixed_precisionÚset_global_policyÚno_cudaÚ
distributeÚOneDeviceStrategyr   Úcluster_resolverÚTPUClusterResolverr   r   Ú
ValueErrorÚRuntimeErrorÚexperimental_connect_to_clusterÚtpuÚexperimentalÚinitialize_tpu_systemÚTPUStrategyÚlenÚMirroredStrategy)ÚselfÚgpusÚstrategyr1   s       úe/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/transformers/training_args_tf.pyÚ_setup_strategyz#TFTrainingArguments._setup_strategy¿   s&  € å˜$  Ñ'Ô'Ð'Ý�ŠÐ5Ñ6Ô6Ð6åŒy×.Ò.¨uÑ5Ô5ˆð Œ9ð 	EÝÔ!×3Ò3°OÑDÔDÐDàŒ<ð "	oÝ”}×6Ò6¸hÐ6ÑGÔGˆH‰HðØ”=ð NÝœ-Ô8×KÒKØœ¨D¬MÀ4ÔCSð Lñ ô �C�Cõ œ-Ô8×KÒKÑMÔM�CøøÝð ð ð Ø”=ð Ý&Ð'RÀ$Ä-Ð'RÐ'RÐ'RÑSÔSÐSà�C�C�Cð	øøøð ð oà”9ð NÝÔ)×;Ò;Ð<LÑMÔMÐMå”	×9Ò9¸#Ñ>Ô>Ð>Ý”Ô#×9Ò9¸#Ñ>Ô>Ð>åœ=×4Ò4°SÑ9Ô9��å�T‘”˜a’�Ýœ=×:Ò:À(Ð:ÑKÔK��Ý�T‘”˜a’�Ýœ=×:Ò:À(Ð:ÑKÔK��Ý�T‘”˜Q’�åœ=×9Ò9Ñ;Ô;��å Ð!mÑnÔnÐnàˆs   ÂA!C= Ã=+D+Ä*D+c                 ó2   — t          | dg¦  «         | j        S )z=
        The strategy used for distributed training.
        r   )r   r;   ©r7   s    r:   r9   zTFTrainingArguments.strategyð   s   € õ
 	˜$  Ñ'Ô'Ð'ØÔ#Ð#ó    c                 ó<   — t          | dg¦  «         | j        j        S )úY
        The number of replicas (CPUs, GPUs or TPU cores) used in this training.
        r   )r   r;   Únum_replicas_in_syncr=   s    r:   Ú
n_replicaszTFTrainingArguments.n_replicasø   s"   € õ
 	˜$  Ñ'Ô'Ð'ØÔ#Ô8Ð8r>   c                 ó   — dS )zH
        Whether or not the current process should produce log.
        F© r=   s    r:   Ú
should_logzTFTrainingArguments.should_log   s	   € ð
 ˆur>   c                 ót   — | j         rt                               d¦  «         | j         p| j        }|| j        z  S )zz
        The actual batch size for training (may differ from `per_gpu_train_batch_size` in distributed training).
        z•Using deprecated `--per_gpu_train_batch_size` argument which will be removed in a future version. Using `--per_device_train_batch_size` is preferred.)Úper_gpu_train_batch_sizer"   ÚwarningÚper_device_train_batch_sizerB   ©r7   Úper_device_batch_sizes     r:   Útrain_batch_sizez$TFTrainingArguments.train_batch_size  sK   € ð
 Ô(ð 	Ý�NŠNðOñô ð ð !%Ô =Ð aÀÔAaÐØ$ t¤Ñ6Ð6r>   c                 ót   — | j         rt                               d¦  «         | j         p| j        }|| j        z  S )z{
        The actual batch size for evaluation (may differ from `per_gpu_eval_batch_size` in distributed training).
        z“Using deprecated `--per_gpu_eval_batch_size` argument which will be removed in a future version. Using `--per_device_eval_batch_size` is preferred.)Úper_gpu_eval_batch_sizer"   rH   Úper_device_eval_batch_sizerB   rJ   s     r:   Úeval_batch_sizez#TFTrainingArguments.eval_batch_size  sK   € ð
 Ô'ð 	Ý�NŠNðNñô ð ð !%Ô <Ð _ÀÔ@_ÐØ$ t¤Ñ6Ð6r>   c                 óp   — t          | dg¦  «         t          j        dt          ¦  «         | j        j        S )r@   r   zaThe n_gpu argument is deprecated and will be removed in a future version, use n_replicas instead.)r   ÚwarningsÚwarnÚFutureWarningr;   rA   r=   s    r:   Ún_gpuzTFTrainingArguments.n_gpu!  s>   € õ
 	˜$  Ñ'Ô'Ð'ÝŒØoÝñ	
ô 	
ð 	
ð Ô#Ô8Ð8r>   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	frameworkr   r   r   ÚstrÚ__annotations__r   r   r   Úfloatr   Úboolr   ÚtupleÚintr;   Úpropertyr9   rB   rE   rL   rP   rU   rD   r>   r:   r   r      s5  € € € € € € ðEð EðN €IØ#˜eØØ˜-Ð(ðñ ô €Hˆh�sŒmð ð ñ ð
 $˜eØØ˜-Ð(ðñ ô €Hˆh�sŒmð ð ñ ð
 "' ØØÐ=Ð>ð"ñ "ô "€K�˜#”ð ð ñ ð
 ˜ØØÐHÐIðñ ô €J�ð ð ñ ð
 �˜e¨vÐ7gÐ.hÐiÑiÔi€CˆÐiÐiÑiàð. Ð'?ÀÐ'DÔ!Eð .ð .ð .ñ „_ð.ð` ð$ð $ð $ñ „Xð$ð ð9˜Cð 9ð 9ð 9ñ „Xð9ð ðð ñ „Xðð ð
7 #ð 
7ð 
7ð 
7ñ „Xð
7ð ð
7 ð 
7ð 
7ð 
7ñ „Xð
7ð ð	9�sð 	9ð 	9ð 	9ñ „Xð	9ð 	9ð 	9r>   r   )rR   Údataclassesr   r   Útypingr   Útraining_argsr   Úutilsr   r	   r
   r   Ú
get_loggerrV   r"   Ú
tensorflowr   Úmodeling_tf_utilsr   r   rD   r>   r:   ú<module>ri      sý   ðð €€€Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø Ð Ð Ð Ð Ð à ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ Oð 
ˆÔ	˜HÑ	%Ô	%€à€?ÑÔð )ØÐÐÐà(Ð(Ð(Ð(Ð(Ð(ð ðK9ð K9ð K9ð K9ð K9Ð+ñ K9ô K9ñ „ðK9ð K9ð K9r>   