From 011d014a063c51176e3529890d5cf6d07a129960 Mon Sep 17 00:00:00 2001 From: Muzamil Bashir <154577974+DynaDATA@users.noreply.github.com> Date: Sun, 19 Jan 2025 08:32:26 +0000 Subject: [PATCH] Add guide for running model on MacBook M4 Max 2024 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Project-MONAI/tutorials?shareId=XXXX-XXXX-XXXX-XXXX). --- acceleration/README.md | 69 +++++++++++++++++++ .../distributed_training.md | 55 +++++++++++++++ acceleration/fast_model_training_guide.md | 56 +++++++++++++++ 3 files changed, 180 insertions(+) diff --git a/acceleration/README.md b/acceleration/README.md index e803b6e445..3d5a0aba4a 100644 --- a/acceleration/README.md +++ b/acceleration/README.md @@ -27,3 +27,72 @@ This notebook shows how to use TensorRT to accelerate the model and achieve a be #### [Tutorials for resource monitoring](./monitoring/README.md) Information about how to set up and apply existing tools to monitor the computing resources. + +### Running a Model on MacBook M4 Max 2024 + +#### Step-by-Step Guide + +##### 1. Installing Dependencies + +To run a model on a MacBook M4 Max 2024, you need to install the necessary dependencies. Follow these steps: + +1. Install Homebrew if you haven't already: + ```sh + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + ``` + +2. Install Python: + ```sh + brew install python + ``` + +3. Install virtualenv: + ```sh + pip install virtualenv + ``` + +4. Create a virtual environment: + ```sh + virtualenv monai_env + ``` + +5. Activate the virtual environment: + ```sh + source monai_env/bin/activate + ``` + +6. Install MONAI and other dependencies: + ```sh + pip install monai numpy torch torchvision + ``` + +##### 2. Setting Up the Environment + +1. Clone the Project-MONAI repository: + ```sh + git clone https://github.com/Project-MONAI/tutorials.git + cd tutorials + ``` + +2. Navigate to the desired tutorial directory, for example: + ```sh + cd acceleration + ``` + +##### 3. Running a Model + +1. Choose the tutorial or example you want to run. For instance, to run the `fast_training_tutorial.ipynb`, you can use Jupyter Notebook. + +2. Install Jupyter Notebook: + ```sh + pip install notebook + ``` + +3. Start Jupyter Notebook: + ```sh + jupyter notebook + ``` + +4. Open the desired notebook (e.g., `fast_training_tutorial.ipynb`) in your browser and follow the instructions to run the model. + +By following these steps, you should be able to install and run a model on your MacBook M4 Max 2024 with the specified system information. diff --git a/acceleration/distributed_training/distributed_training.md b/acceleration/distributed_training/distributed_training.md index 870bd28cda..2cd38f6cd6 100644 --- a/acceleration/distributed_training/distributed_training.md +++ b/acceleration/distributed_training/distributed_training.md @@ -37,3 +37,58 @@ torchrun --nproc_per_node=8 --nnodes=2 --node_rank=1 --master_addr="localhost" - Note that the only difference between the two commands is `--node_rank`. There would be some possible delay between the execution of the two commands in the two nodes. But the first node would always wait for the second one, and they would start and train together. If there is an IP issue for the validation part during model training, please refer to the solution [here](https://discuss.pytorch.org/t/connect-127-0-1-1-a-port-connection-refused/100802/25) to resolve it. + +## Running on MacBook M4 Max 2024 + +To run a model on a MacBook M4 Max 2024, follow these steps to optimize GPU utilization: + +1. **Install Dependencies**: + - Install Homebrew if you haven't already: + ```sh + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + ``` + - Install Python: + ```sh + brew install python + ``` + - Install virtualenv: + ```sh + pip install virtualenv + ``` + - Create a virtual environment: + ```sh + virtualenv monai_env + ``` + - Activate the virtual environment: + ```sh + source monai_env/bin/activate + ``` + - Install MONAI and other dependencies: + ```sh + pip install monai numpy torch torchvision + ``` + +2. **Set Up the Environment**: + - Clone the Project-MONAI repository: + ```sh + git clone https://github.com/Project-MONAI/tutorials.git + cd tutorials + ``` + - Navigate to the desired tutorial directory, for example: + ```sh + cd acceleration + ``` + +3. **Run a Model**: + - Choose the tutorial or example you want to run. For instance, to run the `fast_training_tutorial.ipynb`, you can use Jupyter Notebook. + - Install Jupyter Notebook: + ```sh + pip install notebook + ``` + - Start Jupyter Notebook: + ```sh + jupyter notebook + ``` + - Open the desired notebook (e.g., `fast_training_tutorial.ipynb`) in your browser and follow the instructions to run the model. + +By following these steps, you should be able to install and run a model on your MacBook M4 Max 2024 with the specified system information. diff --git a/acceleration/fast_model_training_guide.md b/acceleration/fast_model_training_guide.md index 5ff3ba8f8a..3b0038717a 100644 --- a/acceleration/fast_model_training_guide.md +++ b/acceleration/fast_model_training_guide.md @@ -21,6 +21,7 @@ To provide an overview of the fast training techniques in practice, this documen * [Execute transforms on GPU](#2-execute-transforms-on-gpu) * [Adapt `cuCIM` to execute GPU transforms](#3-adapt-cucim-to-execute-gpu-transforms) * [Cache IO and transforms data to GPU](#4-cache-io-and-transforms-data-to-gpu) + * [Running on MacBook M4 Max 2024](#5-running-on-macbook-m4-max-2024) * [Leveraging multi-GPU distributed training](#leveraging-multi-gpu-distributed-training) * Demonstration of multi-GPU training for performance improvement. * [Leveraging multi-node distributed training](#leveraging-multi-node-distributed-training) @@ -284,6 +285,61 @@ dataset = CacheDataset(..., transform=train_trans) Here we convert to PyTorch `Tensor` and move data to GPU with `EnsureTyped` transform. `CacheDataset` caches the transform results until `EnsureTyped`, so it is in GPU memory. Then in every epoch, the program fetches cached data from GPU memory and only execute the random transform `RandCropByPosNegLabeld` on GPU directly. GPU caching example is available at [Spleen fast training tutorial](fast_training_tutorial.ipynb). +### 5. Running on MacBook M4 Max 2024 + +To run a model on a MacBook M4 Max 2024, follow these steps to optimize GPU utilization: + +1. **Install Dependencies**: + - Install Homebrew if you haven't already: + ```sh + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + ``` + - Install Python: + ```sh + brew install python + ``` + - Install virtualenv: + ```sh + pip install virtualenv + ``` + - Create a virtual environment: + ```sh + virtualenv monai_env + ``` + - Activate the virtual environment: + ```sh + source monai_env/bin/activate + ``` + - Install MONAI and other dependencies: + ```sh + pip install monai numpy torch torchvision + ``` + +2. **Set Up the Environment**: + - Clone the Project-MONAI repository: + ```sh + git clone https://github.com/Project-MONAI/tutorials.git + cd tutorials + ``` + - Navigate to the desired tutorial directory, for example: + ```sh + cd acceleration + ``` + +3. **Run a Model**: + - Choose the tutorial or example you want to run. For instance, to run the `fast_training_tutorial.ipynb`, you can use Jupyter Notebook. + - Install Jupyter Notebook: + ```sh + pip install notebook + ``` + - Start Jupyter Notebook: + ```sh + jupyter notebook + ``` + - Open the desired notebook (e.g., `fast_training_tutorial.ipynb`) in your browser and follow the instructions to run the model. + +By following these steps, you should be able to install and run a model on your MacBook M4 Max 2024 with the specified system information. + ## Leveraging multi-GPU distributed training When we have fully utilized a single GPU during training, a straightforward optimization idea is to partition the dataset and execute model training in parallel on multiple GPUs.