Skip to content

Commit 1e84d89

Browse files
committed
Run PR check for guided notebooks
1 parent f100ba1 commit 1e84d89

8 files changed

+153
-60
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"cell_type": "code",
3+
"execution_count": null,
4+
"metadata": {},
5+
"outputs": [],
6+
"source": [
7+
"@ray.remote\n",
8+
"def get_minio_run_config():\n",
9+
" import s3fs\n",
10+
" import pyarrow\n",
11+
" s3_fs = s3fs.S3FileSystem(\n",
12+
" key = \"minio\",\n",
13+
" secret = \"minio123\",\n",
14+
" endpoint_url = \"http://minio-service.default.svc.cluster.local:9000\"\n",
15+
" )\n",
16+
" custom_fs = pyarrow.fs.PyFileSystem(pyarrow.fs.FSSpecHandler(s3_fs))\n",
17+
" run_config = ray.train.RunConfig(storage_path='training', storage_filesystem=custom_fs)\n",
18+
" return run_config"
19+
]
20+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"cell_type": "code",
3+
"execution_count": null,
4+
"metadata": {},
5+
"outputs": [],
6+
"source": [
7+
"from time import sleep\n",
8+
"\n",
9+
"finished = False\n",
10+
"while not finished:\n",
11+
" sleep(5)\n",
12+
" status = client.get_job_status(submission_id)\n",
13+
" finished = (status == \"SUCCEEDED\" or status == \"FAILED\" or status == \"STOPPED\")\n",
14+
" print(status)\n",
15+
"print(\"Job status \" + status)\n",
16+
"print(\"Logs: \")\n",
17+
"print(client.get_job_logs(submission_id))\n",
18+
"assert status == \"SUCCEEDED\", \"Job failed or was stopped!\""
19+
]
20+
}

.github/workflows/e2e_tests.yaml renamed to .github/workflows/guided_notebook_tests.yaml

+79-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: e2e
1+
name: Guided notebooks tests
22

33
on:
44
pull_request:
@@ -27,6 +27,10 @@ concurrency:
2727
env:
2828
CODEFLARE_OPERATOR_IMG: "quay.io/project-codeflare/codeflare-operator:dev"
2929

30+
permissions:
31+
id-token: write # This is required for requesting the JWT
32+
contents: read
33+
3034
jobs:
3135
kubernetes:
3236

@@ -76,6 +80,8 @@ jobs:
7680

7781
- name: Install NVidia GPU operator for KinD
7882
uses: ./common/github-actions/nvidia-gpu-operator
83+
with:
84+
enable-time-slicing: 'true'
7985

8086
- name: Deploy CodeFlare stack
8187
id: deploy
@@ -88,6 +94,11 @@ jobs:
8894
kubectl wait --timeout=120s --for=condition=Available=true deployment -n openshift-operators codeflare-operator-manager
8995
cd ..
9096
97+
- name: Install MINIO
98+
run: |
99+
kubectl apply -f ./tests/e2e/minio_deployment.yaml
100+
kubectl wait --timeout=120s --for=condition=Available=true deployment -n default minio
101+
91102
- name: Add user to KinD
92103
uses: ./common/github-actions/kind-add-user
93104
with:
@@ -113,46 +124,99 @@ jobs:
113124
kubectl create clusterrolebinding sdk-user-list-secrets --clusterrole=list-secrets --user=sdk-user
114125
kubectl config use-context sdk-user
115126
116-
- name: Run e2e tests
127+
- name: Setup Guided notebooks execution
117128
run: |
118-
export CODEFLARE_TEST_OUTPUT_DIR=${{ env.TEMP_DIR }}
119-
echo "CODEFLARE_TEST_OUTPUT_DIR=${CODEFLARE_TEST_OUTPUT_DIR}" >> $GITHUB_ENV
129+
echo "Installing papermill and dependencies..."
130+
pip install poetry papermill ipython ipykernel
131+
# Disable virtualenv due to problems using packaged in virtualenv in papermill
132+
poetry config virtualenvs.create false
120133
121-
set -euo pipefail
122-
pip install poetry
134+
echo "Installing SDK..."
123135
poetry install --with test,docs
124-
echo "Running e2e tests..."
125-
poetry run pytest -v -s ./tests/e2e -m 'kind and nvidia_gpu' > ${CODEFLARE_TEST_OUTPUT_DIR}/pytest_output.log 2>&1
136+
137+
- name: Run 0_basic_ray.ipynb
138+
run: |
139+
set -euo pipefail
140+
141+
# Remove login/logout cells, as KinD doesn't support authentication using token
142+
jq -r 'del(.cells[] | select(.source[] | contains("Create authentication object for user permissions")))' 0_basic_ray.ipynb > 0_basic_ray.ipynb.tmp && mv 0_basic_ray.ipynb.tmp 0_basic_ray.ipynb
143+
jq -r 'del(.cells[] | select(.source[] | contains("auth.logout()")))' 0_basic_ray.ipynb > 0_basic_ray.ipynb.tmp && mv 0_basic_ray.ipynb.tmp 0_basic_ray.ipynb
144+
# Run notebook
145+
# poetry run papermill 0_basic_ray.ipynb 0_basic_ray_out.ipynb --log-output --execution-timeout 600
146+
working-directory: demo-notebooks/guided-demos
147+
148+
- name: Run 1_cluster_job_client.ipynb
149+
run: |
150+
set -euo pipefail
151+
152+
# Remove login/logout cells, as KinD doesn't support authentication using token
153+
jq -r 'del(.cells[] | select(.source[] | contains("Create authentication object for user permissions")))' 1_cluster_job_client.ipynb > 1_cluster_job_client.ipynb.tmp && mv 1_cluster_job_client.ipynb.tmp 1_cluster_job_client.ipynb
154+
jq -r 'del(.cells[] | select(.source[] | contains("auth.logout()")))' 1_cluster_job_client.ipynb > 1_cluster_job_client.ipynb.tmp && mv 1_cluster_job_client.ipynb.tmp 1_cluster_job_client.ipynb
155+
# Replace async logs with waiting for job to finish, async logs don't work properly in papermill
156+
JOB_WAIT=$(jq -r '.' ${GITHUB_WORKSPACE}/.github/resources/wait_for_job_cell.json)
157+
jq --argjson job_wait "$JOB_WAIT" -r '(.cells[] | select(.source[] | contains("async for lines in client.tail_job_logs"))) |= $job_wait' 1_cluster_job_client.ipynb > 1_cluster_job_client.ipynb.tmp && mv 1_cluster_job_client.ipynb.tmp 1_cluster_job_client.ipynb
158+
# Run notebook
159+
# poetry run papermill 1_cluster_job_client.ipynb 1_cluster_job_client_out.ipynb --log-output --execution-timeout 1200
160+
working-directory: demo-notebooks/guided-demos
161+
162+
- name: Run 2_basic_interactive.ipynb
163+
run: |
164+
set -euo pipefail
165+
166+
# Remove login/logout cells, as KinD doesn't support authentication using token
167+
jq -r 'del(.cells[] | select(.source[] | contains("Create authentication object for user permissions")))' 2_basic_interactive.ipynb > 2_basic_interactive.ipynb.tmp && mv 2_basic_interactive.ipynb.tmp 2_basic_interactive.ipynb
168+
jq -r 'del(.cells[] | select(.source[] | contains("auth.logout()")))' 2_basic_interactive.ipynb > 2_basic_interactive.ipynb.tmp && mv 2_basic_interactive.ipynb.tmp 2_basic_interactive.ipynb
169+
# Rewrite cluster_uri() to local_client_url() to retrieve client URL available out of cluster, as the test is executed outside of cluster
170+
sed -i "s/cluster_uri()/local_client_url()/" 2_basic_interactive.ipynb
171+
# Set explicit namespace as SDK need it (currently) to resolve local queues
172+
sed -i "s/head_cpus=1,/head_cpus=1, namespace='default',/" 2_basic_interactive.ipynb
173+
# Add MINIO related modules to runtime environment
174+
sed -i "s/transformers/s3fs\\\\\", \\\\\"pyarrow\\\\\", \\\\\"transformers/" 2_basic_interactive.ipynb
175+
# Replace markdown cell with remote configuration for MINIO
176+
MINIO_CONFIG=$(jq -r '.' ${GITHUB_WORKSPACE}/.github/resources/minio_remote_config_cell.json)
177+
jq --argjson minio_config "$MINIO_CONFIG" -r '(.cells[] | select(.source[] | contains("Now that we are connected"))) |= $minio_config' 2_basic_interactive.ipynb > 2_basic_interactive.ipynb.tmp && mv 2_basic_interactive.ipynb.tmp 2_basic_interactive.ipynb
178+
# Configure persistent storage for Ray trainer
179+
sed -i -E "s/# run_config.*\)/, run_config=ray.get(get_minio_run_config.remote())/" 2_basic_interactive.ipynb
180+
# Run notebook
181+
poetry run papermill 2_basic_interactive.ipynb 2_basic_interactive_out.ipynb --log-output --execution-timeout 1200
126182
env:
127183
GRPC_DNS_RESOLVER: "native"
184+
working-directory: demo-notebooks/guided-demos
128185

129186
- name: Switch to kind-cluster context to print logs
130187
if: always() && steps.deploy.outcome == 'success'
131188
run: kubectl config use-context kind-cluster
132189

133-
- name: Print Pytest output log
190+
- name: Print debug info
134191
if: always() && steps.deploy.outcome == 'success'
135192
run: |
136-
echo "Printing Pytest output logs"
137-
cat ${CODEFLARE_TEST_OUTPUT_DIR}/pytest_output.log
193+
echo "Printing debug info"
194+
kubectl describe pods -n default
138195
139196
- name: Print CodeFlare operator logs
140197
if: always() && steps.deploy.outcome == 'success'
141198
run: |
142199
echo "Printing CodeFlare operator logs"
143-
kubectl logs -n openshift-operators --tail -1 -l app.kubernetes.io/name=codeflare-operator | tee ${CODEFLARE_TEST_OUTPUT_DIR}/codeflare-operator.log
200+
kubectl logs -n openshift-operators --tail -1 -l app.kubernetes.io/name=codeflare-operator | tee ${TEMP_DIR}/codeflare-operator.log
201+
202+
- name: Print Kueue operator logs
203+
if: always() && steps.deploy.outcome == 'success'
204+
run: |
205+
echo "Printing Kueue operator logs"
206+
KUEUE_CONTROLLER_POD=$(kubectl get pods -n kueue-system | grep kueue-controller | awk '{print $1}')
207+
kubectl logs -n kueue-system --tail -1 ${KUEUE_CONTROLLER_POD} | tee ${TEMP_DIR}/kueue.log
144208
145209
- name: Print KubeRay operator logs
146210
if: always() && steps.deploy.outcome == 'success'
147211
run: |
148212
echo "Printing KubeRay operator logs"
149-
kubectl logs -n ray-system --tail -1 -l app.kubernetes.io/name=kuberay | tee ${CODEFLARE_TEST_OUTPUT_DIR}/kuberay.log
213+
kubectl logs -n ray-system --tail -1 -l app.kubernetes.io/name=kuberay | tee ${TEMP_DIR}/kuberay.log
150214
151215
- name: Export all KinD pod logs
152216
uses: ./common/github-actions/kind-export-logs
153217
if: always() && steps.deploy.outcome == 'success'
154218
with:
155-
output-directory: ${CODEFLARE_TEST_OUTPUT_DIR}
219+
output-directory: ${TEMP_DIR}
156220

157221
- name: Upload logs
158222
uses: actions/upload-artifact@v4
@@ -161,4 +225,4 @@ jobs:
161225
name: logs
162226
retention-days: 10
163227
path: |
164-
${{ env.CODEFLARE_TEST_OUTPUT_DIR }}/**/*.log
228+
${{ env.TEMP_DIR }}/**/*.log

demo-notebooks/guided-demos/0_basic_ray.ipynb

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@
6262
"# The SDK will try to find the name of your default local queue based on the annotation \"kueue.x-k8s.io/default-queue\": \"true\" unless you specify the local queue manually below\n",
6363
"cluster = Cluster(ClusterConfiguration(\n",
6464
" name='raytest', \n",
65+
" head_cpus='500m',\n",
66+
" head_memory=2,\n",
6567
" head_gpus=0, # For GPU enabled workloads set the head_gpus and num_gpus\n",
6668
" num_gpus=0,\n",
6769
" num_workers=2,\n",
68-
" min_cpus=1,\n",
70+
" min_cpus='250m',\n",
6971
" max_cpus=1,\n",
7072
" min_memory=4,\n",
7173
" max_memory=4,\n",

demo-notebooks/guided-demos/1_cluster_job_client.ipynb

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@
4444
"# The SDK will try to find the name of your default local queue based on the annotation \"kueue.x-k8s.io/default-queue\": \"true\" unless you specify the local queue manually below\n",
4545
"cluster = Cluster(ClusterConfiguration(\n",
4646
" name='jobtest',\n",
47+
" head_cpus=1,\n",
48+
" head_memory=4,\n",
4749
" head_gpus=1, # For GPU enabled workloads set the head_gpus and num_gpus\n",
4850
" num_gpus=1,\n",
4951
" num_workers=2,\n",
50-
" min_cpus=1,\n",
52+
" min_cpus='250m',\n",
5153
" max_cpus=1,\n",
5254
" min_memory=4,\n",
5355
" max_memory=4,\n",

demo-notebooks/guided-demos/2_basic_interactive.ipynb

+17-5
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@
6060
"cluster_name = \"interactivetest\"\n",
6161
"cluster = Cluster(ClusterConfiguration(\n",
6262
" name=cluster_name,\n",
63+
" head_cpus=1,\n",
64+
" head_memory=4,\n",
6365
" head_gpus=1, # For GPU enabled workloads set the head_gpus and num_gpus\n",
6466
" num_gpus=1,\n",
6567
" num_workers=2,\n",
66-
" min_cpus=2,\n",
67-
" max_cpus=2,\n",
68-
" min_memory=8,\n",
69-
" max_memory=8,\n",
68+
" min_cpus='250m',\n",
69+
" max_cpus=1,\n",
70+
" min_memory=4,\n",
71+
" max_memory=4,\n",
7072
" image=\"quay.io/rhoai/ray:2.23.0-py39-cu121\",\n",
7173
" write_to_file=False, # When enabled Ray Cluster yaml files are written to /HOME/.codeflare/resources \n",
7274
" # local_queue=\"local-queue-name\" # Specify the local queue manually\n",
@@ -251,7 +253,17 @@
251253
"\n",
252254
" ray_trainer = TorchTrainer(\n",
253255
" train_func,\n",
254-
" scaling_config=ScalingConfig(num_workers=3, use_gpu=True),\n",
256+
" scaling_config=ScalingConfig(\n",
257+
" # num_workers = number of worker nodes with the ray head node included\n",
258+
" num_workers=3,\n",
259+
" use_gpu=True,\n",
260+
" resources_per_worker={\n",
261+
" \"CPU\": 1,\n",
262+
" },\n",
263+
" trainer_resources={\n",
264+
" \"CPU\": 0,\n",
265+
" }\n",
266+
" )\n",
255267
" # Configure persistent storage that is accessible across \n",
256268
" # all worker nodes.\n",
257269
" # Uncomment and update the RunConfig below to include your storage details.\n",

demo-notebooks/guided-demos/mnist_fashion.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,16 @@ def train_func_distributed():
7878
trainer = TorchTrainer(
7979
train_func_distributed,
8080
scaling_config=ScalingConfig(
81-
num_workers=3, use_gpu=use_gpu
82-
), # num_workers = number of worker nodes with the ray head node included
81+
# num_workers = number of worker nodes with the ray head node included
82+
num_workers=3,
83+
use_gpu=use_gpu,
84+
resources_per_worker={
85+
"CPU": 1,
86+
},
87+
trainer_resources={
88+
"CPU": 0,
89+
},
90+
),
8391
)
8492

8593
results = trainer.fit()

tests/e2e/minio_deployment.yaml

+1-36
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ spec:
8888
mountPath: /data
8989
subPath: minio
9090
terminationMessagePolicy: File
91-
image: >-
92-
quay.io/minio/minio:RELEASE.2024-06-22T05-26-45Z
93-
# In case of disconnected environment, use image digest instead of tag
94-
# For example : <mirror_registry_endpoint>/minio/minio@sha256:6b3abf2f59286b985bfde2b23e37230b466081eda5dccbf971524d54c8e406b5
91+
image: quay.io/minio/minio:RELEASE.2024-06-22T05-26-45Z
9592
args:
9693
- server
9794
- /data
@@ -129,35 +126,3 @@ spec:
129126
sessionAffinity: None
130127
selector:
131128
app: minio
132-
---
133-
kind: Route
134-
apiVersion: route.openshift.io/v1
135-
metadata:
136-
name: minio-api
137-
spec:
138-
to:
139-
kind: Service
140-
name: minio-service
141-
weight: 100
142-
port:
143-
targetPort: api
144-
wildcardPolicy: None
145-
tls:
146-
termination: edge
147-
insecureEdgeTerminationPolicy: Redirect
148-
---
149-
kind: Route
150-
apiVersion: route.openshift.io/v1
151-
metadata:
152-
name: minio-ui
153-
spec:
154-
to:
155-
kind: Service
156-
name: minio-service
157-
weight: 100
158-
port:
159-
targetPort: ui
160-
wildcardPolicy: None
161-
tls:
162-
termination: edge
163-
insecureEdgeTerminationPolicy: Redirect

0 commit comments

Comments
 (0)