Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attention Blocks in Denoiser #27

Open
leakedweights opened this issue Jun 7, 2024 · 0 comments
Open

Attention Blocks in Denoiser #27

leakedweights opened this issue Jun 7, 2024 · 0 comments

Comments

@leakedweights
Copy link

Hi!

I have noticed that the U-Net in ncsnpp.py handles attention blocks differently for the contracting and expanding path.

When downsampling, the number of attention blocks matches the no. of ResNet blocks for each dimension mult.

for i_level in range(num_resolutions):
    # Residual blocks for this resolution
    for i_block in range(num_res_blocks):
        h = ResnetBlock(out_ch=nf * ch_mult[i_level])(hs[-1], temb, train)
        if h.shape[1] in attn_resolutions:
            h = AttnBlock()(h)
        hs.append(h)

In the expanding path, however, there is only a single attention block.

# Upsampling block
for i_level in reversed(range(num_resolutions)):
    for i_block in range(num_res_blocks + 1):
        h = ResnetBlock(out_ch=nf * ch_mult[i_level])(
            jnp.concatenate([h, hs.pop()], axis=-1), temb, train
        )

    if h.shape[1] in attn_resolutions:
        h = AttnBlock()(h)

Why is this beneficial?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant