o
    iN*                     @   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'Voice conversion 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d0dtd1d | jd2d3td4d | jd5td6d7 | jd8td9d7 | jd:tdd;d | jd<tdd=d | jd>td?d@d& | jdAd)tddBd! | jdCdDtg dEddFdG | jdHdItdJdK | jdLdMdNd)tdOd | jdPd)tdQd | jdRd)tdSd | jdTd)tdUd | jdVd)tdWd | jdXdYd.tdZd[d\ | jd]d^d_tdZd`d\ | jdad)tdbd | jdctdddd& | jdedft	dgd | jdhdft	did | jdjdktg dldmd | jdndtdod | jdpdqt
drd | jdsdtt
dud | jdvdtt
dwd | jdxdydztd{d | jd|d}tdd~d! | jddtddd! | jddt
dd | jddtdd | jddft	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.zHTrain a new voice conversion (VC) 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-epochsd   zEvaluation interval epochsz--save-interval-epochszSave interval epochsz--report-interval-iters
   zReport interval iterationsz--srcspkzSource speaker)r   r
   z--trgspkzTarget speakerz--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)r   noamlamb	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-initz-Pre-trained 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 G/home/ubuntu/.local/lib/python3.10/site-packages/espnet/bin/vc_train.py
<listcomp>      0get_parser.<locals>.<lambda>.<locals>.<listcomp>,splitr.   r0   r.   r1   <lambda>      zget_parser.<locals>.<lambda>z<List of encoder modules to initialize, separated by a comma.z
--dec-initz-Pre-trained model path to initialize decoder.z--dec-init-modszdec.c                    r&   )Nc                    r'   r(   r)   r+   r.   r0   r1   r2   #  r3   r4   r5   r6   r.   r0   r.   r1   r8   #  r9   z<List of decoder modules to initialize, separated by a comma.z--freeze-modsc                    r&   )Nc                    r'   r(   r)   r+   r.   r0   r1   r2   )  r3   r4   r5   r6   r.   r0   r.   r1   r8   )  r9   z?List of modules to freeze (not to train), separated by a comma.)configargparseArgumentParserYAMLConfigFileParserArgumentDefaultsHelpFormatteraddadd_argumentintr*   r   r   float)parserr0   r0   r1   
get_parser   s  		
rC   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}n2t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_DEVICESr5   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.)&rC   parse_known_argsespnet.utils.dynamic_importrD   model_module
issubclassr   add_arguments
parse_argsr   versionverboseloggingbasicConfigINFOWARNwarningngpuosenvirongetlenr7   
subprocessrunPIPECalledProcessErrorFileNotFoundErrorrI   decodeinfoseedrandomnpbackendespnet.vc.pytorch_backend.vcrK   NotImplementedError)
cmd_argsrB   args_rD   model_classcvdrY   prK   r0   r0   r1   main0  sP   








rq   __main__r   )__doc__rT   rZ   rf   r^   sysr:   numpyrg   espnetr   espnet.nets.tts_interfacer   espnet.utils.cli_utilsr   espnet.utils.training.batchfyr   rC   rq   __name__argvr0   r0   r0   r1   <module>   s&     ?