model.md 1.24 KB
Newer Older
zbian's avatar
zbian committed
1
2
# Define your own parallel model

3
Let's say that you have a huge MLP model with billions of parameters and its extremely large hidden layer size makes it
4
impossible to fit into a single GPU directly. Don't worry, ColossalAI is here to help you sort things out. With the help of ColossalAI, 
5
6
you can write your model in the familiar way in which you used to write models for a single GPU, while ColossalAI automatically 
splits your model weights and fit them perfectly into a set of GPUs. We give a simple example showing how to write a simple 
7
2D parallel model in the Colossal-AI context.
zbian's avatar
zbian committed
8

9
## Write a simple 2D parallel model
zbian's avatar
zbian committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

```python
from colossalai.nn import Linear2D
import torch.nn as nn

class MLP_2D(nn.Module):

    def __init__(self):
        super().__init__()
        self.linear_1 = Linear2D(in_features=1024, out_features=16384)
        self.linear_2 = Linear2D(in_features=16384, out_features=1024)

    def forward(self, x):
        x = self.linear_1(x)
        x = self.linear_2(x)
        return x
```

## Use pre-defined model
29
30
31

For the sake of your convenience, we kindly provide you in our Model Zoo with some prevalent models such as *BERT*, *VIT*, 
and *MLP-Mixer*. Feel free to customize them into different sizes to fit into your special needs.