Edit model card

QuantFactory/llm-compiler-13b-ftd-GGUF

This is quantized version of facebook/llm-compiler-13b-ftd created using llama.cpp

The information you provide will be collected, stored, processed and shared in accordance with the Meta Privacy Policy.

Notice : LLM Compiler is licensed under the LLM Compiler License, Copyright © Meta Platforms, Inc. All Rights Reserved.

Introducing Meta Large Language Model Compiler (LLM Compiler), a state-of-the-art LLM for compiler optimization

Takeaways

  • LLM Compiler is a state-of-the-art LLM that builds upon Code Llama with improved performance for code optimization and compiler reasoning.
  • LLM Compiler is free for both research and commercial use.
  • LLM Compiler is available in two flavors:
    • LLM Compiler, the foundational models, pretrained on over 500B tokens of LLVM-IR, x86_84, ARM, and CUDA assembly codes and trained to predict the effect of LLVM optimizations;
    • and LLM Compiler FTD, which is further fine-tuned to predict the best optimizations for code in LLVM assembly to reduce code size, and to disassemble assembly code to LLVM-IR.
  • LLM Compiler demonstrates far stronger understanding of compiler optimizations than existing publicly available LLMs, perfectly emulating the compiler 20% of the time.
  • LLM Compiler FTD sets state-of-the-art results on the tasks of optimization for code size and disassembly. It achieves a 5.24% code size improvement over -Oz vs GPT-4 Turbo 0.03%, and 0.96 round-trip BLEU score on disassembly vs GPT-4 Turbo 0.43.

LINKS


We are excited to announce the release of LLM Compiler, a model targeted at code and compiler optimization tasks. LLM Compiler is built on top of our state-of-the-art large language model, Code Llama, adding capabilities to better understand compiler intermediate representations, assembly language and optimization. LLM Compiler is demonstrated on two difficult tasks: optimizing for code size and decompiling from assembly to the compiler’s intermediate representation. We release these foundation models to accelerate the application of LLMs for code optimization tasks and to enhance developer experience.

We are releasing LLM Compiler under the LLM Compiler License Agreement, which incorporates the Acceptable Use Policy for Llama Materials.

How LLM Compiler works

LLM Compiler is a specialization of Code Llama. It is a cutting-edge tool designed to optimize code using deep learning. LLM Compiler has been pre-trained on a vast amount of LLVM assembly (IR), x86_64, ARM, and CUDA assembly codes. LLM Compiler can predict, given a piece of LLVM assembly and a sequence of optimization passes for opt, the LLVM optimizer, what the change in code size will be and what the output code will look like after applying these optimizations. It has ‘understood’ the behavior of the optimizing compiler to such a degree that in many cases it can perfectly replicate its output. These capabilities make it ideally suited to compiler optimization tasks.

Compiler emulation

In addition to this core functionality and to demonstrate its ability to solve complex compiler optimization problems, LLM Compiler has been fine-tuned for two specific downstream tasks:

  1. Predicting the best optimization passes for opt to use in order to minimize code size, given a piece of LLVM assembly code. \

Autotuning

  1. Generating LLVM IR from a piece of x86_64 or ARM assembly code. \

Disassemble

We are releasing LLM Compiler models in two sizes: 7B and 13B parameters. The models have been trained with a context window of 16,000 tokens.

The two models address different serving and latency requirements. The 7B model, for example, can be served on a single GPU and is more suitable for tasks that require low latency, like fine grained optimisation. The 13B model returns the best results.

When using the LLM Compiler models, users must abide by our license and acceptable use policy.

Training

LLM Compiler performance

We tested the performance of LLM Compiler models for emulating compiler transformations, predicting optimal pass lists and decompiling intermediate representation on hold out test sets and compared them to Code Llama and GPT-4. We compare LLM Compiler Foundation to Code Llama Base and LLM Compiler FTD to Code Llama Instruct.

We evaluate LLM Compiler's ability to emulate compiler optimizations by giving it samples of unoptimized intermediate representation and a randomly generated list of optimizations. We then ask the model to generate the corresponding IR after the optimizations have been applied. In the table below we report the model's accuracy in reproducing the IR we would get from running opt. With very little knowledge of IR, Code Llama is unable to achieve high values while the LLM Compiler can generate character-by-character matches of expected assembly in 20% of the cases.

Model Size Accuracy at emulating compiler optimizations
Code Llama 7B 1.2%
Code Llama 13B 0.8%
LLM Compiler 7B 16%
LLM Compiler 13B 20%

In a similar approach we evaluate our model's ability to optimize IR for code size. In this instance, however, we let the model generate the pass list that is to be used on a given unoptimized IR. We then use this pass list to optimize the particular program using opt and record the binary size. The baseline is the binary size of the program when optimized using -Oz. Only LLM Compiler FTD models provide an improvement over -Oz, with the 13B parameter model marginally outperforming the smaller model, generating smaller object files than -Oz in 61% of cases.

Lastly, we evaluate disassembly performance by giving the model x86 assembly code and ask it to generate the corresponding IR. We then round-trip the model-generated disassembled IR back down to assembly. This enables us to evaluate accuracy of the disassembly by comparing the BLEU score of the original assembly against the round-trip result. LLM Compiler FTD 13B has the highest accuracy of round-tripped assembly (round trip BLEU) and most frequently produces perfect disassembly. Code Llama Instruct and GPT-4 Turbo struggle with generating syntactically correct LLVM-IR.

Model Size Code Size Improvement Round trip BLEU
GPT-4 Turbo -0.01% 0.43
Code Llama Inst 7B -0.49% 0.48
Code Llama Inst 13B -0.42% 0.62
LLM Compiler FTD 7B 4.77% 0.95
LLM Compiler FTD 13B 4.88% 0.96

Releasing LLM Compiler

LLMs are being used to make programming easier. They are beginning to be used to make programs more efficient.

At Meta, our conviction is that AI models, especially those designed for coding, thrive best with an open strategy, fostering both innovation and security. Models that are accessible to the public can expedite the creation of novel compiler optimization technologies. In turn, this will allow programs to be more efficient and smaller, enhancing the quality of life for all. By making models such as LLM Compiler available, the whole community can explore their potential, pinpoint problems, and rectify any vulnerabilities.

The model weights are available on Hugging Face.

Responsible use

Our research paper provides an in-depth look into the development process of the LLM Compiler, the methods we used for our benchmarking tests, and further insights into the model's limitations. It also discusses the issues faced, the steps we took to mitigate them.

Developers are advised to assess their models using evaluation benchmarks specific to compilers. Given that compilers are not bug-free, any suggested compiler optimizations must be rigorously tested. When a model decompiles assembly code, its accuracy should be confirmed.

The future of generative AI for optimisation

LLM Compiler is designed to support compiler researchers and engineers. But there are still many more use cases to support than what our models can serve. We hope that LLM Compiler will inspire others to leverage LLMs to create new innovative tools for research and commercial products.

Try LLM Compiler today

Model Card

LLM Compiler is a collection of pretrained and fine-tuned generative text models ranging in scale from 7 billion to 13 billion parameters. This is the repository for the 13 billion parameter foundation model version in the Hugging Face Transformers format. This model is designed for code optimization. Links to other models can be found in the index at the bottom.

Number of parameters Base Model Fine-tuned for code size and dissassembly
7B facebook/llm-compiler-7b facebook/llm-compiler-7b-ftd
13B facebook/llm-compiler-13b facebook/llm-compiler-13b-ftd

Model Use

To use this model, please make sure to install transformers:

pip install transformers accelerate

Example code using each of the model's compiler capabilities may be found in llm_compiler_demo.py.

The code below demonstrates default capabilities. You may need to set the HuggingFace access token - see (https://huggingface.co/docs/hub/security-tokens).

from transformers import AutoTokenizer
import transformers
import torch

model = "facebook/llm-compiler-13b"

tokenizer = AutoTokenizer.from_pretrained(model)
pipeline = transformers.pipeline(
    "text-generation",
    model=model,
    torch_dtype=torch.float16,
    device_map="auto",
)

sequences = pipeline(
    '%3 = alloca i32, align 4',
    do_sample=True,
    top_k=10,
    temperature=0.1,
    top_p=0.95,
    num_return_sequences=1,
    eos_token_id=tokenizer.eos_token_id,
    max_length=200,
)
for seq in sequences:
    print(f"Result: {seq['generated_text']}")

Model Details

*Note: Use of this model is governed by the Meta license. Meta developed and publicly released the LLM Compiler family of large language models (LLMs).

Model Developers Meta

Variations LLM Compiler comes in two model sizes of 7B, 13B parameters in two flavors, the foundation and instruction fine-tuned for code size and disassembly.

This repository contains the 13 billion parameter foundation model.

Input Models input text only.

Example prompt See llm_compiler_demo.py in the repo for examples of the different use cases.

Output Models generate text only.

Model Architecture LLM Compiler is an auto-regressive language model that uses an optimized transformer architecture.

Model Dates LLM Compiler has been trained between January 2024 and June 2024.

Status This is a static model trained on an offline dataset.

License A custom commercial license is available at: https://ai.meta.com/resources/models-and-libraries/llama-downloads/

Research Paper More information can be found in the paper "Meta Large Language Model Compiler: Foundation Models of Compiler Optimization".

Intended Use

Intended Use Cases LLM Compiler is intended for commercial and research use in English, relevant programming languages, LLVM IR, x86_64 assembly and ARM assembly.

Out-of-Scope Uses Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in languages other than English. Use in any other way that is prohibited by the Acceptable Use Policy and Licensing Agreement for LLM Compiler and its variants.

Hardware and Software

Training Factors We used custom training libraries. The training and fine-tuning of the released models have been performed Meta’s Research Super Cluster.

Carbon Footprint In aggregate, training all LLM Compiler models required 14K GPU hours of computation on hardware of type A100-80GB (TDP of 350-400W), not including the training of Code Llama. 100% of the estimated tCO2eq emissions were offset by Meta’s sustainability program.

Training Data

All experiments reported here and the released models have been trained and fine-tuned using the same data as Code Llama with different weights (see Section 2 and Table 1 in the research paper for details).

Evaluation Results

See evaluations for the main models and detailed ablations in Section 3 and safety evaluations in Section 4 of the research paper.

Ethical Considerations and Limitations

LLM Compiler and its variants are a new technology that carries risks with use. Testing conducted to date has been in English, and has not covered, nor could it cover all scenarios. For these reasons, as with all LLMs, LLM Compilers’s potential outputs cannot be predicted in advance, and the model may in some instances produce inaccurate or objectionable responses to user prompts. Therefore, before deploying any applications of LLM Compiler, developers should perform safety testing and tuning tailored to their specific applications of the model.

Please see the Responsible Use Guide available available at https://ai.meta.com/llama/responsible-use-guide.

Downloads last month
41
GGUF
Model size
13B params
Architecture
llama

4-bit

8-bit

Inference Examples
Unable to determine this model's library. Check the docs .

Model tree for QuantFactory/llm-compiler-13b-ftd-GGUF

Quantized
(6)
this model