o
    Þ)i3	  ã                	   @   s„   U d dl mZmZ d dlZdgZeƒ Zeeejejf  e	d< ddej
dej
dedej
fd	d„Zdej
dej
dedej
fd
d„ZdS )é    )ÚSetÚTupleNÚsafe_permuteÚ_EXPERIMENTAL_DTYPESÚvalueÚpermÚdimÚreturnc                 C   sh   | j | jf}|tv rt| ||ƒS z| ttdƒg| |g ƒ W S  ty3   t |¡ t| ||ƒ Y S w )a>  
    Perform out-of-place permutation without using torch.Tensor.index_put_,
    whose implementation is missing for datatypes such as `torch.float8_e4m3fn`

    :param value: tensor to permute
    :param perm: permutation map
    :param dim: dimension along which to apply permutation
    :return: permuted value
    N)ÚdtypeÚdevicer   Ú_fallback_permuteÚtupleÚsliceÚRuntimeErrorÚadd)r   r   r   Zdtype_tuple© r   úl/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/compressed_tensors/utils/permute.pyr      s   

ýc                 C   sf   |   ¡ }tdƒg|d  }tdƒg|d  }t|ƒD ]\}}|||< |||< | t|ƒ |t|ƒ< q|S )zÛ
    Fallback permutation method for experimental dtypes.

    :param value: tensor to permute
    :param perm: permutation map
    :param dim: dimension along which to apply permutation
    :return: permuted value
    Né   )Úcloner   Ú	enumerater   )r   r   r   Z	value_retZorig_slicesZperm_slicesÚindexZ
perm_indexr   r   r   r   2   s   r   )r   )Útypingr   r   ZtorchÚ__all__Úsetr   r
   r   Ú__annotations__ZTensorÚintr   r   r   r   r   r   Ú<module>   s   "ÿÿÿþ