Skip to content

Commit

Permalink
Add guide for running model on MacBook M4 Max 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
DynaDATA committed Jan 19, 2025
1 parent 476d2fc commit 011d014
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 0 deletions.
69 changes: 69 additions & 0 deletions acceleration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
55 changes: 55 additions & 0 deletions acceleration/distributed_training/distributed_training.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
56 changes: 56 additions & 0 deletions acceleration/fast_model_training_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 011d014

Please sign in to comment.