dew.nn.backbones.edm2
EDM2’s magnitude-preserving U-Net.
The architecture is Figure 21 of Karras et al. 2024. The code follows
NVlabs/edm2’s training/networks_edm2.py UNet, channels last, built from
dew.nn.mp: every convolution and dense layer is an MPConv, the time
features are MPFourier, branches join with mp_sum and skips with
mp_cat, and there are no biases or gains. Train it under the edm preset
with OptimConfig.forced_weight_normalization. In place of the one-hot
class label, it embeds the mask-weighted mean of the textcontext states at
unit magnitude through the same dense layer.
| Name | Summary |
|---|---|
Block | Runs one encoder or decoder block, with optional self-attention. |
EDM2UNet | Runs EDM2’s U-Net. |
class Block( flavor: str = 'enc', resample: str = 'keep', attention: bool = False, channels_per_head: int = 64, dropout: float = 0.0, res_balance: float = 0.3, attn_balance: float = 0.3, clip_act: float | None = 256.0, attention_impl: AttentionImpl = 'auto',)Runs one encoder or decoder block, with optional self-attention.
Block.spatial_shape
Section titled “Block.spatial_shape”def spatial_shape(shape: tuple[int, ...]) -> tuple[int, ...]Block.model_flops
Section titled “Block.model_flops”def model_flops(lengths, input_features: int, emb_features: int) -> floatThe block’s residual, time and skip maps and optional spatial attention.
EDM2UNet
Section titled “EDM2UNet”class EDM2UNet( output_channels: int = 3, model_channels: int = 192, channel_mult: Sequence[int] = (1, 2, 3, 4), channel_mult_noise: int | None = None, channel_mult_emb: int | None = None, num_blocks: int = 3, attn_resolutions: Sequence[int] = (16, 8), label_balance: float = 0.5, concat_balance: float = 0.5, channels_per_head: int = 64, dropout: float = 0.0, res_balance: float = 0.3, attn_balance: float = 0.3, clip_act: float | None = 256.0, dtype: Dtype | None = None, attention_impl: AttentionImpl = 'auto',)Runs EDM2’s U-Net.
The fields are the reference’s, and output_channels is its
img_channels. attn_resolutions are feature-map sizes, compared with
the input’s height halved once per level.
EDM2UNet.condition_lengths
Section titled “EDM2UNet.condition_lengths”def condition_lengths(lengths: np.ndarray, spans: np.ndarray) -> np.ndarrayEDM2UNet.model_flops
Section titled “EDM2UNet.model_flops”def model_flops(lengths) -> floatEDM2UNet.spatial_flops
Section titled “EDM2UNet.spatial_flops”def spatial_flops( sample_shape: tuple[int, ...], rows: int, context_lengths=None, text_features: int | None = None,) -> floatCount the shared magnitude-preserving stage walk on spatial shapes.
EDM2UNet.spatial_walk
Section titled “EDM2UNet.spatial_walk”def spatial_walk(x, emb, train, operations)