def gptq_quantize(
    model,
    weight_config=None,
    dataloader=None,
    nsamples=128,
    use_max_length=True,
    pad_max_length=2048,
    device=torch.device("cpu"),
    layer_wise=False,
    model_path=None,
):
    """Run weight-only quantization with weight configs.

    Args:
        model (torch.nn.Module): fp32 model to quantize
        weight_config (dict, optional): contains all info required by GPTQ. Defaults to {}.
            For example:
            weight_config={
                'layer1':
                {
                    'bits': 4,
                    'group_size': 32,
                    'sym': False,
                    'percdamp': .01,
                    'act_order': False
                }
                ...
            }
        dataloader (torch.utils.data.DataLoader): an iterable containing calibration datasets.
        nsamples (int): calibration samples' size.
        use_max_length (bool): whether to align calibration data to a fixed length.
        pad_max_length (int): whether to align calibration data to a fixed length.
        device: set to torch.device("cpu").
        layer_wise (bool): whether to do LWQ.
        model_path (str): path to register LWQ weight hooks.
    """
    assert isinstance(model, torch.nn.Module), "only support torch module"
    if layer_wise:
        assert (
            model_path is not None
        ), "model_path should not be None when use layer_wise mode"

    from .gptq import GPTQuantizer

    if weight_config is None:
        weight_config = {}

    gptq_quantizer = GPTQuantizer(
        model,
        weight_config,
        dataloader,
        nsamples,
        use_max_length,
        pad_max_length,
        device,
        layer_wise=layer_wise,
    )
    fp32_modified_model, gptq_config = gptq_quantizer.execute_quantization(
        model_path=model_path
    )
    logger.info("GPTQ quantizing done.")
    return fp32_modified_model, gptq_config
Run weight-only quantization with weight configs.

    Args:
        model (torch.nn.Module): fp32 model to quantize
        weight_config (dict, optional): contains all info required by GPTQ. Defaults to {}.
            For example:
            weight_config={
                'layer1':
                {
                    'bits': 4,
                    'group_size': 32,
                    'sym': False,
                    'percdamp': .01,
                    'act_order': False
                }
                ...
            }
        dataloader (torch.utils.data.DataLoader): an iterable containing calibration datasets.
        nsamples (int): calibration samples' size.
        use_max_length (bool): whether to align calibration data to a fixed length.
        pad_max_length (int): whether to align calibration data to a fixed length.
        device: set to torch.device("cpu").
        layer_wise (bool): whether to do LWQ.
        model_path (str): path to register LWQ weight hooks.
    
intel_extension_for_pytorch/quantization/_GPTQ/_gptq_utils.py