o
    }oi                     @   s   d dl Z d dlmZ d dlZd dlZd dlmZ edefddZddeej	e
f fd	d
ZedejfddZdefddZdS )    N)contextmanager)ASRModelmodelc              	   c   sj    t | jj}zdV  W | jdd | jj|kr | | dS dS | jdd | jj|kr4| | w w )z
    Context manager to preserve the decoding strategy and device of the model.
    This is useful for tests that modify the model's decoding strategy or device
    to avoid side effects or costly model reloading.
    Ncpudevice)copydeepcopycfgdecodingtochange_decoding_strategy)r   backup_decoding_cfg r   X/home/ubuntu/.local/lib/python3.10/site-packages/tests/collections/asr/decoding/utils.py$preserve_decoding_cfg_and_cpu_device   s   r   >  returnc                 C   s&   t j| |d\}}tj|tjd|fS )N)sr)dtype)librosaloadtorchtensorfloat32)	file_path	target_sraudior   r   r   r   
load_audio)   s   r   r   c              	   c   sZ    z| j dkrtjd d V  W | j dkrtjd d S d S | j dkr,tjd w w )Ncuda   r   )typer   r   set_sync_debug_moder   r   r   r   avoid_sync_operations.   s   

r#   c                 C   s   d| j j_d| j j_d S )Ng        r   )preprocessor
featurizerditherpad_to)r   r   r   r   make_preprocessor_deterministic9   s   
r(   )r   )r   
contextlibr   r   r   nemo.collections.asr.modelsr   r   tupleTensorintr   r   r#   r(   r   r   r   r   <module>   s   
