Skip to content

Commit a0b67c5

Browse files
@Snehil-Shah: refactor to allow arbitrary args to experiments (#885)
Running experiments for #854, an amazing work contributed by @Snehil-Shah. --------- Signed-off-by: Snehil Shah <[email protected]> Co-authored-by: Snehil Shah <[email protected]>
1 parent 6ac8f58 commit a0b67c5

File tree

8 files changed

+324
-235
lines changed

8 files changed

+324
-235
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ RUN apt-get update && \
6565
COPY . /experiment
6666
WORKDIR /experiment
6767
RUN /venv/bin/pip install --disable-pip-version-check -r requirements.txt
68-
ENTRYPOINT ["./report/docker_run.sh"]
68+
ENTRYPOINT ["/venv/bin/python3", "./report/docker_run.py"]

ci/ci_trial_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def exec_command_from_github(pull_request_number):
6868

6969
# Set the branch so that the trial_build builds the projects from the PR
7070
# branch.
71-
command.extend(['-p', str(pull_request_number)])
71+
command = ['-p', str(pull_request_number)] + command
7272
command = [c for c in command if c]
7373
logging.info('Command: %s.', command)
7474
return request_pr_exp.main(command)

ci/k8s/large-pr-exp.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ spec:
3030
# Modify the follow command to customize one-off experiments.
3131
# For benchmark sets that need more disk, increase the results volume
3232
# size too.
33-
command: ["/bin/bash", "report/docker_run.sh", "${GKE_EXP_BENCHMARK}", "${GKE_EXP_NAME}", "${GKE_EXP_FUZZING_TIMEOUT}", "ofg-pr", "${GKE_EXP_LLM}", "${GKE_EXP_DELAY}", "${GKE_EXP_LOCAL_INTROSPECTOR}", "${GKE_EXP_NUM_SAMPLES}", "${GKE_EXP_LLM_FIX_LIMIT}", "${GKE_EXP_VARY_TEMPERATURE}", "${GKE_EXP_AGENT}"]
33+
command: [
34+
"/bin/bash",
35+
"-c",
36+
"/venv/bin/python3 report/docker_run.py --benchmark-set=${GKE_EXP_BENCHMARK} --frequency-label=${GKE_EXP_NAME} --run-timeout=${GKE_EXP_FUZZING_TIMEOUT} --sub-dir=ofg-pr --model=${GKE_EXP_LLM} --delay=${GKE_EXP_DELAY} --num-samples=${GKE_EXP_NUM_SAMPLES} --llm-fix-limit=${GKE_EXP_LLM_FIX_LIMIT} --max-round=${GKE_EXP_MAX_ROUND} --local-introspector=${GKE_EXP_LOCAL_INTROSPECTOR} --vary-temperature=${GKE_EXP_VARY_TEMPERATURE} --agent=${GKE_EXP_AGENT} --redirect-outs=${GKE_REDIRECT_OUTS} ${GKE_EXP_ADDITIONAL_ARGS}"
37+
]
3438
securityContext:
3539
privileged: true
3640
resources:
@@ -52,8 +56,6 @@ spec:
5256
value: 'us-west1'
5357
- name: GCB_BUILDPOOL_NAME
5458
value: projects/oss-fuzz/locations/us-west1/workerPools/buildpool-large-pr
55-
- name: REDIRECT_OUTS
56-
value: '${GKE_REDIRECT_OUTS}'
5759
# imagePullSecrets:
5860
# - name: oss-fuzz-base-artifect
5961
volumes:

ci/k8s/pr-exp.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ spec:
3131
# Modify the follow command to customize one-off experiments.
3232
# For benchmark sets that need more disk, increase the results volume
3333
# size too.
34-
command: ["/bin/bash", "report/docker_run.sh", "${GKE_EXP_BENCHMARK}", "${GKE_EXP_NAME}", "${GKE_EXP_FUZZING_TIMEOUT}", "ofg-pr", "${GKE_EXP_LLM}", "${GKE_EXP_DELAY}", "${GKE_EXP_LOCAL_INTROSPECTOR}", "${GKE_EXP_NUM_SAMPLES}", "${GKE_EXP_LLM_FIX_LIMIT}", "${GKE_EXP_VARY_TEMPERATURE}", "${GKE_EXP_AGENT}", "${GKE_EXP_MAX_ROUND}"]
34+
command: [
35+
"/bin/bash",
36+
"-c",
37+
"/venv/bin/python3 report/docker_run.py --benchmark-set=${GKE_EXP_BENCHMARK} --frequency-label=${GKE_EXP_NAME} --run-timeout=${GKE_EXP_FUZZING_TIMEOUT} --sub-dir=ofg-pr --model=${GKE_EXP_LLM} --delay=${GKE_EXP_DELAY} --num-samples=${GKE_EXP_NUM_SAMPLES} --llm-fix-limit=${GKE_EXP_LLM_FIX_LIMIT} --max-round=${GKE_EXP_MAX_ROUND} --local-introspector=${GKE_EXP_LOCAL_INTROSPECTOR} --vary-temperature=${GKE_EXP_VARY_TEMPERATURE} --agent=${GKE_EXP_AGENT} --redirect-outs=${GKE_REDIRECT_OUTS} ${GKE_EXP_ADDITIONAL_ARGS}"
38+
]
3539
securityContext:
3640
privileged: true
3741
resources:
@@ -53,8 +57,6 @@ spec:
5357
value: 'us-west2'
5458
- name: GCB_BUILDPOOL_NAME
5559
value: projects/oss-fuzz/locations/us-west2/workerPools/buildpool-llm-agents
56-
- name: REDIRECT_OUTS
57-
value: '${GKE_REDIRECT_OUTS}'
5860
# imagePullSecrets:
5961
# - name: oss-fuzz-base-artifect
6062
volumes:
@@ -82,4 +84,4 @@ spec:
8284
values: [0]
8385
- action: Ignore # One of: Ignore, FailJob, Count
8486
onPodConditions:
85-
- type: DisruptionTarget # Indicates Pod disruption
87+
- type: DisruptionTarget # Indicates Pod disruption

ci/request_pr_exp.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
python -m report.request_pr_exp -p <PR-ID> -n <YOUR-NAME>
1919
e.g.,
2020
python -m report.request_pr_exp -p 73 -n dg
21+
22+
You can also pass arbitrary flags to experiments after -- separator:
23+
python -m report.request_pr_exp -p 73 -n dg -- --context --debug
2124
"""
2225

2326
import argparse
@@ -204,7 +207,10 @@ def _parse_args(cmd) -> argparse.Namespace:
204207
action='store_true',
205208
default=False,
206209
help='Redirects experiments stdout/stderr to file')
207-
args = parser.parse_args(cmd)
210+
211+
# Allow piping arbitrary args to run_all_experiments.py
212+
args, additional_args = parser.parse_known_args(cmd)
213+
args.additional_args = additional_args
208214

209215
assert os.path.isfile(
210216
args.gke_template), (f'GKE template does not exist: {args.gke_template}')
@@ -232,6 +238,10 @@ def _parse_args(cmd) -> argparse.Namespace:
232238
if (args.max_round == 100 and
233239
any(args.name_suffix.startswith(suffix) for suffix in ['ascc-', 'dgk-'])):
234240
args.max_round = 10
241+
242+
if args.additional_args:
243+
logging.info("Additional args: %s", args.additional_args)
244+
235245
return args
236246

237247

@@ -342,15 +352,18 @@ def _fill_template(args: argparse.Namespace) -> str:
342352
exp_env_vars['GKE_EXP_NAME'] = args.experiment_name
343353
exp_env_vars['GKE_EXP_REQ_CPU'] = args.request_cpus
344354
exp_env_vars['GKE_EXP_REQ_MEM'] = f'{args.request_memory}Gi'
345-
if args.local_introspector:
346-
exp_env_vars['GKE_EXP_LOCAL_INTROSPECTOR'] = 'true'
355+
exp_env_vars[
356+
'GKE_EXP_LOCAL_INTROSPECTOR'] = f'{args.local_introspector}'.lower()
347357
exp_env_vars['GKE_EXP_NUM_SAMPLES'] = f'{args.num_samples}'
348358
exp_env_vars['GKE_EXP_LLM_FIX_LIMIT'] = f'{args.llm_fix_limit}'
349359
exp_env_vars['GKE_EXP_VARY_TEMPERATURE'] = f'{args.vary_temperature}'.lower()
350360
exp_env_vars['GKE_EXP_AGENT'] = f'{args.agent}'.lower()
351-
exp_env_vars['GKE_REDIRECT_OUTS'] = 'true' if args.redirect_outs else ''
361+
exp_env_vars['GKE_REDIRECT_OUTS'] = f'{args.redirect_outs}'.lower()
352362
exp_env_vars['GKE_EXP_MAX_ROUND'] = args.max_round
353363

364+
# Add additional args as a space-separated string
365+
exp_env_vars['GKE_EXP_ADDITIONAL_ARGS'] = ' '.join(args.additional_args)
366+
354367
with open(args.gke_template, 'r') as file:
355368
yaml_template = file.read()
356369

report/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## Trends Report
1313

14-
1. After each experiment is finished, `docker_run.sh` uploads a summary json
14+
1. After each experiment is finished, `docker_run.py` uploads a summary json
1515
file to `gs://oss-fuzz-gcb-experiment-run-logs/trend-reports/`.
1616
2. Upload of the summary json triggers a
1717
[Cloud Run Function](https://pantheon.corp.google.com/functions/details/us-central1/llm-trends-report-index?env=gen1&project=oss-fuzz)

0 commit comments

Comments
 (0)