Skip to content

Commit 36ab923

Browse files
committed
Add behavioral cloning step to LLVM inliner model training demo
1 parent 625e774 commit 36ab923

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

docs/llvm/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# LLVM MLGO Inliner Demo
2+
3+
## 1. Build the Docker Image
4+
5+
From the repository root, build the development environment container:
6+
7+
```bash
8+
docker build -t ml-compiler-opt-llvm docs/llvm/
9+
```
10+
11+
## 2. Run the Container
12+
13+
Run the container with volume mounts to persist corpus data, training logs, and checkpoints locally. This enables running TensorBoard on the host to monitor training.
14+
15+
```bash
16+
sudo docker run -it \
17+
-v "$(pwd):/work/ml-compiler-opt" \
18+
-v "$(pwd)/local_logs:/work/corpus/" \
19+
ml-compiler-opt-llvm /bin/bash
20+
```
21+
22+
## 3. Run the Training Pipeline
23+
24+
Inside the container, execute the entire end-to-end pipeline:
25+
26+
```bash
27+
./docs/llvm/run_everything.sh
28+
```
29+
30+
---
31+
32+
## 4. Monitor Training Progress
33+
34+
To monitor the training progress using TensorBoard, run the following command on your **host machine** pointing to the mounted logs directory:
35+
36+
```bash
37+
tensorboard --logdir local_logs
38+
```
39+
40+
---
41+
42+
## 5. Evaluate the Model
43+
44+
Evaluate the size savings of your trained ML model against the baseline heuristic:
45+
46+
```bash
47+
./docs/llvm/evaluate_model.sh
48+
```
49+
50+
To see available options (e.g., count, shuffling, specific models):
51+
```bash
52+
./docs/llvm/evaluate_model.sh --help
53+
```

docs/llvm/run_everything.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ fi
2727
"${SCRIPT_DIR}/extract_corpus.sh"
2828
"${SCRIPT_DIR}/generate_default_trace.sh"
2929
"${SCRIPT_DIR}/generate_vocab.sh"
30+
"${SCRIPT_DIR}/train_bc.sh"
3031
"${SCRIPT_DIR}/train_with_es.sh"

docs/llvm/train_bc.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
17+
cd /work/ml-compiler-opt
18+
19+
TF_CPP_MIN_LOG_LEVEL=3 GINPATH=/work/ml-compiler-opt PYTHONPATH=/work/ml-compiler-opt:$PYTHONPATH \
20+
python /work/ml-compiler-opt/compiler_opt/rl/train_bc.py \
21+
--root_dir /work/corpus/bc_model \
22+
--gin_files /work/ml-compiler-opt/compiler_opt/rl/inlining/gin_configs/behavioral_cloning_nn_agent.gin \
23+
--gin_bindings inlining.config.get_observation_processing_layer_creator.quantile_file_dir="'/work/corpus/vocab'" \
24+
--data_path /work/corpus/default_trace

docs/llvm/train_with_es.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ TF_CPP_MIN_LOG_LEVEL=3 PYTHONPATH=/work/ml-compiler-opt:$PYTHONPATH \
2222
--gin_bindings clang_path="'/work/llvm-train/bin/clang'" \
2323
--gin_bindings llvm_size_path="'/work/llvm-train/bin/llvm-size'" \
2424
--gin_bindings inlining.config.get_observation_processing_layer_creator.quantile_file_dir="'/work/corpus/vocab'" \
25+
--gin_bindings pretrained_policy_path="'/work/corpus/bc_model/saved_policy'" \
2526
--output_path /work/corpus/trained_model_es

0 commit comments

Comments
 (0)