fhelium.testing
Numerical checks of encrypted functions against their plaintext reference.
compare runs a function on encryptions of Tensors and on the Tensors themselves and reports the error of every output. With :data:fhelium.knobs.shadow (FHELIUM_SHADOW=1), each Eager Ciphertext operator also evaluates its operation on the decrypted operands and records the error of its result; shadow_records returns the records and clear_shadow_records discards them. Shadow execution decrypts with the Engine's secret key and exists for development; compiled functions do not perform it.
The error of an output
Comparison
class View source
Comparison(outputs: tuple[OutputError, ...])The result of compare: one OutputError per output.
Attributes
| Name | Type | Default/value |
|---|---|---|
outputs | tuple[OutputError, ...] |
max_error
property
max_error: floatThe largest error over all outputs.
precision_bits
property
precision_bits: floatThe smallest precision over all outputs.
OutputError
class View source
OutputError(max_error: float, precision_bits: float)The error of one output: maximum absolute error and precision bits.
Attributes
| Name | Type | Default/value |
|---|---|---|
max_error | float | |
precision_bits | float |
ShadowRecord
class View source
ShadowRecord(operation: str, depth: int, scale: float, max_error: float, precision_bits: float)One operator evaluated under shadow execution.
max_error is the error of the decrypted result against the operation applied to the references of its operands; an operand without a reference contributes its decryption. depth and scale are those of the result after its pending steps.
Attributes
| Name | Type | Default/value |
|---|---|---|
operation | str | |
depth | int | |
scale | float | |
max_error | float | |
precision_bits | float |
clear_shadow_records
function View source
def clear_shadow_records() -> None: ...Discard the shadow-execution records.
compare
function View source
def compare(function: Callable[..., Any], *tensors: torch.Tensor, engine: Any) -> Comparison: ...Compare function on encryptions of tensors with function(*tensors).
Each Tensor of slots is encrypted with engine.encrypt_message on its device; function (an ordinary function or a compiled callable) receives the ciphertexts and its ciphertext outputs are decrypted. Real references are compared with the real part of the decryption. A reference with fewer elements, such as the 0-d result of Tensor.sum, is broadcast to the slot vector.
shadow_records
function View source
def shadow_records() -> Sequence[ShadowRecord]: ...The records of the operators evaluated under shadow execution, in order.