Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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, or check out this demo for a demonstration of how to train your own regalloc-for-performance policy.

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.
-DLLVM_INLINER_MODEL_PATH=/tmp/model

# Download the most recent compatible model
-DLLVM_INLINER_MODEL_PATH=download

Prerequisites

Currently, the assumptions for the system are:

  • Recent Ubuntu distro, e.g. 20.04
  • python 3.8.x/3.9.x/3.10.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:

Pipenv:

pip3 install pipenv

The actual dependencies:

pipenv sync --system

Note that the above command will only work from the root of the repository since it needs to have Pipfile.lock in the working directory at the time of execution.

If you plan on doing development work, make sure you grab the development and CI categories of packages as well:

pipenv sync --system --categories "dev-packages ci"

Optionally, to run tests (run_tests.sh), you also need:

sudo apt-get install virtualenv

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

Docs

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.

Release files for ml-compiler-opt 0.0.1.dev202311050007

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ml-compiler-opt 0.0.1.dev202311050007
File Size Uploaded
ml-compiler-opt-0.0.1.dev202311050007.tar.gz 147.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ml-compiler-opt 0.0.1.dev202311050007
File Interpreter ABI Platform
ml_compiler_opt-0.0.1.dev202311050007-py3-none-any.whl Python 3 none any Details

Total release size: 381.7 kB

Release files / ml-compiler-opt-0.0.1.dev202311050007.tar.gz

Download URL ml-compiler-opt-0.0.1.dev202311050007.tar.gz
Size 147.9 kB
Tags Source
SHA-256 checksum
How to use checksums
584ee54e6aee5ea39a9630bb90e21ff1a951fb06ad6ebcaaacc1bc6200d58a10
BLAKE2b-256 checksum
How to use checksums
17a963a6ee923f0c4689674b043533b1ad0f37f365bf032b6f7c5434068206d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release files / ml_compiler_opt-0.0.1.dev202311050007-py3-none-any.whl

Download URL ml_compiler_opt-0.0.1.dev202311050007-py3-none-any.whl
Size 233.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
067d000f915d083d2d5f33baf46f78ca3b7aa2508ab684941796f4fa00d47d9c
BLAKE2b-256 checksum
How to use checksums
01d55d1f46099d1551d34dbc509f0a1eb2cfab2898040e6c8f32dda82e189ba6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page