def from_float_and_qweight(
        cls,
        mod,
        qweight,
        dtype,
        scales,
        zero_points,
        bias=None,
        group_size=-1,
        g_idx=None,
        weight_format=WoqWeightFormat.PLAIN_FORMAT,
    ):
        r"""Create a weight-only quantized module from a float module and int4 weight

        Args:
            mod (Module): a float module, either produced by torch.ao.quantization
                          utilities or provided by the user
            qweight (Tensor): tensor in int32 dtype and contains actually int4 data
            bias (Tensor or None): bias for linear
            scales (Tensor): scales for qweight
            zero_points (Tensor): zero points for qweight
            group_size: Group size for weight quantization
            g_idx: Indices of groups for each input channel of weight. Generated by
                GPTQ with act-order.
            weight_format: Int4 weight format, plain format or GPTQ format or AWQ format
        """
        float_modules = [torch.nn.Linear]
        deepspeed_modules = may_import_deepspeed_modules()
        if deepspeed_modules is not None:
            float_modules.extend(deepspeed_modules)
        if any(issubclass(type(mod), float_module) for float_module in float_modules):
            float_modules.extend([type(mod)])

        assert type(mod) in float_modules, (
            "WeightOnlyQuantizedLinear.from_float only works for one of"
            + str([float_mod.__name__ for float_mod in float_modules])
            + f" or their subclasses, but found {type(mod)}"
        )
        assert hasattr(mod, "qconfig"), "Input float module must have qconfig defined"

        lowp_mode = 0
        act_quant_mode = 0
        cache_weight_for_large_batch = False
        if mod.qconfig is not None:
            if hasattr(mod.qconfig, "lowp_mode"):
                lowp_mode = mod.qconfig.lowp_mode
            if hasattr(mod.qconfig, "act_quant_mode"):
                act_quant_mode = mod.qconfig.act_quant_mode
            if hasattr(mod.qconfig, "cache_weight_for_large_batch"):
                cache_weight_for_large_batch = (
                    mod.qconfig.cache_weight_for_large_batch and lowp_mode in (2, 3)
                )

        w_dtype = qweight.dtype
        supported_qw_dtype = [
            torch.int32,
            torch.uint8,
            torch.int8,
            torch.quint4x2,
            torch.bfloat16,
            torch.float32,
            torch.float8_e4m3fn,
        ]
        assert (
            w_dtype in supported_qw_dtype
        ), "Data type of quantized weight should be in {}, but got: {}".format(
            supported_qw_dtype, w_dtype
        )
        if not hasattr(mod, "in_features"):
            mod.in_features = mod.weight.size()[1]
        if not hasattr(mod, "out_features"):
            mod.out_features = mod.weight.size()[0]

        if group_size < 0:
            scales = scales.squeeze()
            if zero_points is not None:
                zero_points = zero_points.squeeze()

        qlinear = cls._init_cls(
            mod,
            dtype,
            qweight,
            scales,
            zero_points,
            bias,
            g_idx,
            group_size,
            lowp_mode,
            act_quant_mode,
            cache_weight_for_large_batch,
            dtype == WoqWeightDtype.INT4,  # is_from_int4_weight
            weight_format,
        )
        del qweight
        mod.weight = torch.nn.Parameter()
        return qlinear
Create a weight-only quantized module from a float module and int4 weight

        Args:
            mod (Module): a float module, either produced by torch.ao.quantization
                          utilities or provided by the user
            qweight (Tensor): tensor in int32 dtype and contains actually int4 data
            bias (Tensor or None): bias for linear
            scales (Tensor): scales for qweight
            zero_points (Tensor): zero points for qweight
            group_size: Group size for weight quantization
            g_idx: Indices of groups for each input channel of weight. Generated by
                GPTQ with act-order.
            weight_format: Int4 weight format, plain format or GPTQ format or AWQ format
        
intel_extension_for_pytorch/nn/modules/weight_only_quantization.py