class_docstr: An attention block that allows spatial positions to attend to each other. Originally ported from here, but adapted
  to the N-d case.
  https://github.com/hojonathanho/diffusion/blob/1e0dceb3b3495bbe19116a5e1b3596cd0706c543/diffusion_tf/models/unet.py#L66.
  Uses three q, k, v linear layers to compute attention
class_docstr_tok: ["An","attention","block","that","allows","spatial","positions","to","attend","to","each","other",".","Originally","ported","from","here",",","but","adapted","to","the","N-d","case",".","https",":","\/\/github.com\/hojonathanho\/diffusion\/blob\/1e0dceb3b3495bbe19116a5e1b3596cd0706c543\/diffusion_tf\/models\/unet.py","#","L66",".","Uses","three","q",",","k",",","v","linear","layers","to","compute","attention"]
code: def set_weight(self, attn_layer):
      self.group_norm.weight.set_value(attn_layer.norm.weight)
      self.group_norm.bias.set_value(attn_layer.norm.bias)
  
      if hasattr(attn_layer, "q"):
          self.query.weight.set_value(attn_layer.q.weight[:, :, 0, 0])
          self.key.weight.set_value(attn_layer.k.weight[:, :, 0, 0])
          self.value.weight.set_value(attn_layer.v.weight[:, :, 0, 0])
  
          self.query.bias.set_value(attn_layer.q.bias)
          self.key.bias.set_value(attn_layer.k.bias)
          self.value.bias.set_value(attn_layer.v.bias)
  
          self.proj_attn.weight.set_value(
              attn_layer.proj_out.weight[:, :, 0, 0]
          )
          self.proj_attn.bias.set_value(attn_layer.proj_out.bias)
      elif hasattr(attn_layer, "NIN_0"):
          self.query.weight.set_value(attn_layer.NIN_0.W.t())
          self.key.weight.set_value(attn_layer.NIN_1.W.t())
          self.value.weight.set_value(attn_layer.NIN_2.W.t())
  
          self.query.bias.set_value(attn_layer.NIN_0.b)
          self.key.bias.set_value(attn_layer.NIN_1.b)
          self.value.bias.set_value(attn_layer.NIN_2.b)
  
          self.proj_attn.weight.set_value(attn_layer.NIN_3.W.t())
          self.proj_attn.bias.set_value(attn_layer.NIN_3.b)
  
          self.group_norm.weight.set_value(
              attn_layer.GroupNorm_0.weight
          )
          self.group_norm.bias.set_value(attn_layer.GroupNorm_0.bias)
      else:
          qkv_weight = attn_layer.qkv.weight.reshape(
              [
                  self.num_heads,
                  3 * self.channels // self.num_heads,
                  self.channels,
              ]
          )
          qkv_bias = attn_layer.qkv.bias.reshape(
              [self.num_heads, 3 * self.channels // self.num_heads]
          )
  
          q_w, k_w, v_w = qkv_weight.split(
              self.channels // self.num_heads, axis=1
          )
          q_b, k_b, v_b = qkv_bias.split(
              self.channels // self.num_heads, axis=1
          )
  
          self.query.weight.set_value(q_w.reshape([-1, self.channels]))
          self.key.weight.set_value(k_w.reshape([-1, self.channels]))
          self.value.weight.set_value(v_w.reshape([-1, self.channels]))
  
          self.query.bias.set_value(q_b.flatten())
          self.key.bias.set_value(k_b.flatten())
          self.value.bias.set_value(v_b.flatten())
  
          self.proj_attn.weight.set_value(
              attn_layer.proj.weight[:, :, 0]
          )
          self.proj_attn.bias.set_value(attn_layer.proj.bias)
  
imports: import math
  from inspect import isfunction
  import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
label_desc: Use image node_id 4 for calling the AttentionBlockNew obj's underlying member method code with example usage: obj.set_weight(attn_layer) without return types