Skip to content

Commit a9bedc7

Browse files
[Sharderformer] Support zbv in Sharderformer Policy (#6150)
* [feat] Sharderformer support zbv * [feat] support chatglm2, command, deepseek for zbv * [feat] support zbv in shardformer policy: falcon,gptj,mistral,opt,qwen2,t5, vit, whisper * [feat] support GPT2FusedLinearConv1D * [feat] support GPT2FusedLinear (without tp) * [fix] debug FusedConvLinear * [shardfromer] support gpt2 policy for zbv, support GPT2FusedLinearConv Col and Row. * [Shardformer] support FusedLinear1D base for zbv * [shardformer] support zbv in FusedLinear1D base, Col, Row * [shardformer] support zbv in blip2 and sam policy * [shardformer] fix bug incorrect number of gradients; add fusedLinear base testcase; * [fix] fix incorrect number of gradients ; * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [Shardformer] add en doc for zbv; * [fix] fix typo in Model compatibility table * [fix] fix API Reference typo * [Shardformer] add zh-Han doc for zbv * [fix] fix Linear name; update en & zh doc * [fix] fix shardformer doc import err * [fix] fix shardconfig import in doc * [fix] fix shardformer doc * [fix] fix shardconfig doc * [fix] fix config * [fix] remove shardconfig * [fix] fix doc * [feat] add zbv doc string * [fix] rm doc * [fix] fix doc * [fix] empty zbv doc * [fix] ifx torch version * [fix] fix torch version * [fix] fix torch versions * [fix] fix torch versions * [fix] fix pyramid versions * [fix] fix pyramid, zope version * [fix] try fix workflow * [fix] try import ShardConfig in yml * [fix] fix workflow * [fix] fix workflow * [fix] fix workflow * [fix] fix workflow * [fix] fix ci * [fix] fix zbv doc * [fix] fix param for qkv linear, gpt2fused linear; fix requirments; * [fix] fix policy use fused_linear * [fix] fix weight grad none, err caused by weight ptr change * [fix] fix comm in WeightGradStore * [fix] fix WeightGradStore pop param * [fix] remove useless param in doc; fix gpt2 qkv test; * [shardformer] simplify execute_w_pass_grad_accum; * [fix] rm useless comments * [shardformer] simplify execute_w_pass_grad_accum & execute_w_pass * [shardformer] Run meaningful doc test * [shadformer] fix doc test cmd; --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent af06d16 commit a9bedc7

27 files changed

+3513
-318
lines changed

.github/workflows/doc_check_on_pr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
# there is no main branch, so it's safe to checkout the main branch from the merged branch
5959
# docer will rebase the remote main branch to the merged branch, so we have to config user
6060
- name: Make the merged branch main
61+
6162
run: |
6263
cd ColossalAI
6364
git checkout -b main

colossalai/pipeline/schedule/zero_bubble_pp.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ def _wait_p2p(wait_handles: List[torch.cuda.Event]) -> None:
3838

3939

4040
class ZeroBubbleVPipeScheduler(PipelineSchedule):
41+
r"""
42+
ZeroBubbleVPipeScheduler
43+
44+
Args:
45+
stage_manager (PipelineStageManager): If using pipeline parallelism, it's necessary to specify a pipeline stage manager for inter-process communication in pipeline parallelism. Defaults to None, which means not using pipeline parallelism.
46+
schedule (List[ScheduledNode]): Schedule for ZeroBubbleVPipe.
47+
num_model_chunks (int) : The number of model chunk in a device.
48+
num_microbatch (Optional[int]): The number of microbatch.
49+
microbatch_size (Optional[int]): The size per microbatch.
50+
enable_metadata_cache (bool): whether to enable metadata cache to acclerate communication.
51+
overlap_p2p (bool): whether to use overlap_p2p.
52+
"""
53+
4154
def __init__(
4255
self,
4356
stage_manager: PipelineStageManager,

colossalai/pipeline/weight_grad_store.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class WeightGradStore:
88

99
@classmethod
1010
def put(cls, total_input, grad_output, weight, func):
11-
# func(total_input, grad_output, weight.main_grad)
1211
cls.cache.append((total_input, grad_output, weight, func))
1312

1413
@classmethod
@@ -18,15 +17,26 @@ def flush(cls, chunk=0):
1817

1918
@classmethod
2019
def pop(cls, chunk=0):
21-
# print(f"chunk id {chunk} queue size {cls.weight_grad_queue[chunk].qsize()}")
2220
if cls.weight_grad_queue[chunk].qsize() > 0:
2321
stored_grads = cls.weight_grad_queue[chunk].get()
2422
for total_input, grad_output, weight, func in stored_grads:
25-
if weight.grad is not None:
26-
func(total_input, grad_output, weight.grad)
27-
# for first bwd; weight.grad is None, assign grad_weight to weight.grad
23+
if isinstance(weight, tuple):
24+
# In order to be hooked into Gemini's '__torch_function__', adding a view operation to weight and bias.
25+
# View will lead to weight ptr change
26+
# weight_cal & weight_origin in tuple, weight_cal use to cal dw, weight_origin use to update
27+
_, weight_origin = weight
28+
if weight_origin.grad is not None:
29+
func(total_input, grad_output, weight_origin.grad)
30+
# for first bwd; weight.grad is None, assign grad_weight to weight.grad
31+
else:
32+
grad_weight = func(total_input, grad_output)
33+
weight_origin.grad = grad_weight
2834
else:
29-
grad_weight = func(total_input, grad_output)
30-
weight.grad = grad_weight
35+
if weight.grad is not None:
36+
func(total_input, grad_output, weight.grad)
37+
# for first bwd; weight.grad is None, assign grad_weight to weight.grad
38+
else:
39+
grad_weight = func(total_input, grad_output)
40+
weight.grad = grad_weight
3141
else:
3242
raise Exception("Pop empty queue.")

colossalai/shardformer/layer/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,24 @@
66
from .loss import cross_entropy_1d, dist_cross_entropy
77
from .normalization import FusedLayerNorm, FusedRMSNorm, LayerNorm, RMSNorm
88
from .parallel_module import ParallelModule
9-
from .qkv_fused_linear import FusedLinear1D_Col, FusedLinear1D_Row, GPT2FusedLinearConv1D_Col, GPT2FusedLinearConv1D_Row
9+
from .qkv_fused_linear import (
10+
FusedLinear,
11+
FusedLinear1D_Col,
12+
FusedLinear1D_Row,
13+
GPT2FusedLinearConv,
14+
GPT2FusedLinearConv1D_Col,
15+
GPT2FusedLinearConv1D_Row,
16+
)
1017

1118
__all__ = [
1219
"Embedding1D",
1320
"VocabParallelEmbedding1D",
1421
"LinearWithGradAccum",
1522
"Linear1D_Col",
1623
"Linear1D_Row",
17-
"GPT2FusedLinearConv1D_Col",
24+
"GPT2FusedLinearConv",
1825
"GPT2FusedLinearConv1D_Row",
26+
"GPT2FusedLinearConv1D_Col",
1927
"DropoutForParallelInput",
2028
"DropoutForReplicatedInput",
2129
"cross_entropy_1d",
@@ -26,6 +34,7 @@
2634
"FusedLayerNorm",
2735
"FusedRMSNorm",
2836
"FusedLinear1D_Col",
37+
"FusedLinear",
2938
"ParallelModule",
3039
"PaddingEmbedding",
3140
"PaddingLMHead",

0 commit comments

Comments
 (0)