def get_static_run_config(
        self, model: ONNXModelHandler, config: type[BasePassConfig], run_config: dict, ort_less_than_1_21: bool
    ) -> dict:
        """Prepare the run config for static quantization."""
        dataloader = get_calibration_dataloader(config, model.model_path, model.io_config, config.calibration_providers)
        if config.quant_format != "QDQ" or not config.prepare_qdq_config:
            run_config.update(
                {
                    "calibration_data_reader": dataloader,
                    "use_external_data_format": True,
                    "weight_type": quant_type_from_precision(run_config["precision"]),
                    "activation_type": quant_type_from_precision(run_config["activation_type"]),
                }
            )
            run_config.pop("precision", None)
            return run_config

        is_qnn_ep = self.accelerator_spec.execution_provider == "QNNExecutionProvider"

        if is_qnn_ep:
            from onnxruntime.quantization.execution_providers.qnn import get_qnn_qdq_config as get_qdq_config
        else:
            if ort_less_than_1_21:
                raise ValueError("prepare_qdq_config is only supported for onnxruntime>=1.21.0.")
            from onnxruntime.quantization.quantize import get_qdq_config

        get_qdq_config_kwargs = {
            "model_input": model.model_path,
            "calibration_data_reader": dataloader,
            "weight_type": quant_type_from_precision(run_config["precision"]),
            "activation_type": quant_type_from_precision(run_config["activation_type"]),
            "calibrate_method": run_config["calibrate_method"],
            "per_channel": run_config["per_channel"],
        }
        if not ort_less_than_1_21:
            # only available in onnxruntime>=1.21.0 for prepare_qnn_config
            for key in ["calibration_providers", "op_types_to_quantize", "nodes_to_exclude"]:
                get_qdq_config_kwargs[key] = run_config[key]
        # put the exposed extra options in the get_qdq_config_kwargs
        extra_options = deepcopy(run_config["extra_options"])
        for key, (qdq_key, _) in _param_extra_options_mapping.items():
            if key in extra_options:
                get_qdq_config_kwargs[qdq_key] = extra_options[key]
                # remove the key from extra_options
                extra_options.pop(key, None)
        if extra_options:
            get_qdq_config_kwargs["extra_options"] = extra_options
        # tensor_quant_overrides is init_overrides in qnn
        if is_qnn_ep:
            if "tensor_quant_overrides" in get_qdq_config_kwargs:
                get_qdq_config_kwargs["init_overrides"] = get_qdq_config_kwargs.pop("tensor_quant_overrides")
            elif init_overrides := _get_qnn_init_overrides(model, config):
                get_qdq_config_kwargs["init_overrides"] = init_overrides
            if "min_real_range" in get_qdq_config_kwargs:
                # min_real_range is not supported in QNN EP which enforces 1e-4
                get_qdq_config_kwargs.pop("min_real_range")

        # get the qdq config
        qdq_config = get_qdq_config(**get_qdq_config_kwargs)

        # override the run_config with qdq_config
        new_run_config = {k: v for k, v in inspect.getmembers(qdq_config) if not k.startswith("_")}
        # always run with use_external_data_format
        new_run_config["use_external_data_format"] = True
        if ort_less_than_1_21:
            # only available in onnxruntime>=1.21.0 for prepare_qnn_config
            if run_config["nodes_to_exclude"]:
                new_run_config["nodes_to_exclude"].extend(run_config["nodes_to_exclude"])
            if config.op_types_to_quantize:
                new_run_config["op_types_to_quantize"] = config.op_types_to_quantize
            elif config.op_types_to_exclude:
                # op_types_to_quantize takes precedence over op_types_to_exclude
                new_run_config["op_types_to_quantize"] = list(
                    set(new_run_config["op_types_to_quantize"]) - set(config.op_types_to_exclude)
                )

        return new_run_config
Prepare the run config for static quantization.
olive/passes/onnx/quantization.py