Skip to main content

hetorch.passes.builtin.bootstrap

Bootstrapping insertion pass for noise budget management (Level-aware version).

This pass inserts bootstrapping operations to refresh ciphertexts when their remaining multiplicative depth (levels) falls below a threshold.

For CKKS: Tracks remaining levels in the modulus chain For other schemes: Tracks generic noise budget

Classes

BootstrappingInsertionPass(level_threshold: <class 'float'>, strategy: <class 'str'>, bootstrap_cost: <class 'float'>)

Insert bootstrapping operations to refresh ciphertexts.

For CKKS, this pass tracks the remaining multiplicative depth (levels) and inserts bootstrap operations when levels drop below threshold.

Typical CKKS parameters:

  • poly_modulus_degree (logN): 16 (65536 slots) or 15 (32768 slots)
  • Modulus chain: 36-38 levels of 60-bit primes
  • Bootstrap threshold: 15-16 levels remaining

Two strategies are supported:

  • Greedy: Insert bootstrap as soon as level threshold is reached
  • Optimal: Use dynamic programming to find optimal bootstrap placement

Attributes: level_threshold: Remaining level threshold for bootstrapping strategy: Placement strategy ("greedy" or "optimal") bootstrap_cost: Relative cost of bootstrapping (for optimal strategy)

Methods:

__init__(self, level_threshold: float = 15.0, strategy: str = 'greedy', bootstrap_cost: float = 100.0)

Initialize bootstrapping insertion pass.

Args: level_threshold: Remaining level threshold for bootstrapping For CKKS: typically 15-16 levels (default: 15) For other schemes: noise budget in bits strategy: Placement strategy - "greedy" or "optimal" (default: "greedy") bootstrap_cost: Relative cost of bootstrapping operation (default: 100.0)

Raises: ValueError: If strategy is not "greedy" or "optimal"

analyze_cost(self, graph_module: torch.fx.graph_module.GraphModule, context: hetorch.compiler.context.CompilationContext) -\> hetorch.backend.cost_model.CostAnalysis

Analyze cost impact of this pass

Args: graph_module: Graph module to analyze context: Compilation context

Returns: Cost analysis result

transform(self, graph_module: torch.fx.graph_module.GraphModule, context: hetorch.compiler.context.CompilationContext) -\> torch.fx.graph_module.GraphModule

Insert bootstrapping operations based on level tracking.

Args: graph_module: Input graph module context: Compilation context

Returns: Transformed graph module with bootstrap operations

validate(self, graph_module: torch.fx.graph_module.GraphModule, context: hetorch.compiler.context.CompilationContext) -\> bool

Validate that rescaling has been inserted (required for CKKS).

Args: graph_module: Graph module to validate context: Compilation context

Returns: True if validation passes