Concrete ML
WebsiteLibrariesProducts & ServicesDevelopersSupport
1.2
1.2
  • What is Concrete ML?
  • Getting Started
    • Installation
    • Key Concepts
    • Inference in the Cloud
    • Demos and Tutorials
  • Built-in Models
    • Linear Models
    • Tree-based Models
    • Neural Networks
    • Nearest Neighbors
    • Pandas
    • Built-in Model Examples
  • Deep Learning
    • Using Torch
    • Using ONNX
    • Step-by-step Guide
    • Deep Learning Examples
    • Debugging Models
    • Optimizing Inference
  • Deployment
    • Prediction with FHE
    • Hybrid models
    • Production Deployment
    • Serialization
  • Advanced topics
    • Quantization
    • Pruning
    • Compilation
    • Advanced Features
  • Developer Guide
    • Workflow
      • Set Up the Project
      • Set Up Docker
      • Documentation
      • Support and Issues
      • Contributing
    • Inner Workings
      • Importing ONNX
      • Quantization Tools
      • FHE Op-graph Design
      • External Libraries
    • API
      • concrete.ml.common.check_inputs.md
      • concrete.ml.common.debugging.custom_assert.md
      • concrete.ml.common.debugging.md
      • concrete.ml.common.md
      • concrete.ml.common.serialization.decoder.md
      • concrete.ml.common.serialization.dumpers.md
      • concrete.ml.common.serialization.encoder.md
      • concrete.ml.common.serialization.loaders.md
      • concrete.ml.common.serialization.md
      • concrete.ml.common.utils.md
      • concrete.ml.deployment.deploy_to_aws.md
      • concrete.ml.deployment.deploy_to_docker.md
      • concrete.ml.deployment.fhe_client_server.md
      • concrete.ml.deployment.md
      • concrete.ml.deployment.server.md
      • concrete.ml.deployment.utils.md
      • concrete.ml.onnx.convert.md
      • concrete.ml.onnx.md
      • concrete.ml.onnx.onnx_impl_utils.md
      • concrete.ml.onnx.onnx_model_manipulations.md
      • concrete.ml.onnx.onnx_utils.md
      • concrete.ml.onnx.ops_impl.md
      • concrete.ml.pytest.md
      • concrete.ml.pytest.torch_models.md
      • concrete.ml.pytest.utils.md
      • concrete.ml.quantization.base_quantized_op.md
      • concrete.ml.quantization.md
      • concrete.ml.quantization.post_training.md
      • concrete.ml.quantization.quantized_module.md
      • concrete.ml.quantization.quantized_module_passes.md
      • concrete.ml.quantization.quantized_ops.md
      • concrete.ml.quantization.quantizers.md
      • concrete.ml.search_parameters.md
      • concrete.ml.search_parameters.p_error_search.md
      • concrete.ml.sklearn.base.md
      • concrete.ml.sklearn.glm.md
      • concrete.ml.sklearn.linear_model.md
      • concrete.ml.sklearn.md
      • concrete.ml.sklearn.neighbors.md
      • concrete.ml.sklearn.qnn.md
      • concrete.ml.sklearn.qnn_module.md
      • concrete.ml.sklearn.rf.md
      • concrete.ml.sklearn.svm.md
      • concrete.ml.sklearn.tree.md
      • concrete.ml.sklearn.tree_to_numpy.md
      • concrete.ml.sklearn.xgb.md
      • concrete.ml.torch.compile.md
      • concrete.ml.torch.hybrid_model.md
      • concrete.ml.torch.md
      • concrete.ml.torch.numpy_module.md
      • concrete.ml.version.md
Powered by GitBook

Libraries

  • TFHE-rs
  • Concrete
  • Concrete ML
  • fhEVM

Developers

  • Blog
  • Documentation
  • Github
  • FHE resources

Company

  • About
  • Introduction to FHE
  • Media
  • Careers
On this page
  • module concrete.ml.quantization.quantized_module_passes
  • class PowerOfTwoScalingRoundPBSAdapter

Was this helpful?

Export as PDF
  1. Developer Guide
  2. API

concrete.ml.quantization.quantized_module_passes.md

Previousconcrete.ml.quantization.quantized_module.mdNextconcrete.ml.quantization.quantized_ops.md

Last updated 1 year ago

Was this helpful?

module concrete.ml.quantization.quantized_module_passes

Optimization passes for QuantizedModules.


class PowerOfTwoScalingRoundPBSAdapter

Detect neural network patterns that can be optimized with round PBS.

method __init__

__init__(qmodule: QuantizedModule) → None

property num_ignored_valid_patterns

Get the number of optimizable patterns that were ignored.

Patterns could be ignored since a number of rounding bits was set manually through the compilation function.

Returns:

  • result (int): number of patterns that could be optimized but were not


method compute_op_predecessors

compute_op_predecessors() → DefaultDict[Union[QuantizedOp, NoneType], List[Tuple[Union[QuantizedOp, NoneType], str]]]

Compute the predecessors for each QuantizedOp in a QuantizedModule.

Stores, for each quantized op, a list of quantized ops that produce its inputs. Currently only the first input of the operations is considered as it is, usually, the encrypted input.

Returns:

  • result (PredecessorsType): a dictionary containing a hierarchy of op predecessors


method detect_patterns

detect_patterns(
    predecessors: DefaultDict[Optional[QuantizedOp], List[Tuple[Optional[QuantizedOp], str]]]
) → Dict[QuantizedMixingOp, Tuple[List[Union[QuantizedOp, NoneType]], Union[QuantizedOp, NoneType]]]

Detect the patterns that can be optimized with roundPBS in the QuantizedModule.

Args:

  • predecessors (PredecessorsType): Module predecessor operation list

Returns:

  • result (PatternDict): list of optimizable patterns


method match_path_pattern

match_path_pattern(
    predecessors: DefaultDict[Optional[QuantizedOp], List[Tuple[Optional[QuantizedOp], str]]],
    nodes_in_path: List[Optional[QuantizedOp]],
    input_producer_of_path: Optional[QuantizedOp]
) → bool

Determine if a pattern has the structure that makes it viable for roundPBS.

Args:

  • predecessors (PredecessorsType): Module predecessor operation list

  • nodes_in_path (List[QuantizedOp]): list of quantized ops in the pattern

  • input_producer_of_path (Optional[QuantizedOp]): operation that produces the input

Returns:

  • result (bool): whether the pattern can be optimized


method process

process() → Dict[QuantizedMixingOp, Tuple[List[Union[QuantizedOp, NoneType]], Union[QuantizedOp, NoneType]]]

Analyze an ONNX graph and detect Gemm/Conv patterns that can use RoundPBS.

We want to detect a gemm/conv node whose weights/bias are Brevitas QAT, and whose input is produced by a Brevitas QAT node that is applied on the output of another Gemm/conv node. Optionally a Relu can be placed before this input quantization node.

Nothing will be done if rounding is already specified.

Returns:

  • result (PatternDict): a dictionary containing for each Conv/Gemm node for which round PBS can be applied based on power-of-two scaling factors


method process_patterns

process_patterns(
    valid_paths: Dict[QuantizedMixingOp, Tuple[List[Optional[QuantizedOp]], Optional[QuantizedOp]]]
) → Dict[QuantizedMixingOp, Tuple[List[Union[QuantizedOp, NoneType]], Union[QuantizedOp, NoneType]]]

Configure the rounding bits of roundPBS for the optimizable operations.

Args:

  • valid_paths (PatternDict): list of optimizable patterns

Returns:

  • result (PatternDict): list of patterns actually optimized with roundPBS