o
    }oi                     @   s   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mZm	Z	 d dl
mZ e dd Ze dd Ze d	d
 ZG dd dZdS )    N)	OmegaConf)FastPitchModelHifiGanModelRadTTSModel)AppStatec                  C   s   t jdd} d| jd< | S )Ntts_en_fastpitch
model_nameTenable_volume)r   from_pretrainedexport_configmodel r   ^/home/ubuntu/.local/lib/python3.10/site-packages/tests/collections/tts/test_tts_exportables.pyfastpitch_model   s   
r   c                  C   s   t jdd} | S )Ntts_en_hifiganr   )r   r   r   r   r   r   hifigan_model!   s   r   c                  C   s   t jt jt} tt j| d}d |j_	d|jj
j_d|jj
j_d|jjj_d|jjj_d|_d|_t }d|_t|jd}d|_|  |ddd	 |S )
Nz4../../../examples/tts/conf/rad-tts_feature_pred.yamlz
dummy.jsong33333j@gzG!Q@T)cfgFTrue)enable_ragged_batchesr
   )ospathdirnameabspath__file__r   loadjoinr   init_from_ptl_ckpttrain_dsdatasetmanifest_filepathsup_data_pathvalidation_ds
pitch_mean	pitch_stdr   is_model_being_restoredr   evalset_export_config)this_test_dirr   	app_stater   r   r   r   radtts_model'   s    r+   c                   @   s   e Zd Zejjejdejjdd Zejjej	 ejdejjdd Z
ejjejdejjdd Zejjejdejjdd	 Zd
S )TestExportableGPUc                 C   sX   |  }t }tj|d}|j|ddddd W d    d S 1 s%w   Y  d S )Nzfp.onnxT   )outputverboseonnx_opset_versioncheck_trace
use_dynamo)cudatempfileTemporaryDirectoryr   r   r   export)selfr   r   tmpdirfilenamer   r   r   "test_FastPitchModel_export_to_onnx>   s
   
"z1TestExportable.test_FastPitchModel_export_to_onnxc                 C   sd   |  }|jd usJ t }tj|d}|j|dddd W d    d S 1 s+w   Y  d S )Nzhfg.onnxT)r/   r3   r0   r2   )r4   	generatorr5   r6   r   r   r   r7   )r8   r   r   r9   r:   r   r   r    test_HifiGanModel_export_to_onnxG   s   
"z/TestExportable.test_HifiGanModel_export_to_onnxc              	   C   s   |  }t M}tj|d}tj jjddtj	d" |j
jddd}|j
jdd	d}|j|d||gd
 W d    n1 s@w   Y  W d    d S W d    d S 1 sXw   Y  d S )Nzrad.tsTFenabledcache_enableddtype   	  	max_batchmax_dim     )r/   r0   input_exampler2   r4   r5   r6   r   r   r   torchampautocastfloat16input_modulerI   r7   r8   r+   r   r9   r:   input_example1input_example2r   r   r   &test_RadTTSModel_export_to_torchscriptR   s   
"z5TestExportable.test_RadTTSModel_export_to_torchscriptc              	   C   s   |  }t N}tj|d}tj jjddtj	d# |j
jddd}|j
jdd	d}|j||dd
|gd W d    n1 sAw   Y  W d    d S W d    d S 1 sYw   Y  d S )Nzrad.onnxTFr>   rB   rC   rD   rG   rH   r.   )r/   rI   r0   r1   r2   rJ   rP   r   r   r   test_RadTTSModel_export_to_onnx^   s"   
"z.TestExportable.test_RadTTSModel_export_to_onnxN)__name__
__module____qualname__pytestmarkpleasefixmerun_only_onunitr;   with_downloadsr=   rS   rT   r   r   r   r   r,   =   s$    


	
r,   )r   r5   rX   rK   	omegaconfr   nemo.collections.tts.modelsr   r   r   nemo.utils.app_stater   fixturer   r   r+   r,   r   r   r   r   <module>   s   


