
    bi/                     <    d Z ddlmZ ddlmZ  e       rddlZd Zy)z7
Accelerate utilities: Utilities related to accelerate
    )version   )is_accelerate_availableNc                      t               s S t        j                  t        j                        j
                  }t        j                  |      t        j                  d      k  r S  fd}|S )a  
    Decorator that applies a registered CpuOffload hook to an arbitrary function rather than `forward`. This is useful
    for cases where a PyTorch module provides functions other than `forward` that should trigger a move to the
    appropriate acceleration device. This is the case for `encode` and `decode` in [`AutoencoderKL`].

    This decorator looks inside the internal `_hf_hook` property to find a registered offload hook.

    :param method: The method to decorate. This method should be a method of a PyTorch module.
    z0.17.0c                     t        | d      r1t        | j                  d      r| j                  j                  |         | g|i |S )N_hf_hookpre_forward)hasattrr   r	   )selfargskwargsmethods      [/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/diffusers/utils/accelerate_utils.pywrapperz#apply_forward_hook.<locals>.wrapper+   sA    4$)NMM%%d+d,T,V,,    )r   r   parse
accelerate__version__base_version)r   accelerate_versionr   s   `  r   apply_forward_hookr      sW     #$ z'='=>KK}}'(7==+BB-
 Nr   )__doc__	packagingr   import_utilsr   r   r    r   r   <module>r      s"     1 r   