Skip to content

Commit

Permalink
Bug fix: determine agbench_base_dir based on method of install
Browse files Browse the repository at this point in the history
and use ENV $VENV_BASE_DIR for venv setup
  • Loading branch information
suzhoum committed Nov 12, 2023
1 parent ba59b35 commit e270d3c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 18 deletions.
21 changes: 12 additions & 9 deletions src/autogluon/bench/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ FROM $AG_BENCH_BASE_IMAGE

ENV DEBIAN_FRONTEND=noninteractive
ENV RUNNING_IN_DOCKER=true
ENV AGBENCH_BASE=src/autogluon/bench/

# Install essential packages and Python 3.9
RUN apt-get update && \
Expand All @@ -25,37 +24,41 @@ RUN apt-get install -y python3-pip unzip curl git pciutils && \

# Application-specific steps
ARG AG_BENCH_VERSION
ARG AG_BENCH_BASE_DIR
ARG CDK_DEPLOY_REGION
ARG FRAMEWORK_PATH
ARG GIT_URI
ARG GIT_BRANCH
ARG AMLB_FRAMEWORK
ARG AMLB_USER_DIR

ENV AG_BENCH_BASE_DIR=${AG_BENCH_BASE_DIR}
ENV VENV_BASE_DIR="."

WORKDIR /app/

# Copying necessary files for autogluon-bench package
COPY . /app/
COPY ${AGBENCH_BASE}entrypoint.sh /app/
COPY ${AGBENCH_BASE}custom_configs /app/custom_configs/
# Copying files for installing autogluon.bench from source, user needs to at the root of autogluon.bench repo as we need pyproject.toml
COPY . .
COPY ${AG_BENCH_BASE_DIR}/entrypoint.sh .
COPY ${AG_BENCH_BASE_DIR}/custom_configs custom_configs/

# check if autogluon.bench version contains "dev" tag
RUN if echo "$AG_BENCH_VERSION" | grep -q "dev"; then \
# install from local source
pip install /app/; \
pip install .; \
else \
pip install autogluon.bench==$AG_BENCH_VERSION; \
fi

RUN chmod +x entrypoint.sh \
&& if echo "$FRAMEWORK_PATH" | grep -q -E "tabular|timeseries"; then \
if [ -n "$AMLB_USER_DIR" ]; then \
bash ${AGBENCH_BASE}${FRAMEWORK_PATH}setup.sh $GIT_URI $GIT_BRANCH "/home" $AMLB_FRAMEWORK $AMLB_USER_DIR; \
bash ${AG_BENCH_BASE_DIR}/${FRAMEWORK_PATH}/setup.sh $GIT_URI $GIT_BRANCH $VENV_BASE_DIR $AMLB_FRAMEWORK $AMLB_USER_DIR; \
else \
bash ${AGBENCH_BASE}${FRAMEWORK_PATH}setup.sh $GIT_URI $GIT_BRANCH "/home" $AMLB_FRAMEWORK; \
bash ${AG_BENCH_BASE_DIR}/${FRAMEWORK_PATH}/setup.sh $GIT_URI $GIT_BRANCH $VENV_BASE_DIR $AMLB_FRAMEWORK; \
fi; \
elif echo "$FRAMEWORK_PATH" | grep -q "multimodal"; then \
bash ${AGBENCH_BASE}${FRAMEWORK_PATH}setup.sh $GIT_URI $GIT_BRANCH "/home" $AG_BENCH_VERSION; \
bash ${AG_BENCH_BASE_DIR}/${FRAMEWORK_PATH}/setup.sh $GIT_URI $GIT_BRANCH $VENV_BASE_DIR $AG_BENCH_VERSION; \
fi \
&& echo "CDK_DEPLOY_REGION=$CDK_DEPLOY_REGION" >> /etc/environment

Expand Down
8 changes: 8 additions & 0 deletions src/autogluon/bench/cloud/aws/batch_stack/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ def find_project_root_or_fallback(start_dir: str, root_identifier: str = "pyproj
return start_dir


# when pip installed, project_root is at $site_package_path/src/autogluon/bench agbench_base_dir should be ./
# when installed from source, project_root is at ./, agbench_base_dir should be ./src/autogluon/bench
with importlib.resources.path("autogluon.bench", "Dockerfile") as file_path:
docker_base_dir = os.path.dirname(file_path)
project_root = find_project_root_or_fallback(docker_base_dir)
docker_path = os.path.relpath(file_path, project_root)
agbench_base_dir = os.path.dirname(docker_path)
if agbench_base_dir == "":
agbench_base_dir = "."

with importlib.resources.path("autogluon.bench.cloud.aws.batch_stack.lambdas", "lambda_function.py") as file_path:
lambda_script_dir = os.path.dirname(file_path)
Expand Down Expand Up @@ -174,6 +179,8 @@ def __init__(self, scope: Construct, id: str, static_stack: StaticResourceStack,
# Currently CDK can only push to the default repo aws-cdk/assets
# https://github.com/aws/aws-cdk/issues/12597
# TODO: use https://github.com/cdklabs/cdk-docker-image-deployment

logger.info(f"Building Dockerfile at {docker_path} with context at {project_root}")
docker_image_asset = ecr_assets.DockerImageAsset(
self,
f"{prefix}-ecr-docker-image-asset",
Expand All @@ -182,6 +189,7 @@ def __init__(self, scope: Construct, id: str, static_stack: StaticResourceStack,
follow_symlinks=core.SymlinkFollowMode.ALWAYS,
build_args={
"AG_BENCH_BASE_IMAGE": os.environ["AG_BENCH_BASE_IMAGE"],
"AG_BENCH_BASE_DIR": agbench_base_dir,
"AG_BENCH_VERSION": os.getenv("AG_BENCH_VERSION", "latest"),
"CDK_DEPLOY_REGION": os.environ["CDK_DEPLOY_REGION"],
"FRAMEWORK_PATH": os.environ["FRAMEWORK_PATH"],
Expand Down
3 changes: 1 addition & 2 deletions src/autogluon/bench/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash

echo "Running hardware utilization monitoring in the background..."
${AGBENCH_BASE}utils/hardware_utilization.sh &

${AG_BENCH_BASE_DIR}/utils/hardware_utilization.sh &
agbench run $config_file --skip-setup
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ def run(
None
"""
if os.environ.get("RUNNING_IN_DOCKER", False):
venv_base_dir = "/home/"
venv_base_dir = os.environ["VENV_BASE_DIR"]
else:
venv_base_dir = self.benchmark_dir
PY_EXC_PATH = os.path.join(venv_base_dir, ".venv/bin/python")

exec_path = os.path.abspath(os.path.dirname(__file__)) + "/exec.py"
exec_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "exec.py")
logger.info(f"Executing {exec_path} under {PY_EXC_PATH}")
command = [
PY_EXC_PATH,
exec_path,
Expand Down
1 change: 0 additions & 1 deletion src/autogluon/bench/frameworks/tabular/exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ if [ -n "$fold" ]; then
fi

if [ -n "$user_dir" ]; then
cp -r $user_dir $venv_base_dir
amlb_args+=" -u $user_dir"
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def run(
"""

if os.environ.get("RUNNING_IN_DOCKER", False):
venv_base_dir = "/home/"
venv_base_dir = os.environ["VENV_BASE_DIR"]
else:
venv_base_dir = self.benchmark_dir

Expand Down
1 change: 0 additions & 1 deletion src/autogluon/bench/frameworks/timeseries/exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ if [ -n "$fold" ]; then
fi

if [ -n "$user_dir" ]; then
cp -r $user_dir $venv_base_dir
amlb_args+=" -u $user_dir"
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run(
None
"""
if os.environ.get("RUNNING_IN_DOCKER", False):
venv_base_dir = "/home/"
venv_base_dir = os.environ["VENV_BASE_DIR"]
else:
venv_base_dir = self.benchmark_dir

Expand Down
2 changes: 1 addition & 1 deletion src/autogluon/bench/runbenchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def run(
# setting environment variables for docker build ARG
os.environ["AG_BENCH_VERSION"] = agbench_version

os.environ["FRAMEWORK_PATH"] = f"frameworks/{module}/"
os.environ["FRAMEWORK_PATH"] = f"frameworks/{module}"

if module in AMLB_DEPENDENT_MODULES:
os.environ["AMLB_FRAMEWORK"] = configs["framework"]
Expand Down

0 comments on commit e270d3c

Please sign in to comment.