Repository: microsoft/onnxruntime
File: onnxruntime/python/tools/quantization/quantize.py (Python)

Code before:
        A StaticQuantConfig object
    """
    q16_types = {QuantType.QInt16, QuantType.QUInt16}
    q4_types = {QuantType.QInt4, QuantType.QUInt4}
    op_types_to_exclude = {"Cast", "DequantizeLinear", "QuantizeLinear"}

    model = (
        model_input
        if isinstance(model_input, onnx.ModelProto)
        else onnx.load_model(model_input, load_external_data=False)
    )

    op_types = set()
    model_has_external_data = False
    overrides_helper = TensorQuantOverridesHelper(
        copy.deepcopy(tensor_quant_overrides) if tensor_quant_overrides else {}
    )

    # check if the model has external data.
    for initializer in model.graph.initializer:
        if onnx.external_data_helper.uses_external_data(initializer):
            model_has_external_data = True

    op_types_to_quantize_set = set(op_types_to_quantize) if op_types_to_quantize else None
    nodes_to_exclude_set = (
        set(nodes_to_exclude) if nodes_to_exclude is not None and isinstance(nodes_to_exclude, list) else {}
    )

    # Iterate through nodes to get all operator types in the model and
    # call user's function to filter out nodes from quantization.
    for node in model.graph.node:
        if op_types_to_quantize_set and node.op_type not in op_types_to_quantize_set:
            continue
        if node.name in nodes_to_exclude_set:
            continue
        if nodes_to_exclude is not None and callable(nodes_to_exclude) and nodes_to_exclude(model, node):
            nodes_to_exclude_set.add(node.name)
        else:
            op_types.add(node.op_type)

    final_extra_options = {
        "MinimumRealRange": min_real_range,
        "QDQKeepRemovableActivations": keep_removable_activations,
        "ActivationSymmetric": activation_symmetric,
        "WeightSymmetric": weight_symmetric,
        "ForceQuantizeNoInputCheck": True,
        "TensorQuantOverrides": overrides_helper.get_dict(),
    }

    # Pass along known calibration options
    if calibrate_args:

Review comment (suggestion):
```suggestion
        set(nodes_to_exclude) if nodes_to_exclude is not None and isinstance(nodes_to_exclude, list) else set()
```

Code after:
        A StaticQuantConfig object
    """
    q16_types = {QuantType.QInt16, QuantType.QUInt16}
    q4_types = {QuantType.QInt4, QuantType.QUInt4}
    op_types_to_exclude = {"Cast", "DequantizeLinear", "QuantizeLinear"}

    model = (
        model_input
        if isinstance(model_input, onnx.ModelProto)
        else onnx.load_model(model_input, load_external_data=False)
    )

    op_types = set()
    model_has_external_data = False
    overrides_helper = TensorQuantOverridesHelper(
        copy.deepcopy(tensor_quant_overrides) if tensor_quant_overrides else {}
    )

    # check if the model has external data.
    for initializer in model.graph.initializer:
        if onnx.external_data_helper.uses_external_data(initializer):
            model_has_external_data = True

    op_types_to_quantize_set = set(op_types_to_quantize) if op_types_to_quantize else None
    nodes_to_exclude_set = set(nodes_to_exclude) if isinstance(nodes_to_exclude, list) else set()

    # Iterate through nodes to get all operator types in the model and
    # call user's function to filter out nodes from quantization.
    for node in model.graph.node:
        if op_types_to_quantize_set and node.op_type not in op_types_to_quantize_set:
            continue
        if node.name in nodes_to_exclude_set:
            continue
        if callable(nodes_to_exclude) and nodes_to_exclude(model, node):
            nodes_to_exclude_set.add(node.name)
        else:
            op_types.add(node.op_type)

    final_extra_options = {
        "MinimumRealRange": min_real_range,
        "QDQKeepRemovableActivations": keep_removable_activations,
        "ActivationSymmetric": activation_symmetric,
        "WeightSymmetric": weight_symmetric,
        "ForceQuantizeNoInputCheck": True,
        "TensorQuantOverrides": overrides_helper.get_dict(),
    }

    # Pass along known calibration options
    if calibrate_args:
        calib_extra_options_keys = [
            ("symmetric", "CalibTensorRangeSymmetric"),