Datasets:

Modalities:
Text
Formats:
parquet
Languages:
code
ArXiv:
Tags:
DOI:
License:
File size: 9,742 Bytes
3136413
f7d680d
 
 
ce5f814
f7d680d
 
 
 
5c46422
f7d680d
 
 
 
3136413
 
f7d680d
3136413
1108e86
 
 
 
 
 
 
 
 
 
 
fe037d0
1108e86
f7d680d
3136413
f7d680d
 
 
 
 
 
 
 
b9a6c18
f7d680d
 
 
b9a6c18
 
f7d680d
3136413
ce5f814
3136413
b9a6c18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7d680d
3136413
f7d680d
 
 
 
ce5f814
f7d680d
 
 
ce5f814
 
 
 
 
 
 
f7d680d
 
 
ce5f814
 
 
 
 
f7d680d
 
 
 
ce5f814
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1746762
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7d680d
 
ce5f814
f7d680d
ce5f814
f7d680d
ce5f814
 
 
f7d680d
ce5f814
 
f7d680d
ce5f814
f7d680d
ce5f814
 
f7d680d
ce5f814
f7d680d
ce5f814
 
f7d680d
ce5f814
b9a6c18
dff1b04
 
 
b9a6c18
 
 
 
dff1b04
b9a6c18
 
dff1b04
 
 
 
 
 
a68aef4
 
b9a6c18
 
a68aef4
 
 
 
 
 
 
ce5f814
 
 
 
 
3136413
a68aef4
 
 
 
 
21795d9
fe037d0
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---
annotations_creators: []
language:
- code
license: cc-by-4.0
multilinguality:
- multilingual
pretty_name: ComPile
size_categories:
- n>1T
source_datasets: []
task_categories:
- text-generation
task_ids: []
---

# Dataset Card for ComPile: A Large IR Dataset from Production Sources

## Table of Contents
- [Table of Contents](#table-of-contents)
- [Dataset Description](#dataset-description)
  - [Changelog](#changelog)
  - [Dataset Summary](#dataset-summary)
  - [Languages](#languages)
  - [Dataset Usage](#dataset-usage)
- [Dataset Structure](#dataset-structure)
  - [Data Fields](#data-fields)
- [Dataset Size](#dataset-size)
- [Licensing](#licensing)
- [How to Cite](#how-to-cite)

## Dataset Description

- **Homepage:** https://llvm-ml.github.io/ComPile/
- **Paper:** https://arxiv.org/abs/2309.15432
- **Leaderboard:** N/A

### Changelog

|Release|Programming Languages|Description|
|-|-|-|
|v1.0| C/C++, Rust, Swift, Julia | Fine Tuning-scale dataset of 602GB of deduplicated LLVM (bitcode) IR |

### Dataset Summary

ComPile contains over 2.7TB of permissively-licensed source code compiled to (textual) [LLVM](https://llvm.org)
intermediate representation (IR) covering C/C++, Rust, Swift, and Julia.
The dataset was created by hooking into LLVM code generation either through the language's package manager or the
compiler directly to extract the dataset of intermediate representations from production grade programs using our
[dataset collection utility for the LLVM compilation infrastructure](https://doi.org/10.5281/zenodo.10155761).

### Dataset Size

The public release of ComPile contains over 2.7TB of textual LLVM-IR, which tokenizes into 1.3+T tokens using the Llama
tokenizer.

| Langauage | Bitcode Size | Textual IR Size | Llama Token Count | BPE Token Count (10k Vocab) | BPE Token Count (50k Vocab) |
|-----------|--------------|-----------------|-------------------|-----------------------------|-----------------------------|
| C         | 2.47GB       | 10.19GB         | 5.31B             | 0.91B                       | 0.58B                       |
| C++       | 28.87GB      | 102.76GB        | 46.75B            | 11.20B                      | 6.27B                       |
| Julia     | 164.16GB     | 1088.39GB       | 547.60B           | 41.91B                      | 23.49B                      |
| Rust      | 399.94GB     | 1523.84GB       | 735.90B           | 137.37B                     | 90.01B                      |
| Swift     | 6.95GB       | 35.93GB         | 19.78B            | 3.36B                       | 1.75B                       |
| Total     | 602.39GB     | 2761.11GB       | 1355.34B          | 194.75B                     | 122.10B                     |

ComPile is distributed as bitcode, which is a compressed format that can be easily converted to and from the
textual representation of LLVM-IR. To collect token counts, we disassembled the bitcode to convert it into textual
IR and then ran a tokenizer over it. We used the standard Llama tokenizer and then ran fastBPE using a custom
vocabulary trained on a multi-GB sample of textual IR representativie of all languages in ComPile at two different
two different vocab sizes, particularly 10k and 50k. LLVM-IR is quite formulaic, so using custom vocabulary significantly
reduces the number of tokens generated.

### Languages

The dataset contains **5 programming languages** as of v1.0.
```
"c++", "c", "rust", "swift", "julia"
```

### Dataset Usage

To use ComPile we recommend HuggingFace's [datasets library](https://huggingface.co/docs/datasets/index). To e.g. load the dataset:

```python
from datasets import load_dataset

ds = load_dataset('llvm-ml/ComPile', split='train')
```

By default this will download the entirety of the 550GB+ dataset, and cache it locally at the directory
specified by the environment variable `HF_DATASETS_CACHE`, which defaults to `~/.cache/huggingface`. To
load the dataset in a streaming format, where the data is not saved locally:

```python
ds = load_dataset('llvm-ml/ComPile', split='train', streaming=True)
```

For further arguments of `load_dataset`, please take a look at the
`loading a dataset` [documentation](https://huggingface.co/docs/datasets/load_hub), and
the `streaming` [documentation](https://huggingface.co/docs/datasets/stream). Bear in mind that
this is significantly slower than loading the dataset from a local storage. For experimentation that
requires more performance but might not require the whole dataset, you can also specify a portion
of the dataset to download. For example, the following code will only download the first 10%
of the dataset:

```python
ds = load_dataset('llvm-ml/ComPile', split='train[:10%]')
```

Once the dataset has been loaded, the individual module files can be accessed by iterating through
the dataset or accessing specific indices:

```python
# We can iterate through the dataset
next(iter(ds))
# We can also access modules at specific indices
ds[0]
```

If you're interested in getting textual IR instead of bitcode, you can simply run `llvm-dis`
over the bitcode which will return the IR in textual form. Using Python's `subprocess` module
to do this looks something like this:

```python
bitcode_module = next(iter(ds))['content']
dis_command_vector = ['llvm-dis', '-']
with subprocess.Popen(
    dis_command_vector,
    stdout=subprocess.PIPE,
    stderr=subprocess.STDOUT,
    stdin=subprocess.PIPE) as dis_process:
  output = dis_process.communicate(
      input=bitcode_module)[0].decode('utf-8')
  # the variable output contains the textual IR that can be used downstream.
```

Filtering and map operations can be performed with the primitives available within the
HuggingFace `datasets` library.

## Dataset Structure

### Data Fields
Each row in the dataset consists of an individual LLVM-IR Module along with some metadata. There are
six columns associated with each row:

- `content` (string): This column contains the raw bitcode that composes the module. This can be written to a `.bc`
file and manipulated using the standard llvm utilities or passed in directly through stdin if using something
like Python's `subprocess`.
- `license_expression` (string): This column contains the SPDX expression describing the license of the project that the
module came from.
- `license_source` (string): This column describes the way the `license_expression` was determined. This might indicate
an individual package ecosystem (eg `spack`), license detection (eg `go_license_detector`), or might also indicate
manual curation (`manual`).
- `license_files`: This column contains an array of license files. These file names map to licenses included in
`/licenses/licenses-0.parquet`.
- `package_source` (string): This column contains information on the package that the module was sourced from. This is
typically a link to a tar archive or git repository from which the project was built, but might also contain a
mapping to a specific package ecosystem that provides the source, such as Spack.
- `language` (string): This column indicates the source language that the module was compiled from.

## License Constraints and Deduplication

| Langauge | Raw Size | License Constraints | Deduplicated + License Constraints |
|----------|----------|---------------------|------------------------------------|
| C/C++    | 126GB    | 46GB                | 31GB                               |
| C        | 16GB     | N/A                 | 2GB                                |
| C++      | 109GB    | N/A                 | 29GB                               |
| Julia    | 201GB    | 179GB               | 164GB                              |
| Swift    | 8GB      | 7GB                 | 7GB                                |
| Rust     | 656GB    | 443GB               | 400GB                              |
| Total    | 990GB    | 675GB               | 602GB                              |

The raw size is the size obtained directly from building all the projects. The license constraints column
shows the size per language after license information is taken into account. The last column shows the size
when both license constraints and deduplication are taken into account, which is what is included in the
dataset.

Note that the sizes displayed here are of the compressed bitcode representation rather
than textual IR. We see an expansion ratio of 2-5x, averaging around 4x when converting
from compressed bitcode to textual IR. Specific per-language numbers are available in the section
above on dataset size.

## Dataset Construction

Exact details on how the dataset is constructed are available in
[our paper describing the dataset](https://arxiv.org/abs/2309.15432). The packages for
v1.0 of the dataset were downloaded and built on 1/12/24-1/13/24.

## Licensing

The individual modules within the dataset are subject to the licenses of the projects that they come from. License
information is available in each row, including the SPDX license expression, the license files, and also a link to
the package source where license information can be further validated.

The curation of these modules is licensed under a CC-BY-4.0 license.

## Contact Info

1. Aiden Grossman (amgrossman@ucdavis.edu)
2. Ludger Paehler (paehlerludger@gmail.com)
3. Johannes Doerfert (doerfert1@llnl.gov)

## How to Cite

Please cite the dataset in the following format:

```bibtex
@article{grossman2023compile,
  title={ComPile: A Large IR Dataset from Production Sources},
  author={Grossman, Aiden and Paehler, Ludger and Parasyris, Konstantinos and Ben-Nun, Tal and Hegna, Jacob and Moses, William and Diaz, Jose M Monsalve and Trofin, Mircea and Doerfert, Johannes},
  journal={arXiv preprint arXiv:2309.15432},
  year={2023}
}
```