The distribution called itself torus-ml while shipping a package directory named concrete, so the name a user installs and the name they import disagreed — and most of the tree already said torus.ml, which could not resolve against src/concrete. Moved src/concrete to src/torus and pointed the include at it. The dependency was Zama's concrete-python from their index. It is torus-fhe from ours, which is what luxfhe/torus already ships: that frontend declares torus-fhe and ships a torus/fhe module, so every 'from torus.fhe' in this tree was already naming our compiler and only the dependency lagged. Two distributions share one namespace, which is the shape the upstream this forked from used and the reason the split works: torus-fhe gives torus.fhe, torus-ml gives torus.ml. Swept every other spelling — identifiers, enum members, workflow variables, filenames, notebooks. LICENSE and NOTICE keep the upstream attribution a fork owes; the figures carry the old name in JPEG metadata a text sweep cannot reach.
5.6 KiB
module torus.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 listnodes_in_path(List[QuantizedOp]): list of quantized ops in the patterninput_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