code: def _test_quantize_layernorm(
      batch_size, tokens, embeddings, dtype, activations, device
  ):
      # Instantiate a normalization layer
      norm = torch.nn.LayerNorm(embeddings).to(dtype).to(device)
      qnorm = QLayerNorm.from_module(norm, activations=activations)
      qinputs = random_qtensor(
          (batch_size,) + (tokens, embeddings),
          itype=activations,
          dtype=dtype,
      ).to(device)
      # Calibrate to avoid clipping and to set the correct dtype
      with torch.no_grad(), Calibration():
          qout = qnorm(qinputs)
      qout = qnorm(qinputs)
      assert isinstance(qout, QTensor)
      assert qout.dtype == dtype
      assert qout.itype == activations
      # Compare with the float results
      out = norm(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 = {
          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_qlayernorm.py
imports: import pytest
  import torch
  from helpers import assert_similar, random_qtensor
  from quanto import Calibration, QTensor
  from quanto.nn import QLayerNorm
label_desc: Use image node_id 1 for calling a global function with example usage: _test_quantize_layernorm(batch_size, tokens, embeddings, dtype, activations, device) without return types