o
    i)                     @   s   d Z ddlZddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZ ddlmZ ddlmZ dd Zd	d
 ZedkrMeejdd  dS dS )z%Text-to-speech model training script.    N)__version__)TTSInterface)	strtobool)BATCH_COUNT_CHOICESc                  C   s  t jdt jt jd} | jdddd | jdddd | jd	dd
d | jddtdd | jddtddgdd | jdtddd | jddtdd | jddtdd | jdddtdd d! | jd"d#td$d%d& | jd'd(d)td*d | jd+dtdd,d! | jd-dtd.d | jd/dtd0d | jd1d2td3d | jd4tdd5d | jd6tdd7d | jd8td9d:d& | jd;d)tdd<d! | jd=d>tg d?dd@dA | jdBdCtdDdE | jdFdGdHd)tdId | jdJd)tdKd | jdLd)tdMd | jdNd)tdOd | jdPd)tdQd | jdRdSd2tdTdUdV | jdWdXdYtdTdZdV | jd[d)td\d | jd]tdd^d& | jd_d`t	dad | jdbd`t	dcd | jdddetdedfgdgd | jdhdtdid | jdjdkt
dld | jdmdnt
dod | jdpdnt
dqd | jdrdsdttdud | jdvdwtddxd! | jdydztdd{d! | jd|dt
d}d | jd~dtdd | jdd`t	dd | jddtdd | jdddd dd | jddtdd | jdddd dd | jdddd dd | S )z!Get parser of training arguments.zGTrain a new text-to-speech (TTS) model on one CPU, one or multiple GPUs)descriptionconfig_file_parser_classformatter_classz--configTzconfig file path)is_config_filehelpz	--config2zCsecond config file path that overwrites the settings in `--config`.z	--config3zRthird config file path that overwrites the settings in `--config` and `--config2`.z--ngpuNz5Number of GPUs. If not given, use all visible devices)defaulttyper
   z	--backendpytorchchainerzBackend library)r   r   choicesr
   z--outdirzOutput directory)r   requiredr
   z--debugmode   	Debugmodez--seedzRandom seedz--resumez-r ?z!Resume the training from snapshot)r   r   nargsr
   z--minibatchesz-Nz-1z&Process only N minibatches (for debug))r   r   r
   z	--verbosez-Vr   zVerbose optionz--tensorboard-dirzTensorboard log directory pathz--eval-interval-epochszEvaluation interval epochsz--save-interval-epochszSave interval epochsz--report-interval-itersd   zReport interval iterationsz--train-jsonzFilename of training jsonz--valid-jsonzFilename of validation jsonz--model-modulez7espnet.nets.pytorch_backend.e2e_tts_tacotron2:Tacotron2zmodel defined modulez--sortagradzFHow many epochs to use sortagrad for. 0 = deactivated, -1 = all epochsz--batch-sort-keyshuffle)r   outputinputz@Batch sorting key. "shuffle" only work with --batch-count "seq".)r   r   r   r   r
   z--batch-countautozKHow to count batch_size. The default (auto) will find how to count by args.)r   r   r
   z--batch-sizez--batch-seqsz-bz*Maximum seqs in a minibatch (0 to disable)z--batch-binsz*Maximum bins in a minibatch (0 to disable)z--batch-frames-inz2Maximum input frames in a minibatch (0 to disable)z--batch-frames-outz3Maximum output frames in a minibatch (0 to disable)z--batch-frames-inoutz9Maximum input+output frames in a minibatch (0 to disable)z--maxlen-inz--batch-seq-maxlen-inMLzPWhen --batch-count=seq, batch size is reduced if the input sequence length > ML.)r   r   metavarr
   z--maxlen-outz--batch-seq-maxlen-out   zPWhen --batch-count=seq, batch size is reduced if the output sequence length > MLz--num-iter-processeszNumber of processes of iteratorz--preprocess-confz-The configuration file for the pre-processingz--use-speaker-embeddingFz Whether to use speaker embeddingz--use-second-targetzWhether to use second targetz--optadamnoam	Optimizerz--accum-gradzNumber of gradient accumurationz--lrgMbP?zLearning rate for optimizerz--epsgư>zEpsilon for optimizerz--weight-decayz&Weight decay coefficient for optimizerz--epochsz-e   zNumber of maximum epochsz--early-stop-criterionzvalidation/main/lossz=Value to monitor to trigger an early stopping of the trainingz
--patience   zINumber of epochs to wait without improvement before stopping the trainingz--grad-clipzGradient norm threshold to clipz--num-save-attention   z*Number of samples of attention to be savedz--keep-all-data-on-memz"Whether to keep all data on memoryz
--enc-initz1Pre-trained TTS model path to initialize encoder.z--enc-init-modszenc.c                        fdd  dD S )Nc                       g | ]
} d krt |qS r   str.0mods H/home/ubuntu/.local/lib/python3.10/site-packages/espnet/bin/tts_train.py
<listcomp>      0get_parser.<locals>.<lambda>.<locals>.<listcomp>,splitr,   r.   r,   r/   <lambda>      zget_parser.<locals>.<lambda>z<List of encoder modules to initialize, separated by a comma.z
--dec-initz1Pre-trained TTS model path to initialize decoder.z--dec-init-modszdec.c                    r$   )Nc                    r%   r&   r'   r)   r,   r.   r/   r0     r1   r2   r3   r4   r,   r.   r,   r/   r6     r7   z<List of decoder modules to initialize, separated by a comma.z--freeze-modsc                    r$   )Nc                    r%   r&   r'   r)   r,   r.   r/   r0     r1   r2   r3   r4   r,   r.   r,   r/   r6     r7   z?List of modules to freeze (not to train), separated by a comma.)configargparseArgumentParserYAMLConfigFileParserArgumentDefaultsHelpFormatteraddadd_argumentintr(   r   r   float)parserr.   r.   r/   
get_parser   s  		
rA   c           
   	   C   s  t  }|| \}}ddlm} ||j}t|tsJ || || }t	|_
|jdkr7tjtjdd ntjtjdd td |jdu rtjd}|dur[t|d}n.td	 ztjd
dgtjtjd}W n tjtfy|   d}Y nw t|j dd }||_n|j}td|  td|j  t |j t!j |j |j"dkrddl#m$}	 |	| dS t%d)zRun training.r   )dynamic_importz>%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s)levelformatzSkip DEBUG/INFO messagesNCUDA_VISIBLE_DEVICESr3   z CUDA_VISIBLE_DEVICES is not set.z
nvidia-smiz-L)stdoutstderr
r   zngpu: zrandom seed = %dr   )trainzOnly pytorch is supported.)&rA   parse_known_argsespnet.utils.dynamic_importrB   model_module
issubclassr   add_arguments
parse_argsr   versionverboseloggingbasicConfigINFOWARNwarningngpuosenvirongetlenr5   
subprocessrunPIPECalledProcessErrorFileNotFoundErrorrG   decodeinfoseedrandomnpbackendespnet.tts.pytorch_backend.ttsrI   NotImplementedError)
cmd_argsr@   args_rB   model_classcvdrW   prI   r.   r.   r/   main&  sR   








ro   __main__r   )__doc__rR   rX   rd   r\   sysr8   numpyre   espnetr   espnet.nets.tts_interfacer   espnet.utils.cli_utilsr   espnet.utils.training.batchfyr   rA   ro   __name__argvr.   r.   r.   r/   <module>   s&     @