olmocr/scripts/run_benchmark.sh

98 lines
3.4 KiB
Bash
Raw Normal View History

2025-05-29 17:08:05 +00:00
#!/bin/bash
set -e
2025-05-29 17:12:41 +00:00
# Use conda environment Python if available, otherwise use system Python
if [ -n "$CONDA_PREFIX" ]; then
PYTHON="$CONDA_PREFIX/bin/python"
echo "Using conda Python from: $CONDA_PREFIX"
else
PYTHON="python"
echo "Warning: No conda environment detected, using system Python"
fi
2025-05-29 17:08:05 +00:00
# Get version from version.py
2025-05-29 17:12:41 +00:00
VERSION=$($PYTHON -c 'import olmocr.version; print(olmocr.version.VERSION)')
2025-05-29 17:08:05 +00:00
echo "OlmOCR version: $VERSION"
# Get first 10 characters of git hash
GIT_HASH=$(git rev-parse HEAD | cut -c1-10)
echo "Git hash: $GIT_HASH"
# Get current git branch name
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Git branch: $GIT_BRANCH"
2025-05-29 17:08:05 +00:00
# Create full image tag
IMAGE_TAG="olmocr-benchmark-${VERSION}-${GIT_HASH}"
echo "Building Docker image with tag: $IMAGE_TAG"
# Build the Docker image
echo "Building Docker image..."
docker build --platform linux/amd64 -f ./Dockerfile -t $IMAGE_TAG .
2025-05-29 17:18:12 +00:00
# Get Beaker username
BEAKER_USER=$(beaker account whoami --format json | jq -r '.[0].name')
echo "Beaker user: $BEAKER_USER"
2025-05-29 17:08:05 +00:00
# Push image to beaker
echo "Pushing image to Beaker..."
beaker image create --workspace ai2/oe-data-pdf --name $IMAGE_TAG $IMAGE_TAG
# Create Python script to run beaker experiment
cat << 'EOF' > /tmp/run_benchmark_experiment.py
import sys
2025-05-29 17:12:41 +00:00
from beaker import Beaker, ExperimentSpec, TaskSpec, TaskContext, ResultSpec, TaskResources, ImageSource, Priority, Constraints
2025-05-29 17:08:05 +00:00
# Get image tag, beaker user, git branch, and git hash from command line
2025-05-29 17:08:05 +00:00
image_tag = sys.argv[1]
2025-05-29 17:18:12 +00:00
beaker_user = sys.argv[2]
git_branch = sys.argv[3]
git_hash = sys.argv[4]
2025-05-29 17:08:05 +00:00
# Initialize Beaker client
2025-05-29 17:20:32 +00:00
b = Beaker.from_env(default_workspace="ai2/olmocr")
2025-05-29 17:08:05 +00:00
# Create experiment spec
experiment_spec = ExperimentSpec(
description=f"OlmOCR Benchmark Run - Branch: {git_branch}, Commit: {git_hash}",
2025-05-29 17:08:05 +00:00
budget="ai2/oe-data",
tasks=[
TaskSpec(
name="olmocr-benchmark",
2025-05-29 17:18:12 +00:00
image=ImageSource(beaker=f"{beaker_user}/{image_tag}"),
2025-05-29 17:08:05 +00:00
command=[
"bash", "-c",
" && ".join([
2025-05-29 17:38:00 +00:00
"git clone https://huggingface.co/datasets/allenai/olmOCR-bench",
"cd olmOCR-bench && git lfs pull && cd ..",
2025-05-29 17:58:11 +00:00
"python -m olmocr.pipeline ./localworkspace --markdown --pdfs ./olmOCR-bench/bench_data/pdfs/**/*.pdf",
2025-05-29 20:32:25 +00:00
"python olmocr/bench/scripts/workspace_to_bench.py localworkspace/ olmOCR-bench/bench_data/olmocr --bench-path ./olmOCR-bench/",
2025-05-29 17:08:05 +00:00
"python -m olmocr.bench.benchmark --dir ./olmOCR-bench/bench_data"
])
],
2025-05-29 17:12:41 +00:00
context=TaskContext(
priority=Priority.normal,
preemptible=True,
),
2025-05-29 17:08:05 +00:00
resources=TaskResources(gpu_count=1),
2025-05-29 17:21:58 +00:00
constraints=Constraints(cluster=["ai2/ceres-cirrascale", "ai2/jupiter-cirrascale-2"]),
2025-05-29 17:12:41 +00:00
result=ResultSpec(path="/noop-results"),
2025-05-29 17:08:05 +00:00
)
],
)
# Create the experiment
2025-05-29 17:20:32 +00:00
experiment = b.experiment.create(spec=experiment_spec, workspace="ai2/olmocr")
2025-05-29 17:08:05 +00:00
print(f"Created experiment: {experiment.id}")
print(f"View at: https://beaker.org/ex/{experiment.id}")
EOF
# Run the Python script to create the experiment
echo "Creating Beaker experiment..."
$PYTHON /tmp/run_benchmark_experiment.py $IMAGE_TAG $BEAKER_USER $GIT_BRANCH $GIT_HASH
2025-05-29 17:08:05 +00:00
# Clean up temporary file
rm /tmp/run_benchmark_experiment.py
echo "Benchmark experiment submitted successfully!"