Clone this repo:
  1. 18c0f77 Fixed typo in by Mircea Trofin · 4 days ago main upstream/main
  2. 8b0d885 add the support for dumping best trajectories during training (#153) by Yundi Qian · 5 days ago upstream/fix
  3. 12c239b Move `buffered_scheduler` out of local (#157) by Mircea Trofin · 5 days ago
  4. a3dbc19 Have the worker pool context produce a pool object (#154) by Mircea Trofin · 5 days ago
  5. 9668e36 Update the Dockerfiles to use a base image supported by Fuchsia infra. (#156) by Zero Omega · 6 days ago

Infrastructure for MLGO --- a Machine Learning Guided Compiler Optimizations Framework.

MLGO is a framework for integrating ML techniques systematically in LLVM. It replaces human-crafted optimization heuristics in LLVM with machine learned models. The MLGO framework currently supports two optimizations:

  1. inlining-for-size(LLVM RFC);
  2. register-allocation-for-performance(LLVM RFC)

The compiler components are both available in the main LLVM repository. This repository contains the training infrastructure and related tools for MLGO.

We currently use two different ML algorithms: Policy Gradient and Evolution Strategies to train policies. Currently, this repository only support Policy Gradient training. The release of Evolution Strategies training is on our roadmap.

Check out this demo for an end-to-end demonstration of how to train your own inlining-for-size policy from the scratch with Policy Gradient.

For more details about MLGO, please refer to our paper MLGO: a Machine Learning Guided Compiler Optimizations Framework.

For more details about how to contribute to the project, please refer to contributions.

Pretrained models

We occasionally release pretrained models that may be used as-is with LLVM. Models are released as github releases, and are named as [task]-[major-version].[minor-version].The versions are semantic: the major version corresponds to breaking changes on the LLVM/compiler side, and the minor version corresponds to model updates that are independent of the compiler.

When building LLVM, there is a flag -DLLVM_INLINER_MODEL_PATH which you may set to the path to your inlining model. If the path is set to download, then cmake will download the most recent (compatible) model from github to use. Other values for the flag could be:

# Model is in /tmp/model, i.e. there is a file /tmp/model/saved_model.pb along
# with the rest of the tensorflow saved_model files produced from training.

# Download the most recent compatible model


Currently, the assumption for the is:

  • Recent Ubuntu distro, e.g. 20.04
  • python 3.8.x
  • for local training, which is currently the only supported mode, we recommend a high-performance workstation (e.g. 96 hardware threads).

Training assumes a clang build with ML ‘development-mode’. Please refer to:

The model training - specific prerequisites are:

pip3 install --user -r requirements.txt

Where requirements.txt is provided in the root of the repository.

Optionally, to run tests (, you also need:

sudo apt-get install virtualenv

Note that the same tensorflow package is also needed for building the ‘release’ mode for LLVM.


An end-to-end demo using Fuchsia as a codebase from which we extract a corpus and train a model.

How to add a feature guide. Extensibility model.