初始化项目,由ModelHub XC社区提供模型

Model: facebook/llm-compiler-7b
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-06-13 03:06:13 +08:00
commit d53d97fe9a
19 changed files with 94124 additions and 0 deletions

47
.gitattributes vendored Normal file
View File

@@ -0,0 +1,47 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bin.* filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zstandard filter=lfs diff=lfs merge=lfs -text
*.tfevents* filter=lfs diff=lfs merge=lfs -text
*.db* filter=lfs diff=lfs merge=lfs -text
*.ark* filter=lfs diff=lfs merge=lfs -text
**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.gguf* filter=lfs diff=lfs merge=lfs -text
*.ggml filter=lfs diff=lfs merge=lfs -text
*.llamafile* filter=lfs diff=lfs merge=lfs -text
*.pt2 filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text

BIN
LICENSE.pdf Normal file

Binary file not shown.

396
README.md Normal file
View File

@@ -0,0 +1,396 @@
---
license: other
extra_gated_prompt: >-
**Meta Large Language Model Compiler (LLM Compiler) LICENSE AGREEMENT**
Version Release Date: 27th June 2024
“**Agreement**” means the terms and conditions for use, reproduction, distribution and modification of the LLM Compiler Materials set forth herein.
“**Documentation**” means the specifications, manuals and documentation accompanying the LLM Compiler distributed by Meta at:
* [https://huggingface.co/facebook/llm-compiler-7b](https://huggingface.co/facebook/llm-compiler-7b)
* [https://huggingface.co/facebook/llm-compiler-7b-ftd](https://huggingface.co/facebook/llm-compiler-7b-ftd)
* [https://huggingface.co/facebook/llm-compiler-13b](https://huggingface.co/facebook/llm-compiler-13b)
* [https://huggingface.co/facebook/llm-compiler-13b-ftd](https://huggingface.co/facebook/llm-compiler-13b-ftd)
“**Licensee**” or “**you**” means you, or your employer or any other person or entity (if you are entering into this Agreement on such person or entitys behalf), of the age required under applicable laws, rules or regulations to provide legal consent and that has legal authority to bind your employer or such other person or entity if you are entering in this Agreement on their behalf.
“**Meta Large Language Model Compiler” and “LLM Compiler**” mean the foundational large language models and software and algorithms, including machine-learning model code, trained model weights, inference-enabling code, training-enabling code, fine-tuning enabling code and other elements of the foregoing distributed by Meta at:
* [https://huggingface.co/facebook/llm-compiler-7b](https://huggingface.co/facebook/llm-compiler-7b)
* [https://huggingface.co/facebook/llm-compiler-7b-ftd](https://huggingface.co/facebook/llm-compiler-7b-ftd)
* [https://huggingface.co/facebook/llm-compiler-13b](https://huggingface.co/facebook/llm-compiler-13b)
* [https://huggingface.co/facebook/llm-compiler-13b-ftd](https://huggingface.co/facebook/llm-compiler-13b-ftd)
“**LLM Compiler Materials**” means, collectively, Metas proprietary LLM Compiler and Documentation (and any portion thereof) made available under this Agreement.
“**Meta**” or “**we**” means Meta Platforms Ireland Limited (if you are located in or, if you are an entity, your principal place of business is in the EEA or Switzerland) and Meta Platforms, Inc. (if you are located outside of the EEA or Switzerland).
By clicking “I Accept” below or by using or distributing any portion or element of the LLM Compiler Materials, you agree to be bound by this Agreement.
1. **License Rights and Redistribution**. \
a. <span style="text-decoration:underline;">Grant of Rights</span>. You are granted a non-exclusive, worldwide, non-transferable and royalty-free limited license under Metas intellectual property or other rights owned by Meta embodied in the LLM Compiler Materials to use, reproduce, distribute, copy, create derivative works of, and make modifications to the LLM Compiler Materials.
b. <span style="text-decoration:underline;">Redistribution and Use</span>.
i. If you distribute or make available the LLM Compiler Materials (or any derivative works thereof), or a product or service that uses any of them, including another AI model, you shall (A) provide a copy of this Agreement with any such LLM Compiler Materials; and (B) prominently display “Built with LLM Compiler” on a related website, user interface, blogpost, about page, or product documentation. If you use the LLM Compiler Materials to create, train, fine tune, or otherwise improve an AI model, which is distributed or made available, you shall also include “LLM Compiler” at the beginning of any such AI model name.
ii. If you receive LLM Compiler Materials, or any derivative works thereof, from a Licensee as part of an integrated end user product, then Section 2 of this Agreement will not apply to you.
iii. You must retain in all copies of the LLM Compiler Materials that you distribute the following attribution notice within a “Notice” text file distributed as a part of such copies: “LLM Compiler is licensed under the LLM Compiler License, Copyright © Meta Platforms, Inc. All Rights Reserved.”
iv. Your use of the LLM Compiler Materials must comply with applicable laws and regulations (including trade compliance laws and regulations) and adhere to the Acceptable Use Policy for Llama Materials (available at https://llama.meta.com/llama3/use-policy), which is hereby incorporated by reference into this Agreement.
v. You will not use the LLM Compiler Materials or any output or results of the LLM Compiler Materials to improve any other large language model.
2. **Additional Commercial Terms**. If, on the LLM Compiler release date, the monthly active users of the products or services made available by or for Licensee, or Licensees affiliates, is greater than 700 million monthly active users in the preceding calendar month, you must request a license from Meta, which Meta may grant to you in its sole discretion, and you are not authorized to exercise any of the rights under this Agreement unless or until Meta otherwise expressly grants you such rights.
3**. Disclaimer of Warranty**. UNLESS REQUIRED BY APPLICABLE LAW, THE LLM COMPILER MATERIALS AND ANY OUTPUT AND RESULTS THEREFROM ARE PROVIDED ON AN “AS IS” BASIS, WITHOUT WARRANTIES OF ANY KIND, AND META DISCLAIMS ALL WARRANTIES OF ANY KIND, BOTH EXPRESS AND IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE LLM COMPILER MATERIALS AND ASSUME ANY RISKS ASSOCIATED WITH YOUR USE OF THE LLM COMPILER MATERIALS AND ANY OUTPUT AND RESULTS.
4. **Limitation of Liability**. IN NO EVENT WILL META OR ITS AFFILIATES BE LIABLE UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE, PRODUCTS LIABILITY, OR OTHERWISE, ARISING OUT OF THIS AGREEMENT, FOR ANY LOST PROFITS OR ANY INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL, EXEMPLARY OR PUNITIVE DAMAGES, EVEN IF META OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF ANY OF THE FOREGOING.
5. **Intellectual Property**.
a. No trademark licenses are granted under this Agreement, and in connection with the LLM Compiler Materials, neither Meta nor Licensee may use any name or mark owned by or associated with the other or any of its affiliates, except as required for reasonable and customary use in describing and redistributing the LLM Compiler Materials or as set forth in this Section 5(a). Meta hereby grants you a license to use LLM Compiler (the “Mark”) solely as required to comply with the last sentence of Section 1.b.i. You will comply with Metas brand guidelines (currently accessible at[ https://about.meta.com/brand/resources/meta/company-brand/)](https://about.meta.com/brand/resources/meta/company-brand/). All goodwill arising out of your use of the Mark will inure to the benefit of Meta.
b. Subject to Metas ownership of LLM Compiler Materials and derivatives made by or for Meta, with respect to any derivative works and modifications of the LLM Compiler Materials that are made by you, as between you and Meta, you are and will be the owner of such derivative works and modifications.
c. If you institute litigation or other proceedings against Meta or any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the LLM Compiler Materials or LLM Compiler outputs or results, or any portion of any of the foregoing, constitutes infringement of intellectual property or other rights owned or licensable by you, then any licenses granted to you under this Agreement shall terminate as of the date such litigation or claim is filed or instituted. You will indemnify and hold harmless Meta from and against any claim by any third party arising out of or related to your use or distribution of the LLM Compiler Materials.
6. **Term and Termination**. The term of this Agreement will commence upon your acceptance of this Agreement or access to the LLM Compiler Materials and will continue in full force and effect until terminated in accordance with the terms and conditions herein. Meta may terminate this Agreement if you are in breach of any term or condition of this Agreement. Upon termination of this Agreement, you shall delete and cease use of the LLM Compiler Materials. Sections 3, 4 and 7 shall survive the termination of this Agreement.
7. **Governing Law and Jurisdiction**. This Agreement will be governed and construed under the laws of the State of California without regard to choice of law principles, and the UN Convention on Contracts for the International Sale of Goods does not apply to this Agreement. The courts of California shall have exclusive jurisdiction of any dispute arising out of this Agreement.
extra_gated_fields:
First Name: text
Last Name: text
Date of birth: date_picker
Country: country
Affiliation: text
I accept the terms and conditions: checkbox
geo: ip_location
By clicking Submit below I accept the terms of the license and acknowledge that the information I provide will be collected stored processed and shared in accordance with the Meta Privacy Policy: checkbox
extra_gated_description: The information you provide will be collected, stored, processed and shared in accordance with the [Meta Privacy Policy](https://www.facebook.com/privacy/policy/).
extra_gated_button_content: I Accept Meta LLM Compiler License and AUP
---
# You need to share contact information with Meta to access this model
----
The information you provide will be collected, stored, processed and shared in accordance with the [Meta Privacy Policy](https://www.facebook.com/privacy/policy/).
----
# 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
* [LLM Compiler research paper](https://ai.meta.com/research/publications/meta-large-language-model-compiler-foundation-models-of-compiler-optimization/)
* Download the LLM Compiler and LLM Compiler FTD models:
* [llm-compiler-7b](https://huggingface.co/facebook/llm-compiler-7b)
* [llm-compiler-7b-ftd](https://huggingface.co/facebook/llm-compiler-7b-ftd)
* [llm-compiler-13b](https://huggingface.co/facebook/llm-compiler-13b)
* [llm-compiler-13b-ftd](https://huggingface.co/facebook/llm-compiler-13b-ftd)
---
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 compilers 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](LICENSE.pdf), which incorporates the [Acceptable Use Policy]([https://llama.meta.com/llama3/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](readme/emulate.png)
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](readme/autotune.png)
2. Generating LLVM IR from a piece of x86_64 or ARM assembly code. \
![Disassemble](readme/disassemble.png)
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](readme/training.png)
## 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.
<table>
<tr>
<td>Model
</td>
<td>Size
</td>
<td>Accuracy at emulating compiler optimizations
</td>
</tr>
<tr>
<td>Code Llama
</td>
<td>7B
</td>
<td>1.2%
</td>
</tr>
<tr>
<td>Code Llama
</td>
<td>13B
</td>
<td>0.8%
</td>
</tr>
<tr>
<td>LLM Compiler
</td>
<td>7B
</td>
<td>16%
</td>
</tr>
<tr>
<td>LLM Compiler
</td>
<td>13B
</td>
<td><strong>20%</strong>
</td>
</tr>
</table>
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.
<table>
<tr>
<td>Model
</td>
<td>Size
</td>
<td>Code Size Improvement
</td>
<td>Round trip BLEU
</td>
</tr>
<tr>
<td>GPT-4 Turbo
</td>
<td>
</td>
<td>-0.01%
</td>
<td>0.43
</td>
</tr>
<tr>
<td>Code Llama Inst
</td>
<td>7B
</td>
<td>-0.49%
</td>
<td>0.48
</td>
</tr>
<tr>
<td>Code Llama Inst
</td>
<td>13B
</td>
<td>-0.42%
</td>
<td>0.62
</td>
</tr>
<tr>
<td>LLM Compiler FTD
</td>
<td>7B
</td>
<td>4.77%
</td>
<td>0.95
</td>
</tr>
<tr>
<td>LLM Compiler FTD
</td>
<td>13B
</td>
<td><strong>4.88%</strong>
</td>
<td><strong>0.96</strong>
</td>
</tr>
</table>
## 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
* Download the LLM Compiler and LLM Compiler FTD models:
* [llm-compiler-7b](https://huggingface.co/facebook/llm-compiler-7b)
* [llm-compiler-7b-ftd](https://huggingface.co/facebook/llm-compiler-7b-ftd)
* [llm-compiler-13b](https://huggingface.co/facebook/llm-compiler-13b)
* [llm-compiler-13b-ftd](https://huggingface.co/facebook/llm-compiler-13b-ftd)
* Read the research paper
* [LLM Compiler research paper](https://ai.meta.com/research/publications/meta-large-language-model-compiler-foundation-models-of-compiler-optimization/)
# **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 7 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](https://huggingface.co/facebook/llm-compiler-7b) | [facebook/llm-compiler-7b-ftd](https://huggingface.co/facebook/llm-compiler-7b-ftd) |
| 13B | [facebook/llm-compiler-13b](https://huggingface.co/facebook/llm-compiler-13b) | [facebook/llm-compiler-13b-ftd](https://huggingface.co/facebook/llm-compiler-13b-ftd) |
## Model Use
To use this model, please make sure to install transformers:
```bash
pip install transformers accelerate
```
Example code using each of the model's compiler capabilities may be found in [llm_compiler_demo.py](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).
```python
from transformers import AutoTokenizer
import transformers
import torch
model = "facebook/llm-compiler-7b"
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 7 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/](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](https://ai.meta.com/research/publications/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](https://llama.meta.com/llama3/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 Metas 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 Metas 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](https://ai.meta.com/research/publications/llm-compiler-foundation-models-for-compiler-optimization/) 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 Compilerss 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](https://ai.meta.com/llama/responsible-use-guide).

27
config.json Normal file
View File

@@ -0,0 +1,27 @@
{
"architectures": [
"LlamaForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"bos_token_id": 1,
"eos_token_id": 2,
"hidden_act": "silu",
"hidden_size": 4096,
"initializer_range": 0.02,
"intermediate_size": 11008,
"max_position_embeddings": 16384,
"model_type": "llama",
"num_attention_heads": 32,
"num_hidden_layers": 32,
"num_key_value_heads": 32,
"pretraining_tp": 1,
"rms_norm_eps": 1e-05,
"rope_scaling": null,
"rope_theta": 1000000.0,
"tie_word_embeddings": false,
"torch_dtype": "bfloat16",
"transformers_version": "4.37.2",
"use_cache": true,
"vocab_size": 32000
}

1
configuration.json Normal file
View File

@@ -0,0 +1 @@
{"framework": "pytorch", "task": "text-generation", "allow_remote": true}

6
generation_config.json Normal file
View File

@@ -0,0 +1,6 @@
{
"_from_model_config": true,
"bos_token_id": 1,
"eos_token_id": 2,
"transformers_version": "4.37.2"
}

177
llm_compiler_demo.py Normal file
View File

@@ -0,0 +1,177 @@
# This is a set of super simple inference functions to try out LLM Compiler.
# This is just an example, not the 'recommended' way to do it.
# It emphasizes simplicity over efficiency.
#
# This has been tested on a V100 32Gb GPU. If your GPU is smaller than that, it will likely fail.
# Run it in CPU mode and it should work, albeit very, very slowly.
#
# You may need to set the HuggingFace access token
# see https://huggingface.co/docs/hub/security-tokens
# Once you have a token, export it before running this script
# export HF_TOKEN=...
#
# The API is:
# # Create a compiler object
# llmc = LLMCompiler()
#
# # Do ordinary inference
# output = llmc.infer("A prompt")
#
# # Emulate the compiler
# # Pass in an LLVM IR, a passes argument for opt, the number of instructions in that IR and the number of bytes in the object file.
# # This produces an IR as output
# output = llmc.emulate_ir(ir, ir_count, bin_size)
# # This produces assembly as output
# output = llmc.emulate_ir(ir, ir_count, bin_size)
#
# # Get optimisations for code size
# # Pass in an IR
# output = llmc.optimize_for_code_size(ir)
#
# # Disassemble to IR
# # Pass in assembly
# output = llmc.disassemble(asm)
#
# Note that only models named llm-compiler-\db-ftd have been fine-tuned for the last two tasks
from transformers import AutoTokenizer, AutoModelForCausalLM
from textwrap import indent
import torch
MODEL_NAMES = [
"facebook/llm-compiler-7b",
"facebook/llm-compiler-13b",
"facebook/llm-compiler-7b-ftd",
"facebook/llm-compiler-13b-ftd",
]
class LLM_Compiler:
def __init__(self, model_name: str = "facebook/llm-compiler-7b", device: str = "cuda" if torch.cuda.is_available() else "cpu"):
if model_name not in MODEL_NAMES:
raise ValueError(f"model_name must be one of {MODEL_NAMES}")
self.model_name = model_name
self.device = device
self.tokenizer = AutoTokenizer.from_pretrained(self.model_name)
self.model = AutoModelForCausalLM.from_pretrained(self.model_name).to(self.device)
self.model.eval()
def infer(self, prompt: str, max_new_tokens: int = 50) -> str:
inputs = self.tokenizer(prompt, return_tensors="pt").to(self.device)
outputs = self.model.generate(**inputs, max_new_tokens=max_new_tokens)
text: str = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
return text[len(prompt): ]
def emulate_ir(self, ir: str, passes: str, ir_count: int, bin_size: int, max_new_tokens: int = 50) -> str:
prompt = f"""\
[INST] Give the LLVM-IR for the following code when optimized using opt -p '{passes}':
<code>{ir}</code>
The input code has instruction count {ir_count} and binary size {bin_size} bytes. [/INST]"""
return self.infer(prompt, max_new_tokens=max_new_tokens)
def emulate_asm(self, ir: str, passes: str, ir_count: int, bin_size: int, max_new_tokens: int = 50) -> str:
prompt = f"""\
[INST] Give the assembly for the following code when optimized using opt -p '{passes}':
<code>{ir}</code>
The input code has instruction count {ir_count} and binary size {bin_size} bytes. [/INST]"""
return self.infer(prompt, max_new_tokens=max_new_tokens)
def optimize_for_code_size(self, ir: str, max_new_tokens: int = 50) -> str:
prompt = f"""\
[INST] Tell me how to optimize this LLVM-IR for object file size:
<code>{ir}</code> [/INST]"""
return self.infer(prompt, max_new_tokens=max_new_tokens)
def disassemble(self, asm: str, max_new_tokens: int = 50) -> str:
prompt = f"""\
[INST] Disassemble this code to LLVM-IR:
<code>{asm}</code> [/INST]"""
return self.infer(prompt, max_new_tokens=max_new_tokens)
if __name__ == "__main__":
# Demo the capabilities
ir_count = 8
bin_size = 65
ir = """\
; ModuleID = '<stdin>'
source_filename = "-"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: minsize nounwind optsize uwtable
define dso_local i32 @add_two(i32 noundef %0, i32 noundef %1) #0 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
store i32 %0, ptr %3, align 4, !tbaa !5
store i32 %1, ptr %4, align 4, !tbaa !5
%5 = load i32, ptr %3, align 4, !tbaa !5
%6 = load i32, ptr %4, align 4, !tbaa !5
%7 = add nsw i32 %5, %6
ret i32 %7
}
attributes #0 = { minsize nounwind optsize uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 17.0.6 (git@github.com:fairinternal/CodeGen.git b05db9bbf7a92019267416c1bb9996fe6134e3f1)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
"""
asm = """\
.text
.file "-"
.globl add_two # -- Begin function add_two
.type add_two,@function
add_two: # @add_two
.cfi_startproc
# %bb.0:
movl %edi, -4(%rsp)
movl %esi, -8(%rsp)
movl -4(%rsp), %eax
addl -8(%rsp), %eax
retq
.Lfunc_end0:
.size add_two, .Lfunc_end0-add_two
.cfi_endproc
# -- End function
.ident "clang version 17.0.6 (git@github.com:fairinternal/CodeGen.git b05db9bbf7a92019267416c1bb9996fe6134e3f1)"
.section ".note.GNU-stack","",@progbits
.addrsig
"""
passes = "module(default<Oz>)"
max_new_tokens = 800
# Get the model
llm_compiler = LLM_Compiler()
print(f"Emulating the 'opt -p {passes}' on an ir, producing ir")
print(indent(llm_compiler.emulate_ir(ir, passes, ir_count, bin_size, max_new_tokens), " "))
print(f"Emulating the 'opt -p {passes}' on an ir, producing asm")
print(indent(llm_compiler.emulate_asm(ir, passes, ir_count, bin_size, max_new_tokens), " "))
print(f"Getting the optimal passes for code size")
print(indent(llm_compiler.optimize_for_code_size(ir, max_new_tokens), " "))
print(f"Disassembling to ir")
print(indent(llm_compiler.disassemble(asm, max_new_tokens), " "))

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2ec7bd2581668339973efd1962fdca15bacd291d7c28e1d944c8fc9240936092
size 4939009113

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8438285e8c9449bd59737b0840f2f445f3a47d75bad1bea42b17f6ba28e9fdf8
size 4947415489

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:219f0dc266080d29cdbf0edc72e48ef15eefc9e84cfb466c919f72cd822cb742
size 3590506196

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a3597c838ba29c01a62f88f9844ea21fd2d8a410cca3c8021d509824cf717a9b
size 23950

BIN
readme/autotune.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 858 KiB

BIN
readme/disassemble.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 768 KiB

BIN
readme/emulate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 KiB

BIN
readme/training.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

23
special_tokens_map.json Normal file
View File

@@ -0,0 +1,23 @@
{
"bos_token": {
"content": "<s>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"eos_token": {
"content": "</s>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"unk_token": {
"content": "<unk>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
}
}

93391
tokenizer.json Normal file

File diff suppressed because it is too large Load Diff

3
tokenizer.model Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7d77173a958615d2779fe7b6771a8e310f6f448715f56038a24c1641f9359a67
size 499723

41
tokenizer_config.json Normal file
View File

@@ -0,0 +1,41 @@
{
"add_bos_token": true,
"add_eos_token": false,
"added_tokens_decoder": {
"0": {
"content": "<unk>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"1": {
"content": "<s>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"2": {
"content": "</s>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
}
},
"bos_token": "<s>",
"clean_up_tokenization_spaces": false,
"eos_token": "</s>",
"legacy": true,
"model_max_length": 1000000000000000019884624838656,
"pad_token": null,
"sp_model_kwargs": {},
"spaces_between_special_tokens": false,
"tokenizer_class": "LlamaTokenizer",
"unk_token": "<unk>",
"use_default_system_prompt": false
}