o
    i
                     @   sF   d dl mZ d dlmZmZ ddlmZmZmZ G dd dej	Z
dS )    )Callable)Tensornn   )	Attention
LayerScaleMlpc                       s   e Zd Zddddddddejejeeddfdedede	d	e
d
e
de
de	de	de	dedejf dedejf dedejf dedejf de
ddf fddZddedefddZ  ZS )Blockg      @T        NFdim	num_heads	mlp_ratioqkv_bias	proj_biasffn_biasdrop	attn_drop	drop_path	act_layer.
norm_layer
attn_class	ffn_layerqk_normreturnc              
      s   t    ||| _|||||||||d| _|	rt||	dnt | _||| _t	|| }||||||d| _
|	rAt||	dnt | _d| _d S )N)r   r   r   r   	proj_dropr   rope)init_values)in_featureshidden_featuresr   r   biasr
   )super__init__norm1attnr   r   Identityls1norm2intmlpls2sample_drop_ratio)selfr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mlp_hidden_dim	__class__ @/data/cameron/da3_repo/src/depth_anything_3/model/utils/block.pyr!      s0   



zBlock.__init__xc                    sP   ddt dt f fdd}dt dt f fdd}|||||d }||| }|S )	Nr1   r   c                    s      j | ||dS )Npos	attn_mask)r%   r#   r"   )r1   r3   r4   r+   r/   r0   attn_residual_funcH   s   z)Block.forward.<locals>.attn_residual_funcc                    s       | S )N)r)   r(   r&   )r1   r5   r/   r0   ffn_residual_funcK   s   z(Block.forward.<locals>.ffn_residual_funcr2   NN)r   )r+   r1   r3   r4   r6   r7   r/   r5   r0   forwardG   s
   zBlock.forwardr8   )__name__
__module____qualname__r   GELU	LayerNormr   r   r'   floatboolr   Moduler!   r   r9   __classcell__r/   r/   r-   r0   r	      s^    	0r	   N)typingr   torchr   r   	attentionr   r   r   rA   r	   r/   r/   r/   r0   <module>   s   