Große Sprachmodelle für Compiler-Optimierung
Large Language Models for Compiler Optimization
September 11, 2023
Autoren: Chris Cummins, Volker Seeker, Dejan Grubisic, Mostafa Elhoushi, Youwei Liang, Baptiste Roziere, Jonas Gehring, Fabian Gloeckle, Kim Hazelwood, Gabriel Synnaeve, Hugh Leather
cs.AI
Zusammenfassung
Wir untersuchen die neuartige Anwendung von Large Language Models zur Code-Optimierung. Wir stellen ein 7-Milliarden-Parameter-Transformer-Modell vor, das von Grund auf trainiert wurde, um LLVM-Assembly-Code hinsichtlich der Codegröße zu optimieren. Das Modell nimmt nicht optimierten Assembly-Code als Eingabe und gibt eine Liste von Compiler-Optionen aus, um das Programm bestmöglich zu optimieren. Entscheidend ist, dass wir das Modell während des Trainings dazu anhalten, die Anweisungsanzahl vor und nach der Optimierung sowie den optimierten Code selbst vorherzusagen. Diese zusätzlichen Lernaufgaben verbessern die Optimierungsleistung des Modells erheblich und vertiefen das Verständnis des Modells.
Wir evaluieren unser Modell anhand einer umfangreichen Testsuite von Programmen. Unser Ansatz erzielt eine Verbesserung von 3,0 % bei der Reduzierung der Anweisungsanzahl im Vergleich zum Compiler und übertrifft dabei zwei state-of-the-art Baseline-Methoden, die Tausende von Kompilierungen erfordern. Darüber hinaus zeigt das Modell überraschend starke Fähigkeiten im Code-Verständnis, indem es in 91 % der Fälle kompilierbaren Code erzeugt und in 70 % der Fälle die Ausgabe des Compilers exakt nachahmt.
English
We explore the novel application of Large Language Models to code
optimization. We present a 7B-parameter transformer model trained from scratch
to optimize LLVM assembly for code size. The model takes as input unoptimized
assembly and outputs a list of compiler options to best optimize the program.
Crucially, during training, we ask the model to predict the instruction counts
before and after optimization, and the optimized code itself. These auxiliary
learning tasks significantly improve the optimization performance of the model
and improve the model's depth of understanding.
We evaluate on a large suite of test programs. Our approach achieves a 3.0%
improvement in reducing instruction counts over the compiler, outperforming two
state-of-the-art baselines that require thousands of compilations. Furthermore,
the model shows surprisingly strong code reasoning abilities, generating
compilable code 91% of the time and perfectly emulating the output of the
compiler 70% of the time.