def _replace_qlinear_modules(
    model: torch.nn.Module, mapping: dict[str, tuple[Callable, Callable]], desc: str
) -> tuple[torch.nn.Module, bool]:
    """Make the model export compatible by replacing the quantized linear layers with 4-bit versions.

    :param model: the model to make export compatible. Only modified if model is quantized using a supported method.
    :param mapping: the mapping from quantization method to
        - function to get qlinear class from quantization config
        - function to get new class to replace qlinear modules with
    :param desc: description of the operation
    :return model: the modified model
    :return modified: whether the model was modified
    """
    quantization_method, quantization_config = get_quantization_info(model)

    if quantization_method not in mapping:
        return model, False

    # get the QuantLinear class to look for in the model
    qlinear_class = mapping[quantization_method][0](quantization_config)
    if qlinear_class is None:
        return model, False

    # search and replace
    logger.debug(desc)
    logger.debug("Quantization method: %s, QuantLinear class: %s", quantization_method, qlinear_class)
    num_modified = 0
    for name, module in model.named_modules():
        if isinstance(module, qlinear_class):
            new_module = mapping[quantization_method][1](module)
            set_attr(model, name, new_module)
            # quantized lora layers have another reference to the qlinear module
            parent = get_attr(model, ".".join(name.split(".")[:-1]))
            if parent is not module and getattr(parent, "quant_linear_module", None) is module:
                set_attr(parent, "quant_linear_module", new_module)
            num_modified += 1
    logger.debug("Modified %d modules", num_modified)

    return model, num_modified > 0
Make the model export compatible by replacing the quantized linear layers with 4-bit versions.

    :param model: the model to make export compatible. Only modified if model is quantized using a supported method.
    :param mapping: the mapping from quantization method to
        - function to get qlinear class from quantization config
        - function to get new class to replace qlinear modules with
    :param desc: description of the operation
    :return model: the modified model
    :return modified: whether the model was modified
    
olive/common/hf/quant.py