MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / FlaxDownEncoderBlock2D

Class FlaxDownEncoderBlock2D

src/diffusers/models/vae_flax.py:275–329  ·  view source on GitHub ↗

r""" Flax Resnet blocks-based Encoder block for diffusion-based VAE. Parameters: in_channels (:obj:`int`): Input channels out_channels (:obj:`int`): Output channels dropout (:obj:`float`, *optional*, defaults to 0.0): Dropout rate

Source from the content-addressed store, hash-verified

273
274
275class FlaxDownEncoderBlock2D(nn.Module):
276 r"""
277 Flax Resnet blocks-based Encoder block for diffusion-based VAE.
278
279 Parameters:
280 in_channels (:obj:`int`):
281 Input channels
282 out_channels (:obj:`int`):
283 Output channels
284 dropout (:obj:`float`, *optional*, defaults to 0.0):
285 Dropout rate
286 num_layers (:obj:`int`, *optional*, defaults to 1):
287 Number of Resnet layer block
288 resnet_groups (:obj:`int`, *optional*, defaults to `32`):
289 The number of groups to use for the Resnet block group norm
290 add_downsample (:obj:`bool`, *optional*, defaults to `True`):
291 Whether to add downsample layer
292 dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32):
293 Parameters `dtype`
294 """
295
296 in_channels: int
297 out_channels: int
298 dropout: float = 0.0
299 num_layers: int = 1
300 resnet_groups: int = 32
301 add_downsample: bool = True
302 dtype: jnp.dtype = jnp.float32
303
304 def setup(self):
305 resnets = []
306 for i in range(self.num_layers):
307 in_channels = self.in_channels if i == 0 else self.out_channels
308
309 res_block = FlaxResnetBlock2D(
310 in_channels=in_channels,
311 out_channels=self.out_channels,
312 dropout=self.dropout,
313 groups=self.resnet_groups,
314 dtype=self.dtype,
315 )
316 resnets.append(res_block)
317 self.resnets = resnets
318
319 if self.add_downsample:
320 self.downsamplers_0 = FlaxDownsample2D(self.out_channels, dtype=self.dtype)
321
322 def __call__(self, hidden_states, deterministic=True):
323 for resnet in self.resnets:
324 hidden_states = resnet(hidden_states, deterministic=deterministic)
325
326 if self.add_downsample:
327 hidden_states = self.downsamplers_0(hidden_states)
328
329 return hidden_states
330
331
332class FlaxUpDecoderBlock2D(nn.Module):

Callers 1

setupMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected