lgbm2vhdl
This project aims to create a tool for automated conversion of the LightGBM library model to the digital circuit description in VHDL. The input to this conversion is an arbitrary model obtained by the LightGBM library. The output is a VHDL code that can be synthesized and loaded, for example, on configurable chips with FPGA technology.
Simulations for the ModelSIM environment are also prepared to test the resulting VHDL code. Within these simulations, a testbench file including additional supporting scripts for the ModelSIM environment is created, and it is automatically verified that for a given input test vector, the VHDL architecture gives the same prediction results as the original LightGBM model executed in Python.
Installation
Install the package from pip with:
pip install lgbm2vhdl
Usage Example
import os
from lgbm2vhdl.LGBM2VHDL import LGBM2VHDL
# Example model and quantization definition
model_filename = os.path.join("data", "example_model_class3.txt")
quantization_filename = os.path.join("data", "example_model_class3-quantization.csv")
# Model loading
lvg = LGBM2VHDL(model_filename, quantization_filename, working_dir="./tmp")
# Generation of VHDL files
lvg.generate_vhdl(architecture="mem-c")
# Running simulation
lvg.run_simulation(architecture="mem-c")
Definition of quantization
Some of the input features may be in the form of decimal numbers, usually in floating-point format (exponent and mantissa). Processing this type of number is very computationally resource intensive in FPGA chips, and therefore, these numbers need to be converted to a fixed-point format where a specific number of bits is always specified for the integer and decimal parts of the number. For each such feature, it is necessary to specify the parameters for floating to fixed point conversion. This type of conversion must be performed not only for the input features, but also for the model output values representing the degree of membership (called log-odds ratio) of the input object to the selected class. Therefore, an important input of the conversion is also a CSV file with a definition for quantizing the input features and the output values of the model.
Format of quantization CSV file
For each input feature it is necessary to enter one line in the CSV file containing information about the number format that will be used at the circuit implementation level. In addition, the CSV file will contain one more line defining the number format for the model output values (log-odds ratio). Thus, in total, the file must contain a number of lines corresponding to the number of features + 1.
The format of each line is identical and consists of 5 items:
- Name of the feature
- Integer/Decimal number (True if a number is integer)
- Signed/Unsigned number (True if a number is signed)
- Number of bits for integer part of a number
- Number of bits for decimal part of a number (zero in case of integer numbers)
Architecture specification
The lgbm2vhdl module supports up to four different types of resulting VHDL circuit architectures.
- mem-c - It represents the standard Memory Centric architecture for implementing decision trees and Gradient Boosting models [1]).
- mem-c_ord - Similar to mem-c, but the values of the input features and the thresholds (within instructions) are replaced by the rank order within the sorted sequence of all thresholds used in the model.
- mem-c_mem - Similar to mem-c, but process element multiplexers are replaced by a memory block into which the input features are sequentially loaded.
- mem-c_ord_mem - It combines both the mem-c_ord and mem-c_ord_mem optimizations described above.
Acknowledgements
This project was supported by the Ministry of the Interior of the Czech Republic, grant No. VJ02010024: Flow-Based Encrypted Traffic Analysis.
References
[1] Alcolea, A.; Resano, J. FPGA Accelerator for Gradient Boosting Decision Trees. Electronics 2021, 10, 314. https://doi.org/10.3390/electronics10030314.
Metadata
Release files for lgbm2vhdl 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lgbm2vhdl-0.0.2.tar.gz | 36.8 kB | Without provenance | Details for lgbm2vhdl-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lgbm2vhdl-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for lgbm2vhdl-0.0.2-py3-none-any.whl |
Total release size: 95.6 kB
Release files / lgbm2vhdl-0.0.2.tar.gz
| Download URL | lgbm2vhdl-0.0.2.tar.gz |
|---|---|
| Size | 36.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
53fd894b2b2bacffceeb8e96af318f036e4083b39b501632803bfccc40b27285
|
|
BLAKE2b-256 checksum How to use checksums |
82d5aa7656be3aedaab71e3434e097b45811f8d1d32591a9a56fdc9fafd109d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.25.1 requests-toolbelt/1.0.0 urllib3/1.26.6 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.6.8
|
Release files / lgbm2vhdl-0.0.2-py3-none-any.whl
| Download URL | lgbm2vhdl-0.0.2-py3-none-any.whl |
|---|---|
| Size | 58.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f51af48703eb82736f24c2be51d52bbfe9516fd452473a43c07bd3d8971c9c83
|
|
BLAKE2b-256 checksum How to use checksums |
af97d43fc26e0020c75223436cbd7a7e454a8ef345d0b36e5f5571bb771bf5ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.25.1 requests-toolbelt/1.0.0 urllib3/1.26.6 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.3 CPython/3.6.8
|
Security for lgbm2vhdl 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.