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.
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","."]
code: def set_weights(self, layer):
      if self.overwrite_qkv:
          qkv_weight = paddle.concat(
              [layer.q.weight, layer.k.weight, layer.v.weight], axis=0
          )[:, :, :, 0]
          qkv_bias = paddle.concat(
              [layer.q.bias, layer.k.bias, layer.v.bias], axis=0
          )
  
          self.qkv.weight.set_value(qkv_weight)
          self.qkv.bias.set_value(qkv_bias)
  
          proj_out = nn.Conv1D(self.channels, self.channels, 1)
          proj_out.weight.set_value(layer.proj_out.weight[:, :, :, 0])
          proj_out.bias.set_value(layer.proj_out.bias)
  
          self.proj = proj_out
      elif self.overwrite_linear:
          self.qkv.weight.set_value(
              paddle.concat(
                  [
                      self.NIN_0.W.t(),
                      self.NIN_1.W.t(),
                      self.NIN_2.W.t(),
                  ],
                  axis=0,
              )[:, :, None]
          )
          self.qkv.bias.set_value(
              paddle.concat(
                  [self.NIN_0.b, self.NIN_1.b, self.NIN_2.b], axis=0
              )
          )
  
          self.proj.weight.set_value(self.NIN_3.W.t()[:, :, None])
          self.proj.bias.set_value(self.NIN_3.b)
  
          self.norm.weight.set_value(self.GroupNorm_0.weight)
          self.norm.bias.set_value(self.GroupNorm_0.bias)
      else:
          self.proj.weight.set_value(self.proj_out.weight)
          self.proj.bias.set_value(self.proj_out.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 2 for calling the AttentionBlock obj's underlying member method code with example usage: obj.set_weights(layer) without return types