Cost estimation¶
concrete_fhe_toolkit.ml.estimation ¶
Static cost estimation for FHE models — before compiling anything.
Answers "how expensive will this model be?" from the model's public structure and the feature bounds alone: it counts the encrypted operations the circuit will contain (comparisons, table lookups, multiplications) and the widest lookup domain, then maps them to the same qualitative levels the lookup guardrails use. Estimates are structural, not wall-clock promises — use them to compare models and to catch circuits that will not fit before paying for a compile.
ModelCostEstimate
dataclass
¶
Structural cost summary for one model at given feature bounds.
Attributes:
| Name | Type | Description |
|---|---|---|
comparisons |
int
|
Encrypted comparison operations (each becomes a TLU). |
lookups |
int
|
Explicit table lookups (argmin/argmax encodings included). |
multiplications |
int
|
Encrypted multiplications. |
max_lookup_input_bits |
int
|
Widest lookup-domain bit width in the circuit — the main driver of key size and runtime. |
level |
str
|
|
notes |
List[str]
|
Human-readable advisories (for example when an argmin encoding approaches Concrete's practical bit-width limits). |
Source code in src/concrete_fhe_toolkit/ml/estimation.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
estimate_model_cost ¶
estimate_model_cost(model: Any, *, min_feature: int, max_feature: int) -> ModelCostEstimate
[Client-Side Helper] Estimate a model's encrypted-operation footprint before compiling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Any toolkit model instance ( |
required |
min_feature
|
int
|
Inclusive lower bound of the encrypted features the model will see. |
required |
max_feature
|
int
|
Inclusive upper bound of those features. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
ModelCostEstimate
|
class: |
ModelCostEstimate
|
qualitative level. |
Example
from concrete_fhe_toolkit.ml import FHEKNN
from concrete_fhe_toolkit.ml.estimation import estimate_model_cost
model = FHEKNN(X_train, y_train, k=3)
report = estimate_model_cost(model, min_feature=0, max_feature=15)
print(report.level, report.max_lookup_input_bits, *report.notes)
Source code in src/concrete_fhe_toolkit/ml/estimation.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |