Your code is unfortunately not executable and yields shape mismatch errors:
# first code snippet:
    out = out.view(batch, channels, width_key, height_key)
RuntimeError: shape '[1, 128, 160, 160]' is invalid for input of size 819200

# second code snippet:
    V = self.valueConv(value).view(batch, -1, width * height)
RuntimeError: shape '[1, -1, 102400]' is invalid for input of size 25600

I assume that you are calling it via out = attention(a, b, b) based on the error message.