MCPcopy Create free account
hub / github.com/Little-Podi/AdaWorld / Encoder

Class Encoder

worldmodel/vwm/modules/diffusionmodules/model.py:254–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252
253
254class Encoder(nn.Module):
255 def __init__(
256 self,
257 *,
258 ch,
259 out_channels,
260 ch_mult=(1, 2, 4, 8),
261 num_res_blocks,
262 attn_resolutions,
263 dropout=0.0,
264 resamp_with_conv=True,
265 in_channels,
266 resolution,
267 z_channels,
268 use_linear_attn=False,
269 attn_type="vanilla",
270 **ignore_kwargs
271 ):
272 super(Encoder, self).__init__()
273 if use_linear_attn:
274 attn_type = "linear"
275 self.ch = ch
276 self.temb_ch = 0
277 self.num_resolutions = len(ch_mult)
278 self.num_res_blocks = num_res_blocks
279 self.resolution = resolution
280 self.in_channels = in_channels
281
282 # Downsampling
283 self.conv_in = nn.Conv2d(in_channels, self.ch, kernel_size=3, stride=1, padding=1)
284
285 curr_res = resolution
286 in_ch_mult = (1,) + tuple(ch_mult)
287 self.in_ch_mult = in_ch_mult
288 self.down = nn.ModuleList()
289 for i_level in range(self.num_resolutions):
290 block = nn.ModuleList()
291 attn = nn.ModuleList()
292 block_in = ch * in_ch_mult[i_level]
293 block_out = ch * ch_mult[i_level]
294 for i_block in range(self.num_res_blocks):
295 block.append(
296 ResnetBlock(
297 in_channels=block_in,
298 out_channels=block_out,
299 temb_channels=self.temb_ch,
300 dropout=dropout
301 )
302 )
303 block_in = block_out
304 if curr_res in attn_resolutions:
305 attn.append(make_attn(block_in, attn_type=attn_type))
306 down = nn.Module()
307 down.block = block
308 down.attn = attn
309 if i_level != self.num_resolutions - 1:
310 down.downsample = Downsample(block_in, resamp_with_conv)
311 curr_res = curr_res // 2

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected