code: def _test_quantize_linear(
      batch_size,
      tokens,
      embeddings,
      use_bias,
      weights,
      activations,
      dtype,
      device,
  ):
      linear = (
          torch.nn.Linear(embeddings, embeddings, bias=use_bias)
          .to(dtype)
          .to(device)
      )
      qlinear = QLinear.from_module(
          linear, weights=weights, activations=activations
      )
      assert qlinear.qweight().itype == weights
      qinputs = random_qtensor(
          (batch_size,) + (tokens, embeddings), dtype=dtype
      ).to(device)
      # Run an inference with Calibration to get the correct output dtype
      with torch.no_grad(), Calibration():
          qout = qlinear(qinputs)
      if activations is not None:
          assert isinstance(qout, QTensor)
          assert qout.itype == activations
      # Align linear weights with quantized linear weights for comparison
      linear.weight = torch.nn.Parameter(qlinear.qweight().dequantize())
      out = linear(qinputs.dequantize())
      # We need to increase atol for float16 dtype
      dtype_atol = {torch.float32: 1e-4, torch.float16: 1e-3}[dtype]
      # We also need to increase atol for float8 itypes
      atol = {
          None: dtype_atol,
          torch.int8: dtype_atol,
          torch.float8_e5m2: 5e-3,
          torch.float8_e4m3fn: 5e-3,
      }[activations]
      assert_similar(out, qout, atol=atol)
  
file_path: quanto/test/nn/test_qlinear.py
imports: import pytest
  import torch
  from helpers import assert_similar, random_qtensor
  from quanto import Calibration, QTensor, int4
  from quanto.nn import QLinear
label_desc: Use image node_id 1 for calling a global function with example usage: _test_quantize_linear(batch_size, tokens, embeddings, use_bias, weights, activations, dtype, device) without return types