Skip to content

I have a model that has two different inputs, can I quantize it so that each input will have different bias and scale? #800

@orena1

Description

@orena1

The model is in pytorch, this is how I use the conversion, but I don't think it is working.

# Set model to Eval
conversion_model = model.eval()

# function to generate representative dataset
def representative_dataset():
    for i in range(100):
        row = df.iloc[i]
        input_a, input_b = load_inputs(row)
        output = [input_a, input_b]
        yield output


# load single sample
row = df.iloc[i]
input_a, input_b = load_inputs(row)
input_a = torch.from_numpy(input_a)
input_b = torch.from_numpy(input_b)

tfl_converter_flags = {
    "optimizations": [tf.lite.Optimize.DEFAULT],
    "representative_dataset": representative_dataset,
    "target_spec.supported_ops": [tf.lite.OpsSet.TFLITE_BUILTINS_INT8],
    "inference_input_type": tf.int8,
    "inference_output_type": tf.int8,
    "target_spec.supported_types": [tf.int8],
    "_experimental_new_quantizer": True,
    # Force per-tensor quantization to be disabled
    # "_experimental_disable_per_tensor_quantization": True,
    # Enable more aggressive quantization analysis
    "_experimental_calibrate_quantization": True,
}


tfl_fullint_model = ai_edge_torch.convert(
    conversion_model, (input_a, input_b, ), _ai_edge_converter_flags=tfl_converter_flags
)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions