MCPcopy Create free account
hub / github.com/bbaaii/DreamDiffusion / Model

Class Model

code/dc_ldm/modules/diffusionmodules/model.py:216–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

214
215
216class Model(nn.Module):
217 def __init__(self, *, ch, out_ch, ch_mult=(1,2,4,8), num_res_blocks,
218 attn_resolutions, dropout=0.0, resamp_with_conv=True, in_channels,
219 resolution, use_timestep=True, use_linear_attn=False, attn_type="vanilla"):
220 super().__init__()
221 if use_linear_attn: attn_type = "linear"
222 self.ch = ch
223 self.temb_ch = self.ch*4
224 self.num_resolutions = len(ch_mult)
225 self.num_res_blocks = num_res_blocks
226 self.resolution = resolution
227 self.in_channels = in_channels
228
229 self.use_timestep = use_timestep
230 if self.use_timestep:
231 # timestep embedding
232 self.temb = nn.Module()
233 self.temb.dense = nn.ModuleList([
234 torch.nn.Linear(self.ch,
235 self.temb_ch),
236 torch.nn.Linear(self.temb_ch,
237 self.temb_ch),
238 ])
239
240 # downsampling
241 self.conv_in = torch.nn.Conv2d(in_channels,
242 self.ch,
243 kernel_size=3,
244 stride=1,
245 padding=1)
246
247 curr_res = resolution
248 in_ch_mult = (1,)+tuple(ch_mult)
249 self.down = nn.ModuleList()
250 for i_level in range(self.num_resolutions):
251 block = nn.ModuleList()
252 attn = nn.ModuleList()
253 block_in = ch*in_ch_mult[i_level]
254 block_out = ch*ch_mult[i_level]
255 for i_block in range(self.num_res_blocks):
256 block.append(ResnetBlock(in_channels=block_in,
257 out_channels=block_out,
258 temb_channels=self.temb_ch,
259 dropout=dropout))
260 block_in = block_out
261 if curr_res in attn_resolutions:
262 attn.append(make_attn(block_in, attn_type=attn_type))
263 down = nn.Module()
264 down.block = block
265 down.attn = attn
266 if i_level != self.num_resolutions-1:
267 down.downsample = Downsample(block_in, resamp_with_conv)
268 curr_res = curr_res // 2
269 self.down.append(down)
270
271 # middle
272 self.mid = nn.Module()
273 self.mid.block_1 = ResnetBlock(in_channels=block_in,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected