Skip to content

Commit b448cf2

Browse files
ericspodKumoLiu
andauthored
Updating workflow to use Github CPU runner (#2032)
Fixes #2031. ### Description This will change the failing CICD check to use Github CPU runners. ### Checks <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Avoid including large-size files in the PR. - [x] Clean up long text outputs from code cells in the notebook. - [x] For security purposes, please check the contents and remove any sensitive info such as user names and private key. - [x] Ensure (1) hyperlinks and markdown anchors are working (2) use relative paths for tutorial repo files (3) put figure and graphs in the `./figure` folder - [x] Notebook runs automatically `./runner.sh -t <path to .ipynb file>` --------- Signed-off-by: Eric Kerfoot <[email protected]> Co-authored-by: YunLiu <[email protected]>
1 parent b5cb801 commit b448cf2

File tree

4 files changed

+37
-43
lines changed

4 files changed

+37
-43
lines changed

.github/workflows/test-modified.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,39 @@ on:
99

1010
concurrency:
1111
# automatically cancel the previously triggered workflows when there's a newer version
12-
group: build-gpu-${{ github.event.pull_request.number || github.ref }}
12+
group: build-${{ github.event.pull_request.number || github.ref }}
1313
cancel-in-progress: true
1414

1515
jobs:
1616
build:
17-
if: github.repository == 'Project-MONAI/tutorials'
18-
container:
19-
image: nvcr.io/nvidia/pytorch:24.02-py3
20-
options: --gpus all --ipc host
21-
runs-on: [self-hosted, linux, x64]
17+
runs-on: ubuntu-latest
2218
steps:
19+
- uses: actions/checkout@v3
20+
- name: Set up Python 3.10
21+
uses: actions/setup-python@v3
22+
with:
23+
python-version: '3.10'
2324
- name: Install MONAI
2425
id: monai-install
2526
run: |
2627
which python
27-
nvidia-smi
28-
rm -rf ../../MONAI/MONAI
29-
python -m pip install --upgrade pip wheel
30-
pip uninstall -y monai
31-
pip uninstall -y monai
32-
pip uninstall -y monai-weekly
33-
pip uninstall -y monai-weekly # make sure there's no existing installation
34-
BUILD_MONAI=0 python -m pip install git+https://github.com/Project-MONAI/MONAI#egg=MONAI
28+
python -m pip install -U pip wheel
29+
python -m pip install torch torchvision torchaudio
30+
3531
python -m pip install -r https://raw.githubusercontent.com/Project-MONAI/MONAI/dev/requirements-dev.txt
36-
python -m pip install -U torch torchvision torchaudio
37-
- uses: actions/checkout@v3
32+
python -m pip install -r requirements.txt
33+
34+
BUILD_MONAI=0 python -m pip install git+https://github.com/Project-MONAI/MONAI#egg=MONAI
35+
python -m pip list
3836
- name: Notebook quick check
3937
shell: bash
4038
run: |
41-
git config --global --add safe.directory /__w/tutorials/tutorials
42-
git fetch origin main
43-
python -m pip install -r requirements.txt; python -m pip list
4439
python -c "import monai; monai.config.print_debug_info()"
45-
export CUDA_VISIBLE_DEVICES=0
46-
git diff --name-only origin/main | while read line; do if [[ $line == *.ipynb ]]; then ./runner.sh -p " -and -wholename './${line}'"; fi; done;
47-
# [[ $line == *.ipynb ]] && ./runner.sh --file "$line"
40+
git fetch origin main
41+
git diff --name-only origin/main | while read line
42+
do
43+
if [[ $line == *.ipynb ]]
44+
then
45+
./runner.sh -p " -and -wholename './${line}'"
46+
fi
47+
done

2d_classification/monai_101.ipynb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,7 @@
141141
"cell_type": "code",
142142
"execution_count": null,
143143
"metadata": {},
144-
"outputs": [
145-
{
146-
"name": "stdout",
147-
"output_type": "stream",
148-
"text": [
149-
"/workspace/data\n"
150-
]
151-
}
152-
],
144+
"outputs": [],
153145
"source": [
154146
"directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
155147
"if directory is not None:\n",
@@ -250,11 +242,12 @@
250242
"outputs": [],
251243
"source": [
252244
"max_epochs = 5\n",
253-
"model = densenet121(spatial_dims=2, in_channels=1, out_channels=6).to(\"cuda:0\")\n",
245+
"device = torch.device(\"cuda:0\" if torch.cuda.device_count() > 0 else \"cpu\")\n",
246+
"model = densenet121(spatial_dims=2, in_channels=1, out_channels=6).to(device)\n",
254247
"\n",
255248
"logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
256249
"trainer = SupervisedTrainer(\n",
257-
" device=torch.device(\"cuda:0\"),\n",
250+
" device=device,\n",
258251
" max_epochs=max_epochs,\n",
259252
" train_data_loader=DataLoader(dataset, batch_size=512, shuffle=True, num_workers=4),\n",
260253
" network=model,\n",
@@ -320,7 +313,7 @@
320313
"max_items_to_print = 10\n",
321314
"with eval_mode(model):\n",
322315
" for item in DataLoader(testdata, batch_size=1, num_workers=0):\n",
323-
" prob = np.array(model(item[\"image\"].to(\"cuda:0\")).detach().to(\"cpu\"))[0]\n",
316+
" prob = np.array(model(item[\"image\"].to(device)).detach().to(\"cpu\"))[0]\n",
324317
" pred = class_names[prob.argmax()]\n",
325318
" gt = item[\"class_name\"][0]\n",
326319
" print(f\"Class prediction is {pred}. Ground-truth: {gt}\")\n",

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ autopep8
44
jupytext<=1.16.3
55
autoflake
66
ipywidgets
7+
ipykernel
78
tensorboard>=2.4.0

runner.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,15 @@ trap finish EXIT
466466
# After setup, don't want to exit immediately after error
467467
set +e
468468

469+
# FIXME: https://github.com/Project-MONAI/MONAI/issues/4354
470+
protobuf_major_version=$(${PY_EXE} -m pip list | grep '^protobuf ' | tr -s ' ' | cut -d' ' -f2 | cut -d'.' -f1)
471+
if [ "$protobuf_major_version" -ge "4" ]
472+
then
473+
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
474+
else
475+
unset PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION
476+
fi
477+
469478
########################################################################
470479
# #
471480
# loop over files #
@@ -559,15 +568,6 @@ for file in "${files[@]}"; do
559568

560569
python -c 'import monai; monai.config.print_config()'
561570

562-
# FIXME: https://github.com/Project-MONAI/MONAI/issues/4354
563-
protobuf_major_version=$(${PY_EXE} -m pip list | grep '^protobuf ' | tr -s ' ' | cut -d' ' -f2 | cut -d'.' -f1)
564-
if [ "$protobuf_major_version" -ge "4" ]
565-
then
566-
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
567-
else
568-
unset PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION
569-
fi
570-
571571
cmd=$(echo "papermill ${papermill_opt} --progress-bar --log-output -k ${kernelspec}")
572572
echo "$cmd"
573573
time out=$(echo "$notebook" | eval "$cmd")

0 commit comments

Comments
 (0)