code: def _test_quantize_attention(
      device, dtype=torch.float32, weights=torch.int8, activations=None
  ):
      att = Attention().to(dtype).to(device)
      batch_size = 10
      seq_len = 64
      input_shape = (batch_size, seq_len, att.hidden_size)
      inputs = random_tensor(input_shape).to(device)
      with torch.no_grad():
          outputs = att(inputs)
      quantize(att, weights=weights, activations=activations)
      if activations is None:
          with torch.no_grad():
              qoutputs = att(inputs)
      else:
          with torch.no_grad(), Calibration():
              qoutputs = att(inputs)
      atol = {
          None: 1e-4,
          torch.int8: 1e-3,
          torch.float8_e5m2: 1e-2,
          torch.float8_e4m3fn: 1e-2,
      }[activations]
      assert_similar(outputs, qoutputs, atol=atol)
  
imports: import math
  from typing import Optional
  import pytest
  import torch
  import torch.utils.checkpoint
  from helpers import assert_similar, random_tensor
  from torch import nn
  from quanto import Calibration, quantize
label_desc: Use image node_id 4 for calling a global function with example usage: _test_quantize_attention(device, dtype, weights, activations) without return types