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.
12 KiB
module torus.ml.sklearn.qnn
Scikit-learn interface for fully-connected quantized neural networks.
Global Variables
- QNN_AUTO_KWARGS
- OPTIONAL_MODULE_PARAMS
- ATTRIBUTE_PREFIXES
class NeuralNetRegressor
A Fully-Connected Neural Network regressor with FHE.
This class wraps a quantized neural network implemented using Torch tools as a scikit-learn estimator. The skorch package allows to handle training and scikit-learn compatibility, and adds quantization as well as compilation functionalities. The neural network implemented by this class is a multi layer fully connected network trained with Quantization Aware Training (QAT).
Inputs and targets that are float64 will be casted to float32 before training as Torch does not handle float64 types properly. Thus should not have a significant impact on the model's performances. An error is raised if these values are not floating points.
method __init__
__init__(
criterion=<class 'torch.nn.modules.loss.MSELoss'>,
optimizer=<class 'torch.optim.adam.Adam'>,
lr=0.01,
max_epochs=10,
batch_size=128,
iterator_train=<class 'torch.utils.data.dataloader.DataLoader'>,
iterator_valid=<class 'torch.utils.data.dataloader.DataLoader'>,
dataset=<class 'skorch.dataset.Dataset'>,
train_split=None,
callbacks=None,
predict_nonlinearity='auto',
warm_start=False,
verbose=1,
device='cpu',
**kwargs
)
property base_module
Get the Torch module.
Returns:
SparseQuantNeuralNetwork: The fitted underlying module.
property fhe_circuit
property history
property input_quantizers
Get the input quantizers.
Returns:
List[UniformQuantizer]: The input quantizers.
property is_compiled
Indicate if the model is compiled.
Returns:
bool: If the model is compiled.
property is_fitted
Indicate if the model is fitted.
Returns:
bool: If the model is fitted.
property onnx_model
Get the ONNX model.
Is None if the model is not fitted.
Returns:
onnx.ModelProto: The ONNX model.
property output_quantizers
Get the output quantizers.
Returns:
List[UniformQuantizer]: The output quantizers.
method dump_dict
dump_dict() → Dict[str, Any]
method fit
fit(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
y: Union[ndarray, Tensor, ForwardRef('DataFrame'), ForwardRef('Series'), List],
*args,
**kwargs
)
method fit_benchmark
fit_benchmark(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
y: Union[ndarray, Tensor, ForwardRef('DataFrame'), ForwardRef('Series'), List],
*args,
**kwargs
)
classmethod load_dict
load_dict(metadata: Dict)
method predict
predict(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
fhe: Union[FheMode, str] = <FheMode.DISABLE: 'disable'>
) → ndarray
method predict_proba
predict_proba(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
fhe: Union[FheMode, str] = <FheMode.DISABLE: 'disable'>
) → ndarray
class NeuralNetClassifier
A Fully-Connected Neural Network classifier with FHE.
This class wraps a quantized neural network implemented using Torch tools as a scikit-learn estimator. The skorch package allows to handle training and scikit-learn compatibility, and adds quantization as well as compilation functionalities. The neural network implemented by this class is a multi layer fully connected network trained with Quantization Aware Training (QAT).
Inputs that are float64 will be casted to float32 before training as Torch does not handle float64 types properly. Thus should not have a significant impact on the model's performances. If the targets are integers of lower bit-width, they will be safely casted to int64. Else, an error is raised.
method __init__
__init__(
criterion=<class 'torch.nn.modules.loss.CrossEntropyLoss'>,
optimizer=<class 'torch.optim.adam.Adam'>,
classes=None,
lr=0.01,
max_epochs=10,
batch_size=128,
iterator_train=<class 'torch.utils.data.dataloader.DataLoader'>,
iterator_valid=<class 'torch.utils.data.dataloader.DataLoader'>,
dataset=<class 'skorch.dataset.Dataset'>,
train_split=None,
callbacks=None,
predict_nonlinearity='auto',
warm_start=False,
verbose=1,
device='cpu',
**kwargs
)
property base_module
Get the Torch module.
Returns:
SparseQuantNeuralNetwork: The fitted underlying module.
property classes_
property fhe_circuit
property history
property input_quantizers
Get the input quantizers.
Returns:
List[UniformQuantizer]: The input quantizers.
property is_compiled
Indicate if the model is compiled.
Returns:
bool: If the model is compiled.
property is_fitted
Indicate if the model is fitted.
Returns:
bool: If the model is fitted.
property n_classes_
Get the model's number of classes.
Using this attribute is deprecated.
Returns:
int: The model's number of classes.
property onnx_model
Get the ONNX model.
Is None if the model is not fitted.
Returns:
onnx.ModelProto: The ONNX model.
property output_quantizers
Get the output quantizers.
Returns:
List[UniformQuantizer]: The output quantizers.
property target_classes_
Get the model's classes.
Using this attribute is deprecated.
Returns:
Optional[numpy.ndarray]: The model's classes.
method dump_dict
dump_dict() → Dict[str, Any]
method fit
fit(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
y: Union[ndarray, Tensor, ForwardRef('DataFrame'), ForwardRef('Series'), List],
*args,
**kwargs
)
method fit_benchmark
fit_benchmark(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
y: Union[ndarray, Tensor, ForwardRef('DataFrame'), ForwardRef('Series'), List],
*args,
**kwargs
)
classmethod load_dict
load_dict(metadata: Dict)
method predict
predict(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
fhe: Union[FheMode, str] = <FheMode.DISABLE: 'disable'>
) → ndarray
method predict_proba
predict_proba(
X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
fhe: Union[FheMode, str] = <FheMode.DISABLE: 'disable'>
) → ndarray