o
    ॵi                     @   s.   d dl mZ d dlZd dlmZ dddZdS )    )MappingN)ModelOutputBaseFc                    s   t | trtt| D ]}t| |  | |< q| S t | ts#t | trIt| dr:|  D ]\}}t| | |< q,| S t	|  fdd|  D S t | t
tfr]t	|  fdd| D S t | tjrj| j |dS | S )a   Put the data to the target cuda device just before the forward function.
    Args:
        batch: The batch data out of the dataloader.
        device: (str | torch.device): The target device for the data.

    Returns: The data to the target device.

    __setitem__c                    s   i | ]
\}}|t | qS  	to_device).0kvdevicer   O/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/utils/data_utils.py
<dictcomp>   s    zto_device.<locals>.<dictcomp>c                 3   s    | ]}t | V  qd S )Nr   )r   r
   r   r   r   	<genexpr>!   s    zto_device.<locals>.<genexpr>)non_blocking)
isinstancer   rangelenr   dictr   hasattritemstypetuplelisttorchTensorto)batchr   r   idxr	   r
   r   r   r   r   	   s&   
	

r   )F)collections.abcr   r   modelscope.outputsr   r   r   r   r   r   <module>   s   