Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ColossalAI
Commits
ce886a90
Commit
ce886a90
authored
Mar 10, 2022
by
lucasliunju
Committed by
Frank Lee
Mar 11, 2022
Browse files
fix format (#374)
parent
526a3180
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
0 additions
and
64 deletions
+0
-64
model_zoo/mlp_mixer/__init__.py
model_zoo/mlp_mixer/__init__.py
+0
-0
model_zoo/mlp_mixer/parallel_1d/.init
model_zoo/mlp_mixer/parallel_1d/.init
+0
-0
model_zoo/mlp_mixer/parallel_2d/.init
model_zoo/mlp_mixer/parallel_2d/.init
+0
-0
model_zoo/mlp_mixer/parallel_2p5d/.init
model_zoo/mlp_mixer/parallel_2p5d/.init
+0
-0
model_zoo/mlp_mixer/parallel_3d/__init__.py
model_zoo/mlp_mixer/parallel_3d/__init__.py
+0
-1
model_zoo/mlp_mixer/parallel_3d/mlp_mixer.py
model_zoo/mlp_mixer/parallel_3d/mlp_mixer.py
+0
-63
No files found.
model_zoo/mlp_mixer/__init__.py
deleted
100644 → 0
View file @
526a3180
model_zoo/mlp_mixer/parallel_1d/.init
deleted
100644 → 0
View file @
526a3180
model_zoo/mlp_mixer/parallel_2d/.init
deleted
100644 → 0
View file @
526a3180
model_zoo/mlp_mixer/parallel_2p5d/.init
deleted
100644 → 0
View file @
526a3180
model_zoo/mlp_mixer/parallel_3d/__init__.py
deleted
100644 → 0
View file @
526a3180
from
.mlp_mixer
import
*
model_zoo/mlp_mixer/parallel_3d/mlp_mixer.py
deleted
100644 → 0
View file @
526a3180
# modified from https://github.com/lucidrains/mlp-mixer-pytorch/blob/main/mlp_mixer_pytorch/mlp_mixer_pytorch.py
from
functools
import
partial
from
colossalai.context
import
ParallelMode
from
colossalai.registry
import
MODELS
from
torch
import
nn
from
colossalai
import
nn
as
col_nn
from
colossalai.nn.layer.parallel_3d._utils
import
get_depth_from_env
from
einops.layers.torch
import
Rearrange
,
Reduce
__all__
=
[
'MLPMixer'
,
]
class
PreNormResidual
(
nn
.
Module
):
def
__init__
(
self
,
dim
,
fn
,
depth_3d
):
super
().
__init__
()
self
.
fn
=
fn
self
.
norm
=
col_nn
.
LayerNorm3D
(
dim
,
depth_3d
,
ParallelMode
.
PARALLEL_3D_INPUT
,
ParallelMode
.
PARALLEL_3D_WEIGHT
)
def
forward
(
self
,
x
):
return
self
.
fn
(
self
.
norm
(
x
))
+
x
def
FeedForward
(
dim
,
depth_3d
,
expansion_factor
=
4
,
dropout
=
0.
,
dense
=
None
):
if
dense
is
None
:
dense
=
partial
(
col_nn
.
Linear3D
,
depth
=
depth_3d
,
input_parallel_mode
=
ParallelMode
.
PARALLEL_3D_INPUT
,
weight_parallel_mode
=
ParallelMode
.
PARALLEL_3D_WEIGHT
)
return
nn
.
Sequential
(
dense
(
dim
,
dim
*
expansion_factor
),
nn
.
GELU
(),
nn
.
Dropout
(
dropout
),
dense
(
dim
*
expansion_factor
,
dim
),
nn
.
Dropout
(
dropout
)
)
@
MODELS
.
register_module
def
MLPMixer
(
image_size
,
channels
,
patch_size
,
dim
,
depth
,
num_classes
,
expansion_factor
=
4
,
dropout
=
0.
):
assert
(
image_size
%
patch_size
)
==
0
,
'image must be divisible by patch size'
num_patches
=
(
image_size
//
patch_size
)
**
2
depth_3d
=
get_depth_from_env
()
linear
=
partial
(
col_nn
.
Linear3D
,
depth
=
depth_3d
,
input_parallel_mode
=
ParallelMode
.
PARALLEL_3D_INPUT
,
weight_parallel_mode
=
ParallelMode
.
PARALLEL_3D_WEIGHT
)
norm_layer
=
partial
(
col_nn
.
LayerNorm3D
,
depth
=
depth_3d
,
input_parallel_mode
=
ParallelMode
.
PARALLEL_3D_INPUT
,
weight_parallel_mode
=
ParallelMode
.
PARALLEL_3D_WEIGHT
)
chan_first
,
chan_last
=
partial
(
nn
.
Conv1d
,
kernel_size
=
1
),
linear
return
nn
.
Sequential
(
Rearrange
(
'b c (h p1) (w p2) -> b (h w) (p1 p2 c)'
,
p1
=
patch_size
,
p2
=
patch_size
),
linear
((
patch_size
**
2
)
*
channels
,
dim
),
*
[
nn
.
Sequential
(
PreNormResidual
(
dim
,
FeedForward
(
num_patches
,
expansion_factor
,
dropout
,
chan_first
)),
PreNormResidual
(
dim
,
FeedForward
(
dim
,
expansion_factor
,
dropout
,
chan_last
))
)
for
_
in
range
(
depth
)],
norm_layer
(
dim
),
Reduce
(
'b n c -> b c'
,
'mean'
),
linear
(
dim
,
num_classes
)
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment