Skip to content

Inconsistent usage of the linear layer in the SABlock #7992

Closed

Description

@KumoLiu

There are three linear in the original generative repo which now is combined within one linear layer. We need add an argument to make it consistent with before.

https://github.com/Project-MONAI/GenerativeModels/blob/main/generative/networks/nets/diffusion_model_unet.py#L379-L381

self.qkv = nn.Linear(self.hidden_input_size, self.inner_dim * 3, bias=qkv_bias)

Activity

  1. ericspod commented on Aug 5, 2024

    @ericspod
    Member

    Perhaps we change the current implementation to match this instead? I don't know if it's significant but making this an option will be problematic with Torchscript which doesn't like class variables being optional.

  2. added a commit that references this issue on Aug 6, 2024
    0337d45
  3. KumoLiu commented on Aug 6, 2024

    @KumoLiu
    ContributorAuthor

    I did a quick test, looks the outcome shows significantly different. In this PR, I utilized identity to get around the torchscript conversion issue. Could you please help review it, thanks!

    import torch.nn as nn
    import torch
    from monai.utils import set_determinism
    
    set_determinism(0)
    
    hidden_input_size = 360
    inner_dim = 360
    qkv_bias = True
    qkv = nn.Linear(hidden_input_size, inner_dim * 3, bias=qkv_bias)
    
    
    q = nn.Linear(hidden_input_size, inner_dim, bias=qkv_bias)
    k = nn.Linear(hidden_input_size, inner_dim, bias=qkv_bias)
    v = nn.Linear(hidden_input_size, inner_dim, bias=qkv_bias)
    
    input = torch.rand(2, 512, 360)
    qkv_out = qkv(input)
    q_out = q(input)
    k_out = k(input)
    v_out = v(input)
    
    print((qkv_out - torch.cat([q_out, k_out, v_out], dim=-1)).abs().sum().item()) --> 410444.28125
    
  4. added a commit that references this issue on Aug 9, 2024
    069519d
  5. added a commit that references this issue on Sep 2, 2024
    0d7744f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions