code: def test_mixed_dtypes_linear(
      self, dtype: torch.dtype, device: str = "cuda"
  ):
      version = _get_torch_cuda_version()
      if version < (11, 8):
          self.skipTest(
              "_mixed_dtypes_linear only compiled for CUDA 11.8+"
          )
  
      def run_test(
          batch_shape,
          m,
          n,
          k,
          add_bias,
          activation,
          dtype,
          dtypeq,
          device,
          rtol,
          atol,
      ):
          if not add_bias and activation != "none":
              return
  
          val_lo, val_hi = -1, 1
          valq_lo, valq_hi = -2, 2
          input = make_tensor(
              *batch_shape,
              m,
              k,
              low=val_lo,
              high=val_hi,
              dtype=dtype,
              device=device,
          )
          weight = make_tensor(
              n,
              k,
              low=valq_lo,
              high=valq_hi,
              dtype=torch.int8,
              device=device,
          )
          scale = make_tensor(
              (n,),
              low=val_lo,
              high=val_hi,
              dtype=input.dtype,
              device=device,
          )
          bias = (
              make_tensor(
                  (n,),
                  low=val_lo,
                  high=val_hi,
                  dtype=input.dtype,
                  device=device,
              )
              if add_bias
              else None
          )
  
          input_ref = input.reshape(-1, input.shape[-1])
  
          # First, test plain multiplication.
          weight_ref = weight.T.to(input.dtype) * scale.view(1, n)
          weightq = (
              pack_int4_to_int8(weight.T)
              if dtypeq == torch.quint4x2
              else weight.T
          )
          output_ref = torch.mm(input_ref, weight_ref).reshape(
              *input.shape[:-1], n
          )
          output = torch.ops.aten._mixed_dtypes_linear(
              input,
              quantized_weight_reorder_for_mixed_dtypes_linear_cutlass(
                  weightq, dtypeq, transpose=False
              ),
              scale,
          )
          torch.testing.assert_close(
              output, output_ref, rtol=rtol, atol=atol
          )
  
          # Second, test the linear operator itself.
          weight_ref = weight.to(input.dtype) * scale.view(n, 1)
          weightq = (
              pack_int4_to_int8(weight)
              if dtypeq == torch.quint4x2
              else weight
          )
          bias_ref = bias.view(1, n) if add_bias else None
          output_ref = torch.nn.functional.linear(
              input_ref, weight_ref, bias=bias_ref
          ).reshape(*input.shape[:-1], n)
          if activation == "relu":
              relu = torch.nn.ReLU()
              output_ref = relu(output_ref)
          elif activation == "silu":
              silu = torch.nn.SiLU()
              output_ref = silu(output_ref)
          output = torch.ops.aten._mixed_dtypes_linear(
              input,
              quantized_weight_reorder_for_mixed_dtypes_linear_cutlass(
                  weightq, dtypeq, transpose=True
              ),
              scale,
              bias=bias,
              activation=activation,
          )
          torch.testing.assert_close(
              output, output_ref, rtol=rtol, atol=atol
          )
  
      dtypeqs = [torch.int8, torch.quint4x2]
      batch_shapes = [[], [2], [2, 1]]
      shapes = [
          [8, 64, 64],
          [8, 64, 128],
          [8, 128, 64],
          [8, 128, 128],
          [8, 128, 192],
          [8, 128, 256],
          [8, 256, 128],
          [8, 256, 384],
          [8, 384, 256],
      ]
      activations = [None, "relu", "silu"]
      rtol, atol = 1e-3, 1e-3
      if dtype == torch.bfloat16:
          rtol, atol = 1e-2, 1e-3
      for (
          dtypeq,
          batch_shape,
          (m, n, k),
          add_bias,
          activation,
      ) in product(
          dtypeqs, batch_shapes, shapes, (False, True), activations
      ):
          run_test(
              batch_shape,
              m,
              n,
              k,
              add_bias,
              activation,
              dtype,
              dtypeq,
              device,
              rtol,
              atol,
          )
  
imports: import unittest
  from itertools import product
  from functools import partial
  from typing import Optional
  import torch
  from torch.quantization._quantized_conversions import pack_int4_to_int8, quantized_weight_reorder_for_mixed_dtypes_linear_cutlass
  from torch.testing import make_tensor
  from torch.testing._internal.common_cuda import SM53OrLater, _get_torch_cuda_version
  from torch.testing._internal.common_device_type import dtypes, instantiate_device_type_tests, onlyCUDA, tol, toleranceOverride
  from torch.testing._internal.common_utils import IS_ARM64, IS_JETSON, IS_WINDOWS, parametrize, run_tests, skipIfRocmVersionLessThan, TEST_WITH_ROCM, skipIfRocm, TestCase
label_desc: Use image node_id 1 for calling the TestMixedDtypesLinearCuda obj's underlying member method code with example usage: obj.test_mixed_dtypes_linear(dtype, device) without return types