SPHINX studies how to reuse machine-learning performance predictors across MLIR dialects. A program in MLIR changes shape as it is lowered: the same neural network looks different in stablehlo, in linalg and in llvm. A predictor trained on one of these levels normally has to be retrained from scratch for the next one. We represent MLIR programs as ProGraML graphs, train a graph neural network on one dialect, and fine-tune it on another, so that most of what the model learned carries over.
This repository holds the code behind the paper Transfer Learning Across MLIR Dialects (CGO 2027): the tool that turns MLIR into graphs, the models, and the experiment scripts.
mlir_to_programlreads an MLIR module in any dialect and writes a ProGraML graph, with nodes for operations and values and edges for control, data and call relations.- A Gated Graph Neural Network (GGNN) reads the graph and predicts a property of the program. In the paper the programs are the networks of NAS-Bench-101 and NAS-Bench-201, and the properties are their training time and test accuracy.
- The model is first trained on a source dialect, where data is plentiful. It is then fine-tuned on a target dialect with a new vocabulary, keeping or freezing different parts of the network. The paper compares eight such configurations (FTE1 to FTE8) against training on the target from scratch.
mlir_to_programl/(C++): the graph generator.ml_experiments/programl_mlir_performance/(Python): the GGNN, the training and fine-tuning scripts, and the experiments of the paper.ml_experiments/programl_llvm_experiment/(Python): a reproduction of the liveness experiment of the ProGraML paper, on LLVM IR, as they ran it.ml_experiments/programl_mlir_liveness/(Python): the same experiment on MLIR, with graphs produced by our generator, to check that we get the same results over MLIR as over LLVM IR.sample_programs/: a few NAS-Bench programs instablehloandlinalg, with their graphs.dataset_generation/: the scripts that turn NAS-Bench-101 and NAS-Bench-201 into MLIR programs in each dialect. See its README.artifact/: Dockerfiles, pinned requirements and packaging scripts for the paper's artifact.
The two liveness experiments were sanity checks made before the work in the paper, and are not part of it.
ARTIFACT.md has the full instructions. In short, the datasets, training logs and model checkpoints are archived on Zenodo (https://doi.org/10.5281/zenodo.24175862), and the paper can be checked at three levels: rebuilding the tables and figures from the logs (under a minute, no GPU), re-evaluating the trained models on the test sets, and training again.
The image builds LLVM/MLIR and StableHLO from source at the versions we used, so nothing else has to be installed:
docker build -t sphinx-tool -f artifact/Dockerfile.tool .
docker run --rm sphinx-tool artifact/check_tool.shThe second command converts the sample programs and compares the result with the graphs in this repository.
You need:
- CMake 3.20 or newer and a C++20 compiler
- LLVM/MLIR (tested with LLVM 22)
- Protobuf and Abseil
- Optionally StableHLO, to read programs in the
stablehlodialect
The build looks for StableHLO in $HOME/stablehlo, and uses the LLVM build inside it ($HOME/stablehlo/llvm-build) when there is one. Otherwise it looks for LLVM in $HOME/llvm_install. If your LLVM is somewhere else, point CMake at it:
export CMAKE_PREFIX_PATH=/path/to/your/llvm/lib/cmake:$CMAKE_PREFIX_PATHThen build:
cd mlir_to_programl
mkdir build && cd build
cmake ..
make -j8Convert one file. Without an output path, the graph is written next to the input with the extension .ProgramGraph.pb:
./mlir_to_programl <input.mlir> [output.ProgramGraph.pb]Convert a whole dataset. The folder must contain an mlir/ subfolder; the graphs are written to graphs/ beside it, and errors go to conversion.log:
./mlir_to_programl <dataset_folder>For example, from mlir_to_programl/build:
./mlir_to_programl ../../sample_programs/linalgThe experiments need Python 3.12. A GPU is not required to look at results, but training without one is not practical.
python3 -m venv venv
source venv/bin/activate
pip install -r artifact/requirements.txtartifact/requirements.txt pins the versions used for the paper. ml_experiments/requirements.txt lists the same packages without versions, if you prefer newer ones.
The scripts live in ml_experiments/programl_mlir_performance/:
GGNN_train.pytrains a model on one dialect.finetune_experiment.pyfine-tunes a trained model on another dialect, in any of the eight configurations.pipeline_9010.pyandpipeline_9010_2.pyrun the whole sequence (source model, scratch baseline, fine-tuning) on NAS-Bench-201.incremental_linalg_experiment.pyandscarcity_sweep.pytrain on growing fractions of the data.reproduce/rebuilds the paper's tables and figures.
The benchmark, dialect and prediction target are chosen with environment variables. For example, to train on the stablehlo programs of NAS-Bench-101 and then fine-tune on linalg:
cd ml_experiments/programl_mlir_performance
export SPHINX_DATA=/path/to/extracted/dataset
SPHINX_DIALECT=stablehlo python GGNN_train.py
SPHINX_DIALECT=linalg SPHINX_BACKBONE=/path/to/best_tau_model.pt python finetune_experiment.pyARTIFACT.md lists every variable and the settings of each experiment, and shows how to add a new dialect or benchmark, with a worked example that runs on the sample programs.
sample_programs/ has 16 NAS-Bench-101 networks in stablehlo and the same 16 lowered to linalg, each with the graph the generator produces for it:
sample_programs/
stablehlo/
mlir/ model_<id>.mlir
programl/ model_<id>.ProgramGraph.pb
linalg/
mlir/ model_<id>.mlir
programl/ model_<id>.ProgramGraph.pb
labels.json training time and accuracy of the 16 networks
They are a quick way to try the generator and to see what the graphs look like.
If you use this work, please cite:
@inproceedings{coutinho2027transfer,
title = {Transfer Learning Across {MLIR} Dialects},
author = {Coutinho, Douglas Viana and Ros{\'a}rio, Vanderson and Pereira, Fernando M. Quint{\~a}o},
booktitle = {Proceedings of the IEEE/ACM International Symposium on Code Generation and Optimization (CGO)},
year = {2027}
}The code is released under the GPL-3.0 license (see LICENSE). The datasets are derived from NAS-Bench-101 (Apache-2.0) and NAS-Bench-201 (MIT) and are released under the same terms.
