diff --git a/.github/workflows/test-modified.yml b/.github/workflows/test-modified.yml index 2f8b92f591..6f2cccbb98 100644 --- a/.github/workflows/test-modified.yml +++ b/.github/workflows/test-modified.yml @@ -9,39 +9,39 @@ on: concurrency: # automatically cancel the previously triggered workflows when there's a newer version - group: build-gpu-${{ github.event.pull_request.number || github.ref }} + group: build-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: build: - if: github.repository == 'Project-MONAI/tutorials' - container: - image: nvcr.io/nvidia/pytorch:24.02-py3 - options: --gpus all --ipc host - runs-on: [self-hosted, linux, x64] + runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: '3.10' - name: Install MONAI id: monai-install run: | which python - nvidia-smi - rm -rf ../../MONAI/MONAI - python -m pip install --upgrade pip wheel - pip uninstall -y monai - pip uninstall -y monai - pip uninstall -y monai-weekly - pip uninstall -y monai-weekly # make sure there's no existing installation - BUILD_MONAI=0 python -m pip install git+https://github.com/Project-MONAI/MONAI#egg=MONAI + python -m pip install -U pip wheel + python -m pip install torch torchvision torchaudio + python -m pip install -r https://raw.githubusercontent.com/Project-MONAI/MONAI/dev/requirements-dev.txt - python -m pip install -U torch torchvision torchaudio - - uses: actions/checkout@v3 + python -m pip install -r requirements.txt + + BUILD_MONAI=0 python -m pip install git+https://github.com/Project-MONAI/MONAI#egg=MONAI + python -m pip list - name: Notebook quick check shell: bash run: | - git config --global --add safe.directory /__w/tutorials/tutorials - git fetch origin main - python -m pip install -r requirements.txt; python -m pip list python -c "import monai; monai.config.print_debug_info()" - export CUDA_VISIBLE_DEVICES=0 - git diff --name-only origin/main | while read line; do if [[ $line == *.ipynb ]]; then ./runner.sh -p " -and -wholename './${line}'"; fi; done; - # [[ $line == *.ipynb ]] && ./runner.sh --file "$line" + git fetch origin main + git diff --name-only origin/main | while read line + do + if [[ $line == *.ipynb ]] + then + ./runner.sh -p " -and -wholename './${line}'" + fi + done diff --git a/2d_classification/monai_101.ipynb b/2d_classification/monai_101.ipynb index f4fe298dd6..5f3c3d0829 100644 --- a/2d_classification/monai_101.ipynb +++ b/2d_classification/monai_101.ipynb @@ -141,15 +141,7 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/workspace/data\n" - ] - } - ], + "outputs": [], "source": [ "directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n", "if directory is not None:\n", @@ -250,11 +242,12 @@ "outputs": [], "source": [ "max_epochs = 5\n", - "model = densenet121(spatial_dims=2, in_channels=1, out_channels=6).to(\"cuda:0\")\n", + "device = torch.device(\"cuda:0\" if torch.cuda.device_count() > 0 else \"cpu\")\n", + "model = densenet121(spatial_dims=2, in_channels=1, out_channels=6).to(device)\n", "\n", "logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n", "trainer = SupervisedTrainer(\n", - " device=torch.device(\"cuda:0\"),\n", + " device=device,\n", " max_epochs=max_epochs,\n", " train_data_loader=DataLoader(dataset, batch_size=512, shuffle=True, num_workers=4),\n", " network=model,\n", @@ -320,7 +313,7 @@ "max_items_to_print = 10\n", "with eval_mode(model):\n", " for item in DataLoader(testdata, batch_size=1, num_workers=0):\n", - " prob = np.array(model(item[\"image\"].to(\"cuda:0\")).detach().to(\"cpu\"))[0]\n", + " prob = np.array(model(item[\"image\"].to(device)).detach().to(\"cpu\"))[0]\n", " pred = class_names[prob.argmax()]\n", " gt = item[\"class_name\"][0]\n", " print(f\"Class prediction is {pred}. Ground-truth: {gt}\")\n", diff --git a/requirements.txt b/requirements.txt index 3c32bcb0ef..24b290cb48 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ autopep8 jupytext<=1.16.3 autoflake ipywidgets +ipykernel tensorboard>=2.4.0 diff --git a/runner.sh b/runner.sh index e2bd1f8539..1f72f6fcb8 100755 --- a/runner.sh +++ b/runner.sh @@ -466,6 +466,15 @@ trap finish EXIT # After setup, don't want to exit immediately after error set +e +# FIXME: https://github.com/Project-MONAI/MONAI/issues/4354 +protobuf_major_version=$(${PY_EXE} -m pip list | grep '^protobuf ' | tr -s ' ' | cut -d' ' -f2 | cut -d'.' -f1) +if [ "$protobuf_major_version" -ge "4" ] +then + export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python +else + unset PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION +fi + ######################################################################## # # # loop over files # @@ -559,15 +568,6 @@ for file in "${files[@]}"; do python -c 'import monai; monai.config.print_config()' - # FIXME: https://github.com/Project-MONAI/MONAI/issues/4354 - protobuf_major_version=$(${PY_EXE} -m pip list | grep '^protobuf ' | tr -s ' ' | cut -d' ' -f2 | cut -d'.' -f1) - if [ "$protobuf_major_version" -ge "4" ] - then - export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python - else - unset PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION - fi - cmd=$(echo "papermill ${papermill_opt} --progress-bar --log-output -k ${kernelspec}") echo "$cmd" time out=$(echo "$notebook" | eval "$cmd")