Proposal: migrate from TF to ONNX
meanrin opened this issue · comments
Propose to migrate model from TF to ONNX ML libraries
https://onnx.ai/ - "ONNX is an open format built to represent machine learning models."
This lib allows to run ml models on a different platforms, but not training them
Motivation:
- tf i a big library that allows to train models. credsweeper code only execute models, not training them
- tf is slow to load: on linux with Core-I9 it takes 1s, on windows os it might take up to 9s on the same hardware (details below)
- we have problems with tf changing interface or having vulnerabilities every few months
- current tf pypi weights "438.0 MB" ( https://pypi.org/project/tensorflow/#files )
- current onnx+onnxruntime pypi weights ~17MB in total (https://pypi.org/project/onnxruntime/#files, https://pypi.org/project/onnx/#files)
Migration from TF to ONNX usually require simple model conversion process: https://onnxruntime.ai/docs/tutorials/tf-get-started.html#converting-a-model
Other than that we would need to update code that directly utilize tensorflow functions
CredSweeper exec time with tf imports:
$ time python -m credsweeper --ml_validation --path tests/samples/password -j 1
real 0m4,487s
user 0m4,182s
sys 0m2,635s
And without them (--ml_validation
also removed due to it currently depends ion tf):
$ time python -m credsweeper --path tests/samples/password -j 1
real 0m0,440s
user 0m0,400s
sys 0m0,045s
Example import time for tf and onnx:
$ time python -c "import tensorflow"
real 0m1,198s
user 0m1,464s
sys 0m1,814s
$ time python -c "import onnx"
real 0m0,098s
user 0m0,219s
sys 0m0,707s