
    9i9                         S SK Jr  S rS rg)    )Mappingc                 ~   SSK n [        U [        [        45      (       a  [	        U 5      " S U  5       5      $ [        U [
        5      (       a/  U R                  5        VVs0 s H  u  p#U[        U5      _M     snn$ [        XR                  5      (       a   U R                  5       nUR                  5       $ U $ s  snnf )zNumpify nested torch tensors.

NOTE: If the type of input tensors is dict-like(Mapping, dict, OrderedDict, etc.), the return type will be dict.

Args:
    tensors: Nested torch tensors.

Returns:
    The numpify tensors.
r   Nc              3   8   #    U  H  n[        U5      v   M     g 7fN)torch_nested_numpify.0ts     ]/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/utils/tensor_utils.py	<genexpr>'torch_nested_numpify.<locals>.<genexpr>   s     Fg1!44g   )torch
isinstancelisttupletyper   itemsr   Tensorcpunumpytensorsr   kr
   s       r   r   r      s     F'D%=))G}FgFFF'7##7>}}Gtq'**GG'<<((KKMwwyN	 Hs   !B9c                 ^   SSK n [        U [        [        45      (       a  [	        U 5      " S U  5       5      $ [        U [
        5      (       a/  U R                  5        VVs0 s H  u  p#U[        U5      _M     snn$ [        XR                  5      (       a  U R                  5       $ U $ s  snnf )zDetach nested torch tensors.

NOTE: If the type of input tensors is dict-like(Mapping, dict, OrderedDict, etc.), the return type will be dict.

Args:
    tensors: Nested torch tensors.

Returns:
    The detached tensors.
r   Nc              3   8   #    U  H  n[        U5      v   M     g 7fr   )torch_nested_detachr   s     r   r   &torch_nested_detach.<locals>.<genexpr>.   s     EW033Wr   )
r   r   r   r   r   r   r   r   r   detachr   s       r   r   r      s     E'D%=))G}EWEEE'7##6=mmoFoda&q))oFF'<<((~~N Gs   !B)N)collections.abcr   r   r        r   <module>r#      s    $2r"   