diff --git a/README.md b/README.md index d59d2f9beb..3a3921d4f4 100644 --- a/README.md +++ b/README.md @@ -197,8 +197,6 @@ This notebook compares the performance of `Dataset`, `CacheDataset` and `Persist ##### [fast_training_tutorial](./acceleration/fast_training_tutorial.ipynb) This tutorial compares the training performance of pure PyTorch program and optimized program in MONAI based on NVIDIA GPU device and latest CUDA library. The optimization methods mainly include: `AMP`, `CacheDataset`, `GPU transforms`, `ThreadDataLoader`, `DiceCELoss` and `SGD`. -##### [multi_gpu_test](./acceleration/multi_gpu_test.ipynb) -This notebook is a quick demo for devices, run the Ignite trainer engine on CPU, GPU and multiple GPUs. ##### [threadbuffer_performance](./acceleration/threadbuffer_performance.ipynb) Demonstrates the use of the `ThreadBuffer` class used to generate data batches during training in a separate thread. ##### [transform_speed](./acceleration/transform_speed.ipynb) diff --git a/acceleration/README.md b/acceleration/README.md index 1245757528..47e2e7fb99 100644 --- a/acceleration/README.md +++ b/acceleration/README.md @@ -18,8 +18,6 @@ This notebook compares the performance of `Dataset`, `CacheDataset` and `Persist #### [fast_training_tutorial](./fast_training_tutorial.ipynb) This tutorial compares the training performance of pure PyTorch program and optimized program in MONAI based on NVIDIA GPU device and latest CUDA library. The optimization methods mainly include: `AMP`, `CacheDataset` and `Novograd`. -#### [multi_gpu_test](./multi_gpu_test.ipynb) -This notebook is a quick demo for devices, run the Ignite trainer engine on CPU, GPU and multiple GPUs. #### [threadbuffer_performance](./threadbuffer_performance.ipynb) Demonstrates the use of the `ThreadBuffer` class used to generate data batches during training in a separate thread. #### [transform_speed](./transform_speed.ipynb) diff --git a/acceleration/multi_gpu_test.ipynb b/acceleration/multi_gpu_test.ipynb deleted file mode 100644 index e4c1263358..0000000000 --- a/acceleration/multi_gpu_test.ipynb +++ /dev/null @@ -1,316 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Copyright (c) MONAI Consortium \n", - "Licensed under the Apache License, Version 2.0 (the \"License\"); \n", - "you may not use this file except in compliance with the License. \n", - "You may obtain a copy of the License at \n", - "    http://www.apache.org/licenses/LICENSE-2.0 \n", - "Unless required by applicable law or agreed to in writing, software \n", - "distributed under the License is distributed on an \"AS IS\" BASIS, \n", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \n", - "See the License for the specific language governing permissions and \n", - "limitations under the License.\n", - "\n", - "# Multi GPU Test\n", - "\n", - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Project-MONAI/tutorials/blob/main/acceleration/multi_gpu_test.ipynb)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setup environment" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "!python -c \"import monai\" || pip install -q \"monai-weekly[ignite]\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setup imports" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "MONAI version: 1.1.0+2.g97918e46\n", - "Numpy version: 1.22.2\n", - "Pytorch version: 1.13.0a0+d0d6b1f\n", - "MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False\n", - "MONAI rev id: 97918e46e0d2700c050e678d72e3edb35afbd737\n", - "MONAI __file__: /workspace/monai/monai-in-dev/monai/__init__.py\n", - "\n", - "Optional dependencies:\n", - "Pytorch Ignite version: 0.4.10\n", - "Nibabel version: 4.0.2\n", - "scikit-image version: 0.19.3\n", - "Pillow version: 9.0.1\n", - "Tensorboard version: 2.10.1\n", - "gdown version: 4.6.0\n", - "TorchVision version: 0.14.0a0\n", - "tqdm version: 4.64.1\n", - "lmdb version: 1.3.0\n", - "psutil version: 5.9.2\n", - "pandas version: 1.4.4\n", - "einops version: 0.6.0\n", - "transformers version: 4.21.3\n", - "mlflow version: 2.0.1\n", - "pynrrd version: 1.0.0\n", - "\n", - "For details about installing the optional dependencies, please visit:\n", - " https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n", - "\n" - ] - } - ], - "source": [ - "import torch\n", - "from monai.config import print_config\n", - "from monai.engines import create_multigpu_supervised_trainer\n", - "from monai.networks.nets import UNet\n", - "\n", - "print_config()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Test GPUs" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "max_epochs = 2\n", - "lr = 1e-3\n", - "device = torch.device(\"cuda:0\")\n", - "net = UNet(\n", - " spatial_dims=2,\n", - " in_channels=1,\n", - " out_channels=1,\n", - " channels=(16, 32, 64, 128, 256),\n", - " strides=(2, 2, 2, 2),\n", - " num_res_units=2,\n", - ").to(device)\n", - "\n", - "\n", - "def fake_loss(y_pred, y):\n", - " return (y_pred[0] + y).sum()\n", - "\n", - "\n", - "def fake_data_stream():\n", - " while True:\n", - " yield torch.rand((10, 1, 64, 64)), torch.rand((10, 1, 64, 64))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### 1 GPU" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2023-01-20 14:16:00,009 - Engine run starting with max_epochs=2.\n", - "2023-01-20 14:16:00,189 - Epoch[1] Complete. Time taken: 00:00:00.180\n", - "2023-01-20 14:16:00,201 - Epoch[2] Complete. Time taken: 00:00:00.011\n", - "2023-01-20 14:16:00,201 - Engine run complete. Time taken: 00:00:00.192\n" - ] - }, - { - "data": { - "text/plain": [ - "State:\n", - "\titeration: 4\n", - "\tepoch: 2\n", - "\tepoch_length: 2\n", - "\tmax_epochs: 2\n", - "\toutput: 23339.560546875\n", - "\tbatch: \n", - "\tmetrics: \n", - "\tdataloader: \n", - "\tseed: \n", - "\ttimes: " - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "opt = torch.optim.Adam(net.parameters(), lr)\n", - "trainer = create_multigpu_supervised_trainer(net, opt, fake_loss, [device])\n", - "trainer.run(fake_data_stream(), max_epochs=max_epochs, epoch_length=2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### all GPUs" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "pycharm": { - "name": "#%%\n" - }, - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2023-01-20 14:16:00,208 - Engine run starting with max_epochs=2.\n", - "2023-01-20 14:16:01,364 - Epoch[1] Complete. Time taken: 00:00:01.154\n", - "2023-01-20 14:16:01,391 - Epoch[2] Complete. Time taken: 00:00:00.026\n", - "2023-01-20 14:16:01,391 - Engine run complete. Time taken: 00:00:01.181\n" - ] - }, - { - "data": { - "text/plain": [ - "State:\n", - "\titeration: 4\n", - "\tepoch: 2\n", - "\tepoch_length: 2\n", - "\tmax_epochs: 2\n", - "\toutput: 22608.560546875\n", - "\tbatch: \n", - "\tmetrics: \n", - "\tdataloader: \n", - "\tseed: \n", - "\ttimes: " - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "opt = torch.optim.Adam(net.parameters(), lr)\n", - "trainer = create_multigpu_supervised_trainer(net, opt, fake_loss, None)\n", - "trainer.run(fake_data_stream(), max_epochs=max_epochs, epoch_length=2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### CPU" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "pycharm": { - "name": "#%%\n" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2023-01-20 14:16:01,402 - Engine run starting with max_epochs=2.\n", - "2023-01-20 14:16:01,475 - Epoch[1] Complete. Time taken: 00:00:00.073\n", - "2023-01-20 14:16:01,575 - Epoch[2] Complete. Time taken: 00:00:00.100\n", - "2023-01-20 14:16:01,576 - Engine run complete. Time taken: 00:00:00.174\n" - ] - }, - { - "data": { - "text/plain": [ - "State:\n", - "\titeration: 4\n", - "\tepoch: 2\n", - "\tepoch_length: 2\n", - "\tmax_epochs: 2\n", - "\toutput: 21955.39453125\n", - "\tbatch: \n", - "\tmetrics: \n", - "\tdataloader: \n", - "\tseed: \n", - "\ttimes: " - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "net = net.to(torch.device(\"cpu:0\"))\n", - "opt = torch.optim.Adam(net.parameters(), lr)\n", - "trainer = create_multigpu_supervised_trainer(net, opt, fake_loss, [])\n", - "trainer.run(fake_data_stream(), max_epochs=max_epochs, epoch_length=2)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.13" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -}