chop.passes.module.transform.quantize

quantize_module_transform_pass

chop.passes.module.transforms.quantize.quantize_module_transform_pass(network, pass_args)[source]

Apply quantization transformation to the given nn.Module.

Parameters:
  • network (torch.nn.Module) – The input network to be transformed.

  • pass_args (dict, optional) – Additional arguments for the transformation.

Examples pass_args:

pass_args = {
    "by": "type", # quantize by type, name, or regex_name
    "default": {"config": {"name": None}}, # default config, this would be used for any node that does not have a specific config
    "linear": {
        "config": {
            "name": "integer",  # quantization scheme name supported are ["integer", "fixed" (equivalent to integer), "lutnet" (dev mode), "logicnets" (dev mode), "binary", "binary_residual", "ternary", "minifloat_ieee", "minifloat_denorm", "log", "block_fp", "block_minifloat", "block_log"]
            # data
            "data_in_width": 8,
            "data_in_frac_width": 4,
            # weight
            "weight_width": 8,
            "weight_frac_width": 4,
            # bias
            "bias_width": 8,
            "bias_frac_width": 4,
        }
    },
}
Returns:

The transformed torch.nn.Module.

Return type:

tuple

Raises:

ValueError – If the quantize “by” argument is unsupported.