MCPcopy Create free account
hub / github.com/Ropedia/SpatialBench / __init__

Method __init__

benchmark/models/loger/models/layers/block.py:40–84  ·  view source on GitHub ↗
(
        self,
        dim: int,
        num_heads: int,
        mlp_ratio: float = 4.0,
        qkv_bias: bool = False,
        proj_bias: bool = True,
        ffn_bias: bool = True,
        drop: float = 0.0,
        attn_drop: float = 0.0,
        init_values=None,
        drop_path: float = 0.0,
        act_layer: Callable[..., nn.Module] = nn.GELU,
        norm_layer: Callable[..., nn.Module] = nn.LayerNorm,
        attn_class: Callable[..., nn.Module] = Attention,
        ffn_layer: Callable[..., nn.Module] = Mlp,
    )

Source from the content-addressed store, hash-verified

38
39class Block(nn.Module):
40 def __init__(
41 self,
42 dim: int,
43 num_heads: int,
44 mlp_ratio: float = 4.0,
45 qkv_bias: bool = False,
46 proj_bias: bool = True,
47 ffn_bias: bool = True,
48 drop: float = 0.0,
49 attn_drop: float = 0.0,
50 init_values=None,
51 drop_path: float = 0.0,
52 act_layer: Callable[..., nn.Module] = nn.GELU,
53 norm_layer: Callable[..., nn.Module] = nn.LayerNorm,
54 attn_class: Callable[..., nn.Module] = Attention,
55 ffn_layer: Callable[..., nn.Module] = Mlp,
56 ) -> None:
57 super().__init__()
58 # print(f"biases: qkv: {qkv_bias}, proj: {proj_bias}, ffn: {ffn_bias}")
59 self.norm1 = norm_layer(dim)
60 self.attn = attn_class(
61 dim,
62 num_heads=num_heads,
63 qkv_bias=qkv_bias,
64 proj_bias=proj_bias,
65 attn_drop=attn_drop,
66 proj_drop=drop,
67 )
68
69 self.ls1 = LayerScale(dim, init_values=init_values) if init_values else nn.Identity()
70 self.drop_path1 = DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
71
72 self.norm2 = norm_layer(dim)
73 mlp_hidden_dim = int(dim * mlp_ratio)
74 self.mlp = ffn_layer(
75 in_features=dim,
76 hidden_features=mlp_hidden_dim,
77 act_layer=act_layer,
78 drop=drop,
79 bias=ffn_bias,
80 )
81 self.ls2 = LayerScale(dim, init_values=init_values) if init_values else nn.Identity()
82 self.drop_path2 = DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
83
84 self.sample_drop_ratio = drop_path
85
86 def forward(self, x: Tensor) -> Tensor:
87 def attn_residual_func(x: Tensor) -> Tensor:

Callers 4

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 2

LayerScaleClass · 0.50
DropPathClass · 0.50

Tested by

no test coverage detected