I am developing SkimXDP, a simple tool integrating the machine learning model created with scikit-learn into XDP, a technique to execute packet processing inside the Linux kernel. This tool aims to create a fast machine learning-based packet filter that works inside the kernel.
Since we cannot use floating points for XDP, I have to quantize the fitted classifier like linear models or neural networks.
I would like to hear your opinion about the best way to quantize the trained model.
My current approach is just scaling all parameters with the given precision like follows:
def dump_linear_model(
clf, feature_names, threshold=0, precision=4, indent_char=" "
):
code = indent_char
code += f"y += ({int(clf.intercept_[0] * (10**(precision)))}"
for c, n in zip(clf.coef_[0], feature_names):
code += f" + ({int(c * (10**precision))} * {n})"
code += f") > {int(threshold * (10 ** precision))};{endl}"
return code