GithubHelp home page GithubHelp logo

mllite / ml2cpp Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 1.0 92.51 MB

Machine Learning Models Deployment using C++ Code Generation

License: BSD 3-Clause "New" or "Revised" License

C++ 99.95% SWIG 0.05% Makefile 0.01%
scikit-learn xgboost lightgbm deployment pytorch keras caret edge stm32 esp32

ml2cpp's People

Contributors

antoinecarme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ssh352

ml2cpp's Issues

Experiments with Small Devices

ml2cpp, as it is now, allows converting any ML model to a C++ code for inference purposes.

This code is however not yet optimized to run on small devices : these devices may have low CPU speed, low memory, low-power, no FPU, no real OS. ml2cpp Jupyter notebooks were run and inference was tested on a sparc64 or x86-64 server with gigabytes of memory and running full-featured g++ compiler.

We need:

  1. get some hardware/micro-controller : STM32, ESP32 and K210 (riscv-64) at least.
  2. Check that the generated code can be compiled with the respective gcc versions (C++-17 support, exceptions, RTTI are not always available).
  3. check the capacities of these devices (CPU + memory)
  4. Check floating point issues : is there an FPU? half-precision floats (float16), bfloat16, ...
  5. get an emulator for each device (qemu-???). use it for automated tests.

Priority 1 : Getting at least one of these devices running all these steps (feasibility). choose the one with less constraints (K210 can run a small linux)

The goal is to be able to run the model on the bare metal. No arduino. No MicroPython.

Using STM32, ESP32 or K210 is here only for tuning purposes. Their only added value is to provide a test envoironment so that C++ code will be incrementally adapted in a real-world case.

ml2cpp step 8 : Ensemble Models

ensemble.AdaBoostClassifier
ensemble.AdaBoostRegressor
ensemble.BaggingClassifier
ensemble.BaggingRegressor
ensemble.ExtraTreesClassifier
ensemble.ExtraTreesRegressor
ensemble.GradientBoostingClassifier
ensemble.GradientBoostingRegressor
ensemble.IsolationForest
ensemble.RandomForestClassifier
ensemble.RandomForestRegressor
...

Follow the six steps described in #1

ml2cpp step 3 : Linear Models

Basic support for linear models as a first working case for prototyping and C++ design.

RidgeClassifier + Ridge Regressor

ml2cpp step 2 : C++ code design

Need to have a complete specification for the following :

  1. Test datasets (CSV file => C++ std::map)
  2. Classification/Regression/Transformation models : C++ functions used to compute the scores
  3. Classification/Regression/Transformation models : input/output datasets layouts

This spec should evolve when more and more models/features are added.

ml2cpp step 1 : Prototyping

Need to prototype something that works, even partially automated or hardcoded, to compute the scores of a pickled classification model using only C++ code.

Add a Specific Implementation for RISC-V ISA AI Extensions

ML2CPP can generate specific C++ code with RISC-V extensions allowing all scikit-learn, pytorch, caret ML models to be deployable natively on this platform.

RISC-V extensions have the advantage to be non-proprietary.

This is a place holder for following the recent efforts on designing RISC-V specific extensions for AI/ML.

No public hardware is available yet.

Sifive Intelligence X280 CPU is an interesting start point. https://www.sifive.com/blog/introduction-to-the-sifive-intelligence-x280

ml2cpp step 4 : Decision Tree Models

Basic support for decision tree models as a working case for prototyping and C++ design.

DecisionTreeClassifier + DecisionTreeRegressor

Follow the six steps described in #1

Prepare a test framework for ml2cpp

We need a way to perform the same checks done for scikit-learn python models for assessing the quality of C++ code generation for machine learning models.

Need (all the code in python):

1. generate/train a model on a dataset (training = python data.frame)

2. predict the classes of a test dataset ( test = python data.frame df_out)

3. generate a C++ code for the model (use the sklearn2sql_heroku for example)

4. transfer the test dataset to a local CSV file.

5. Compile and execute the model C++ generated in point 3 ( => predicted CSV file => data.frame cpp_df_out)

6. compare the two dataframes (df_out and cpp_df_out). A simple merge is OK. The prediction columns should be identical.

In a first time, the goal is just to put in place the framework to be used as a template for coming tests. An xgboost model is OK for this task.

deliverable : A jupyter notebook with all the process.

Experiments with Small Devices : Floating Point Issues

See #25

ml2cp uses float64 in all computations by default. This is not always a limitation.

For each device, Check the availability of major floating point types (float64, float32, float16, bfloat16, ...)

  1. Allow using float32, float16 or bfloat16 when available.
  2. Allow using hardware FPU when available.
  3. Adapt the code, when needed, according to floating point capabilities.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.