MCPcopy Create free account
hub / github.com/TimSeizinger/Bokehlicious / BasicLayer

Class BasicLayer

method/blocks.py:87–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85 return self.final_op(rb_res, x_size)
86
87class BasicLayer(nn.Module):
88 def __init__(self, embed_dim, depth, num_heads,
89 init_value: float, heads_range: float,
90 ffn_dim=96, drop_path=0., norm_layer=nn.LayerNorm,
91 use_checkpoint=False,
92 layerscale=False, layer_init_values=1e-5):
93
94 super().__init__()
95 self.embed_dim = embed_dim
96 self.depth = depth
97 self.use_checkpoint = use_checkpoint
98
99 self.Relpos = DynRelPos2d(embed_dim, num_heads, init_value, heads_range)
100
101 # build blocks
102 self.blocks = nn.ModuleList([
103 ApertureAttentionBlock(embed_dim=embed_dim, num_heads=num_heads, ffn_dim=ffn_dim,
104 layerscale=layerscale, norm_layer=norm_layer, layer_init_values=layer_init_values,
105 drop_path=drop_path[i] if isinstance(drop_path, list) else drop_path)
106 for i in range(depth)])
107
108 def forward(self, x, att_range_factor=None):
109 b, h, w, d = x.size()
110
111
112 rel_pos = self.Relpos((h, w), range_factor=att_range_factor)
113
114 for blk in self.blocks:
115 if self.use_checkpoint:
116 tmp_blk = partial(blk, attention_rel_pos=rel_pos)
117 x = checkpoint.checkpoint(tmp_blk, x)
118 else:
119 x = blk(x, attention_rel_pos=rel_pos)
120
121 return x
122
123class ApertureAttentionBlock(nn.Module):
124

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected