Skip to content

Commit 779eca4

Browse files
authored
fix: @benchmark bot fixes (#565)
* Update ci-testing.yml * update * update * Update .github/benchmark/benchmark.py * feat: Add support for Makefile arguments in benchmark script and CI workflow * feat: Enhance benchmark script and CI workflow to handle Makefile arguments and improve error reporting * update
1 parent bbf0250 commit 779eca4

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

.github/benchmark/benchmark.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,26 @@ class BenchmarkArgs:
1818
"""Arguments for the LitData benchmark."""
1919

2020
pr_number: int
21+
branch: str
2122
org: Optional[str]
2223
user: Optional[str]
2324
teamspace: str
2425
machine: Machine
26+
make_args: str
2527

2628

2729
def parse_args() -> BenchmarkArgs:
2830
"""Parse command line arguments."""
2931
parser = argparse.ArgumentParser(description="Benchmark LitData in CI.")
3032
parser.add_argument("--pr", type=int, required=True, help="GitHub PR number")
33+
parser.add_argument("--branch", type=str, required=True, help="GitHub PR branch name")
3134
parser.add_argument("--user", default=DEFAULT_USER, type=str, help="Lightning Studio username")
3235
parser.add_argument("--org", default=DEFAULT_ORG, type=str, help="Lightning Studio org")
3336
parser.add_argument("--teamspace", default=DEFAULT_TEAMSPACE, type=str, help="Lightning Studio teamspace")
3437
parser.add_argument(
3538
"--machine", type=str, default=DEFAULT_MACHINE, choices=["A10G", "T4", "CPU"], help="Machine type"
3639
)
40+
parser.add_argument("--make-args", type=str, default="", help="Makefile variables passed to the script")
3741

3842
args = parser.parse_args()
3943

@@ -45,10 +49,12 @@ def parse_args() -> BenchmarkArgs:
4549

4650
return BenchmarkArgs(
4751
pr_number=args.pr,
52+
branch=args.branch,
4853
user=args.user,
4954
org=args.org,
5055
teamspace=args.teamspace,
5156
machine=machine_map[args.machine],
57+
make_args=args.make_args,
5258
)
5359

5460

@@ -63,10 +69,12 @@ def __init__(self, config: BenchmarkArgs):
6369
raise ValueError("Only one of user or org must be provided.")
6470

6571
self.pr = config.pr_number
72+
self.branch = config.branch
6673
self.teamspace = config.teamspace
6774
self.user = config.user
6875
self.org = config.org
6976
self.machine = config.machine
77+
self.make_args = config.make_args
7078
self.studio: Optional[Studio] = None
7179

7280
def run(self) -> None:
@@ -88,15 +96,21 @@ def setup_studio(self) -> None:
8896
org=self.org,
8997
)
9098
self.studio.start(self.machine)
99+
cmd = "rm -rf lit*(N)"
100+
output, output_code = self.studio.run_with_exit_code(cmd)
101+
if output_code != 0:
102+
raise RuntimeError(f"Command failed:\n{cmd}\nExit code {output_code}:\n{output}")
91103

92104
def setup_litdata_pr(self) -> None:
93105
"""Set up the LitData PR in the studio."""
94106
assert self.studio is not None, "Studio is not set up"
107+
108+
# don't use `gh` cli, as it requires to login
95109
commands = [
96-
"rm -rf lit*",
97110
"git clone https://github.com/Lightning-AI/litData.git",
98111
"cd litData",
99-
f"gh pr checkout {self.pr}",
112+
f"git fetch origin pull/{self.pr}/head:{self.branch}",
113+
f"git checkout {self.branch}",
100114
"make setup",
101115
]
102116
final_command = " && ".join(commands)
@@ -111,7 +125,7 @@ def setup_and_run_litdata_benchmark(self) -> None:
111125
commands = [
112126
"git clone https://github.com/bhimrazy/litdata-benchmark.git",
113127
"cd litdata-benchmark",
114-
"make benchmark",
128+
f"make benchmark {self.make_args}",
115129
]
116130
final_command = " && ".join(commands)
117131
print(f"Running command: {final_command}")

.github/workflows/ci-benchmark.yml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ permissions:
1111
jobs:
1212
reply-to-benchmark:
1313
if: |
14-
github.event.comment.body == '@benchmark' &&
14+
startsWith(github.event.comment.body, '@benchmark') &&
1515
github.event.issue.pull_request &&
1616
(
1717
github.event.comment.user.login == 'tchaton' ||
@@ -24,6 +24,16 @@ jobs:
2424
runs-on: ubuntu-latest
2525
steps:
2626
- uses: actions/checkout@v4
27+
- name: Extract make args
28+
id: extract
29+
uses: actions/github-script@v7
30+
with:
31+
script: |
32+
const fullComment = context.payload.comment.body;
33+
const parts = fullComment.trim().split(/\s+/);
34+
const makeargs = parts.slice(1).join(' '); // remove "@benchmark" and keep rest
35+
core.setOutput("make_args", makeargs);
36+
2737
- name: Reply to PR comment and save ID
2838
id: comment
2939
uses: actions/github-script@v7
@@ -35,6 +45,13 @@ jobs:
3545
const username = context.payload.comment.user.login;
3646
const prNumber = context.payload.issue.number;
3747
48+
const pr = await github.rest.pulls.get({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
pull_number: context.payload.issue.number,
52+
});
53+
const branch = pr.data.head.ref;
54+
3855
// Replace placeholders
3956
const reply = replyTemplate
4057
.replace(/{{username}}/g, username)
@@ -49,12 +66,19 @@ jobs:
4966
5067
core.setOutput("comment_id", response.data.id);
5168
core.setOutput("prNumber", prNumber);
69+
core.setOutput("branch", branch);
5270
core.setOutput("username", username);
5371
5472
- name: run python
5573
run: |
5674
pip install -U lightning-sdk
57-
python .github/benchmark/benchmark.py --pr ${{ steps.comment.outputs.prNumber }}
75+
echo '"pr number: ${{ steps.comment.outputs.prNumber }}"; "branch: ${{ steps.comment.outputs.branch }}"'
76+
echo "make-args: ${{steps.extract.outputs.make_args}}"
77+
python .github/benchmark/benchmark.py \
78+
--pr "${{ steps.comment.outputs.prNumber }}" \
79+
--branch "${{ steps.comment.outputs.branch }}" \
80+
--make-args "${{ steps.extract.outputs.make_args }}" \
81+
2> error.txt || true
5882
env: # the following values are parsed from the repository secrets
5983
LIGHTNING_USER_ID: ${{ secrets.LIGHTNING_USER_ID }}
6084
LIGHTNING_API_KEY: ${{ secrets.LIGHTNING_API_KEY }}
@@ -67,11 +91,19 @@ jobs:
6791
with:
6892
script: |
6993
const fs = require('fs');
70-
const path = 'result.md';
71-
const reply = fs.readFileSync(path, 'utf8');
72-
7394
const comment_id = Number(process.env.COMMENT_ID);
74-
const updated_body = `Hi @${process.env.USERNAME}!\n\n- Benchmarking output:\n\n${reply}\n\n\ncc: @tchaton @deependujha @bhimrazy`;
95+
96+
let reply = '';
97+
if (fs.existsSync('result.md')) {
98+
reply = fs.readFileSync('result.md', 'utf8');
99+
} else if (fs.existsSync('error.txt') && fs.readFileSync('error.txt', 'utf8').trim().length > 0) {
100+
const err = fs.readFileSync('error.txt', 'utf8');
101+
reply = `❌ **Benchmark failed**\n\n\`\`\`\n${err}\n\`\`\``;
102+
} else {
103+
reply = '❌ Benchmark completed, but can\'t find `result.md` and `error.txt` file. Something went wrong.';
104+
}
105+
106+
const updated_body = `Hi @${process.env.USERNAME}!\n\n${reply}\n\ncc: @tchaton @deependujha @bhimrazy`;
75107
76108
await github.rest.issues.updateComment({
77109
owner: context.repo.owner,

.github/workflows/ci-testing.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
- name: Install package & dependencies
3838
run: |
3939
pip --version
40+
pip install -U lightning-sdk
4041
pip install -e ".[extras]" -r requirements/test.txt -U -q --find-links $TORCH_URL
4142
pip list
4243

0 commit comments

Comments
 (0)