Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. C/C++
  3. m2cgen

m2cgen

MITPythonv0.10.0

Transpile trained machine learning models into native code (Java, C, Python, Go, etc.) with zero dependencies.

GitHubGitHub
3.0k stars260 forks0 contributors

What is m2cgen?

m2cgen is a Python library that transpiles trained machine learning models into native source code across multiple programming languages like Java, C, Python, and Go. It solves the problem of deploying models in environments where Python or heavy dependencies are not feasible, enabling integration into embedded systems, mobile applications, or performance-critical services.

Target Audience

Machine learning engineers and developers who need to deploy models in production environments without Python runtimes, such as in C++ applications, JavaScript web apps, or resource-constrained devices.

Value Proposition

Developers choose m2cgen for its zero-dependency output, extensive language support, and compatibility with popular ML frameworks, making model deployment flexible and portable across diverse tech stacks.

Overview

Transform ML models into a native code (Java, C, Python, Go, JavaScript, Visual Basic, C#, R, PowerShell, PHP, Dart, Haskell, Ruby, F#, Rust) with zero dependencies

Use Cases

Best For

  • Deploying scikit-learn models in C++ applications
  • Embedding XGBoost models into JavaScript web apps
  • Running LightGBM models on mobile devices without Python
  • Integrating ML models into Go microservices
  • Deploying models in serverless functions with strict dependency constraints
  • Converting trained models for use in embedded systems or IoT devices

Not Ideal For

  • Projects relying on TensorFlow or PyTorch neural networks, as m2cgen only supports traditional ML models from scikit-learn, XGBoost, and LightGBM.
  • Real-time systems where models are frequently retrained and require dynamic updates, since m2cgen necessitates manual code regeneration for each model change.
  • Applications demanding exact numerical reproducibility across all platforms, due to potential floating-point arithmetic differences in generated code.

Pros & Cons

Pros

Extensive Language Coverage

Supports 16+ programming languages including C, Java, Go, and JavaScript, enabling deployment in diverse environments from embedded systems to web apps, as listed in the README.

Broad Model Compatibility

Covers linear models, SVMs, decision trees, random forests, and gradient boosting from scikit-learn, XGBoost, and LightGBM, providing wide utility for common ML tasks.

Dependency-Free Output

Generates self-contained code with zero runtime dependencies, perfect for constrained environments like serverless functions or mobile devices, as emphasized in the key features.

API Consistency

Maintains alignment with original model APIs, such as decision_function for SVMs or predict_proba for trees, ensuring predictable behavior post-transpilation.

Cons

No Deep Learning Support

Excludes frameworks like TensorFlow and PyTorch, limiting its utility for modern neural network-based models, which are not mentioned in the supported models table.

Recursion Limitations

Large ensemble models can trigger recursion errors during code generation, requiring manual intervention to reduce estimators or increase recursion limits, as noted in the FAQ.

Numerical Discrepancies

Generated code may produce slightly different results due to float64-only handling and language-specific floating-point implementations, a known issue acknowledged in the FAQ.

Frequently Asked Questions

Quick Stats

Stars2,974
Forks260
Contributors0
Open Issues41
Last commit1 year ago
CreatedSince 2019

Tags

#haskell#transpiler#lightning#statistical-learning#csharp#model-deployment#zero-dependencies#lightgbm#java#c#python#xgboost#javascript#cross-platform#scikit-learn#go#machine-learning#code-generation#embedded-ai#dartlang

Built With

P
Python

Included in

Go169.1kMachine Learning72.2kC/C++70.6kFlutter59.5kRust56.6kJava47.5kJavaScript34.9kRuby14.1kElixir13.1kPowerShell5.4kHaskell3.3kDart2.5kF#1.4k
Auto-fetched 1 day ago

Related Projects

OpenCVOpenCV

Open Source Computer Vision Library

Stars87,213
Forks56,544
Last commit2 days ago
FAISSFAISS

A library for efficient similarity search and clustering of dense vectors.

Stars39,808
Forks4,347
Last commit1 day ago
XGBoostXGBoost

Scalable, Portable and Distributed Gradient Boosting (GBDT, GBRT or GBM) Library, for Python, R, Java, Scala, C++ and more. Runs on single machine, Hadoop, Spark, Dask, Flink and DataFlow

Stars28,301
Forks8,864
Last commit2 days ago
DarknetDarknet

Convolutional Neural Networks

Stars26,450
Forks21,131
Last commit2 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub