class_docstr: Single-head Attention layer for label-specific representations
class_docstr_tok: ["Single-head","Attention","layer","for","label-specific","representations"]
code: def split_qkv_packed(self, inp, k_inp=None):
      len_inp = inp.size(0)
      v_inp_repeated = inp.repeat(self.d_l, 1).view(
          self.d_l, -1, inp.size(-1)
      )  # d_l x len_inp x d_model
      if k_inp is None:
          k_inp_repeated = v_inp_repeated
      else:
          k_inp_repeated = k_inp.repeat(self.d_l, 1).view(
              self.d_l, -1, k_inp.size(-1)
          )  # d_l x len_inp x d_model
  
      if not self.partitioned:
          if self.q_as_matrix:
              q_s = torch.bmm(
                  k_inp_repeated, self.w_qs
              )  # d_l x len_inp x d_k
          else:
              q_s = self.w_qs.unsqueeze(1)  # d_l x 1 x d_k
          k_s = torch.bmm(
              k_inp_repeated, self.w_ks
          )  # d_l x len_inp x d_k
          v_s = torch.bmm(
              v_inp_repeated, self.w_vs
          )  # d_l x len_inp x d_v
      else:
          if self.q_as_matrix:
              q_s = torch.cat(
                  [
                      torch.bmm(
                          k_inp_repeated[:, :, : self.d_content],
                          self.w_qs1,
                      ),
                      torch.bmm(
                          k_inp_repeated[:, :, self.d_content :],
                          self.w_qs2,
                      ),
                  ],
                  -1,
              )
          else:
              q_s = torch.cat(
                  [
                      self.w_qs1.unsqueeze(1),
                      self.w_qs2.unsqueeze(1),
                  ],
                  -1,
              )
          k_s = torch.cat(
              [
                  torch.bmm(
                      k_inp_repeated[:, :, : self.d_content], self.w_ks1
                  ),
                  torch.bmm(
                      k_inp_repeated[:, :, self.d_content :], self.w_ks2
                  ),
              ],
              -1,
          )
          v_s = torch.cat(
              [
                  torch.bmm(
                      v_inp_repeated[:, :, : self.d_content], self.w_vs1
                  ),
                  torch.bmm(
                      v_inp_repeated[:, :, self.d_content :], self.w_vs2
                  ),
              ],
              -1,
          )
      return q_s, k_s, v_s
  
imports: import numpy
  import functools
  import sys
  import torch
  from torch.autograd import Variable
  import torch.nn
  import torch.nn.init
label_desc: Use image node_id 2 for calling the LabelAttention obj's underlying member method code with example usage: obj.split_qkv_packed(inp, k_inp) and returns: q_s,  k_s,  v_s