Skip to content

Commit

Permalink
Install dependencies in yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
saileshd1402 committed Dec 2, 2024
1 parent e345916 commit 4c135d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test-example-notebooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ jobs:
kubernetes-version: ${{ matrix.kubernetes-version }}
python-version: ${{ matrix.python-version }}

- name: Install Python Dependencies
run: |
pip install papermill==2.6.0 jupyter==1.1.1 ipykernel==6.29.5
- name: Run Jupyter Notebook with Papermill
shell: bash
run: |
./scripts/run-notebook.sh \
-i ./examples/pytorch/image-classification/create-pytorchjob.ipynb \
-o ./examples/pytorch/image-classification/create-pytorchjob-output.ipynb \
-p "namespace default" \
-d jupyter==1.1.1 -d ipykernel==6.29.5 -d papermill==2.6.0 \
-k ./sdk/python
33 changes: 3 additions & 30 deletions scripts/run-notebook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@ NOTEBOOK_OUTPUT=""
PAPERMILL_PARAMS=()
PAPERMILL_PARAM_YAML=""
TRAINING_PYTHON_SDK="git+https://github.com/kubeflow/training-operator.git#subdirectory=sdk/python"
PYTHON_DEPENDENCIES=()
PYTHON_REQUIREMENTS_FILE=""

usage() {
echo "Usage: $0 -i <input_notebook> -o <output_notebook> [-p \"<param> <value>\"...] [-y <params.yaml>] [-d <package>==<version>...] [-r <requirements.txt>]"
echo "Usage: $0 -i <input_notebook> -o <output_notebook> [-p \"<param> <value>\"...] [-y <params.yaml>]"
echo "Options:"
echo " -i Input notebook (required)"
echo " -o Output notebook (required)"
echo " -p Papermill parameters (optional), pass param name and value pair (in quotes whitespace separated)"
echo " -y Papermill parameters YAML file (optional)"
echo " -k Kubeflow Training Operator Python SDK (optional)"
echo " -d Python dependencies args (optional)"
echo " -r Python dependencies requirements file (optional)"
echo " -h Show this help message"
echo "NOTE: papermill, jupyter and ipykernel are required Python dependencies to run Notebooks. Dependencies can be passed through -d or -r"
echo "NOTE: papermill, jupyter and ipykernel are required Python dependencies to run Notebooks"
exit 1
}

Expand All @@ -46,8 +42,6 @@ while getopts "i:o:y:p:k:r:d:h:" opt; do
p) PAPERMILL_PARAMS+=("$OPTARG") ;; # -p for papermill parameters
y) PAPERMILL_PARAM_YAML="$OPTARG" ;; # -y for papermill parameter yaml path
k) TRAINING_PYTHON_SDK="$OPTARG" ;; # -k for training operator python sdk
d) PYTHON_DEPENDENCIES+=("$OPTARG") ;; # -d for passing python dependencies as args
r) PYTHON_REQUIREMENTS_FILE="$OPTARG" ;; # -r for passing python dependencies as requirements file
h) usage ;; # -h for help (usage)
*) usage; exit 1 ;;
esac
Expand All @@ -58,26 +52,6 @@ if [ -z "$NOTEBOOK_INPUT" ] || [ -z "$NOTEBOOK_OUTPUT" ]; then
exit 1
fi

# Check if we need to install dependencies
if [ ${#PYTHON_DEPENDENCIES[@]} -gt 0 ] || [ -n "$PYTHON_REQUIREMENTS_FILE" ]; then
pip_install_cmd="pip install"

for dep in "${PYTHON_DEPENDENCIES[@]}"; do
pip_install_cmd="$pip_install_cmd $dep"
done

if [ -n "$PYTHON_REQUIREMENTS_FILE" ]; then
pip_install_cmd="$pip_install_cmd -r $PYTHON_REQUIREMENTS_FILE"
fi

echo "Installing Dependencies: $pip_install_cmd"
eval "$pip_install_cmd"
if [ $? -ne 0 ]; then
echo "Error: Failed to install dependencies." >&2
exit 1
fi
fi

papermill_cmd="papermill $NOTEBOOK_INPUT $NOTEBOOK_OUTPUT -p training_python_sdk $TRAINING_PYTHON_SDK"
# Add papermill parameters (param name and value)
for param in "${PAPERMILL_PARAMS[@]}"; do
Expand All @@ -88,9 +62,8 @@ if [ -n "$PAPERMILL_PARAM_YAML" ]; then
papermill_cmd="$papermill_cmd -y $PAPERMILL_PARAM_YAML"
fi

# Check if papermill is installed
if ! command -v papermill &> /dev/null; then
echo "Error: papermill is not installed. Please install papermill to proceed. Python dependencies can be passed through -d or -r args"
echo "Error: papermill is not installed. Please install papermill to proceed."
exit 1
fi

Expand Down

0 comments on commit 4c135d5

Please sign in to comment.