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
c1e8d200
"git@developer.sourcefind.cn:OpenDAS/colossalai.git" did not exist on "6a21f96a87948971e7c2e96f2cf2e563304e0c7a"
Unverified
Commit
c1e8d200
authored
Apr 24, 2022
by
LuGY
Committed by
GitHub
Apr 24, 2022
Browse files
modefied the pp build for ckpt adaptation (#803)
parent
8789850e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
3 deletions
+6
-3
colossalai/builder/pipeline.py
colossalai/builder/pipeline.py
+4
-2
colossalai/initialize.py
colossalai/initialize.py
+2
-1
No files found.
colossalai/builder/pipeline.py
View file @
c1e8d200
...
@@ -240,7 +240,6 @@ def build_pipeline_model_from_cfg(config,
...
@@ -240,7 +240,6 @@ def build_pipeline_model_from_cfg(config,
def
build_pipeline_model
(
layers
:
nn
.
Sequential
,
num_chunks
:
int
=
1
,
verbose
:
bool
=
False
):
def
build_pipeline_model
(
layers
:
nn
.
Sequential
,
num_chunks
:
int
=
1
,
verbose
:
bool
=
False
):
"""An intializer to split the model into different stages for pipeline parallelism.
"""An intializer to split the model into different stages for pipeline parallelism.
Note that `layer` must be `torch.nn.Sequential`.
Note that `layer` must be `torch.nn.Sequential`.
Args:
Args:
layers (`torch.nn.Sequential`): Layers of model
layers (`torch.nn.Sequential`): Layers of model
num_chunks: The number of chunks you want to have on the current stage. This value should be 1
num_chunks: The number of chunks you want to have on the current stage. This value should be 1
...
@@ -252,7 +251,9 @@ def build_pipeline_model(layers: nn.Sequential, num_chunks: int = 1, verbose: bo
...
@@ -252,7 +251,9 @@ def build_pipeline_model(layers: nn.Sequential, num_chunks: int = 1, verbose: bo
partitions
=
partition_uniform
(
len
(
layers
),
pipeline_parallel_size
,
num_chunks
)
partitions
=
partition_uniform
(
len
(
layers
),
pipeline_parallel_size
,
num_chunks
)
module_list
=
[]
module_list
=
[]
for
start
,
end
in
partitions
[
pipeline_rank
]:
for
start
,
end
in
partitions
[
pipeline_rank
]:
module_list
.
append
(
nn
.
Sequential
(
*
layers
[
start
:
end
]))
module_list
.
append
(
nn
.
Sequential
(
*
[
nn
.
Identity
()
for
_
in
range
(
start
)],
*
layers
[
start
:
end
],
*
[
nn
.
Identity
()
for
_
in
range
(
len
(
layers
)
-
end
)]))
if
verbose
:
if
verbose
:
logger
=
get_dist_logger
()
logger
=
get_dist_logger
()
logger
.
info
(
f
'Total
{
len
(
layers
)
}
layers'
,
ranks
=
[
0
])
logger
.
info
(
f
'Total
{
len
(
layers
)
}
layers'
,
ranks
=
[
0
])
...
@@ -263,3 +264,4 @@ def build_pipeline_model(layers: nn.Sequential, num_chunks: int = 1, verbose: bo
...
@@ -263,3 +264,4 @@ def build_pipeline_model(layers: nn.Sequential, num_chunks: int = 1, verbose: bo
log_str
+=
'
\n
'
.
join
([
str
(
layer
)
for
layer
in
layers
[
start
:
end
]])
+
'
\n
'
log_str
+=
'
\n
'
.
join
([
str
(
layer
)
for
layer
in
layers
[
start
:
end
]])
+
'
\n
'
logger
.
info
(
log_str
,
ranks
=
[
0
])
logger
.
info
(
log_str
,
ranks
=
[
0
])
return
nn
.
ModuleList
(
module_list
)
if
len
(
module_list
)
>
1
else
module_list
[
0
]
return
nn
.
ModuleList
(
module_list
)
if
len
(
module_list
)
>
1
else
module_list
[
0
]
\ No newline at end of file
colossalai/initialize.py
View file @
c1e8d200
...
@@ -399,6 +399,8 @@ def initialize(model: nn.Module,
...
@@ -399,6 +399,8 @@ def initialize(model: nn.Module,
else
:
else
:
scatter_gather
=
False
scatter_gather
=
False
if
use_interleaved
:
if
use_interleaved
:
if
isinstance
(
model
,
nn
.
Sequential
):
model
=
nn
.
ModuleList
([
model
])
schedule
=
InterleavedPipelineSchedule
(
gpc
.
config
.
NUM_MICRO_BATCHES
,
schedule
=
InterleavedPipelineSchedule
(
gpc
.
config
.
NUM_MICRO_BATCHES
,
gpc
.
config
.
model
.
num_chunks
,
gpc
.
config
.
model
.
num_chunks
,
tensor_shape
=
tensor_shape
,
tensor_shape
=
tensor_shape
,
...
@@ -434,7 +436,6 @@ def initialize(model: nn.Module,
...
@@ -434,7 +436,6 @@ def initialize(model: nn.Module,
accumulate_size
=
grad_accum_size
,
accumulate_size
=
grad_accum_size
,
gradient_handlers
=
gradient_handlers
,
gradient_handlers
=
gradient_handlers
,
lr_scheduler
=
lr_scheduler
)
lr_scheduler
=
lr_scheduler
)
engine
=
Engine
(
model
=
model
,
engine
=
Engine
(
model
=
model
,
optimizer
=
optimizer
,
optimizer
=
optimizer
,
criterion
=
criterion
,
criterion
=
criterion
,
...
...
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