Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
e84250e8
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e84250e8
编写于
8月 09, 2022
作者:
Y
Yuang Liu
提交者:
GitHub
8月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[model parallel] enable mp to use fused linear (#44968)
上级
c91aaced
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
48 addition
and
10 deletion
+48
-10
python/paddle/distributed/fleet/meta_parallel/parallel_layers/mp_layers.py
...tributed/fleet/meta_parallel/parallel_layers/mp_layers.py
+48
-10
未找到文件。
python/paddle/distributed/fleet/meta_parallel/parallel_layers/mp_layers.py
浏览文件 @
e84250e8
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
# limitations under the License.
# limitations under the License.
import
paddle
import
paddle
from
paddle.fluid
import
core
from
paddle.fluid.dygraph.layers
import
Layer
from
paddle.fluid.dygraph.layers
import
Layer
from
.random
import
get_rng_state_tracker
from
.random
import
get_rng_state_tracker
from
paddle.nn
import
functional
as
F
from
paddle.nn
import
functional
as
F
...
@@ -27,6 +28,13 @@ __all__ = []
...
@@ -27,6 +28,13 @@ __all__ = []
# language models using model parallelism[J]. arXiv preprint arXiv:1909.08053, 2019. (https://arxiv.org/abs/1909.08053)
# language models using model parallelism[J]. arXiv preprint arXiv:1909.08053, 2019. (https://arxiv.org/abs/1909.08053)
def
is_fused_matmul_bias_supported
():
if
paddle
.
is_compiled_with_cuda
()
and
not
paddle
.
is_compiled_with_rocm
():
return
hasattr
(
core
.
ops
,
'fused_gemm_epilogue'
)
else
:
return
False
class
VocabParallelEmbedding
(
Layer
):
class
VocabParallelEmbedding
(
Layer
):
def
__init__
(
self
,
def
__init__
(
self
,
...
@@ -100,7 +108,8 @@ class ColumnParallelLinear(Layer):
...
@@ -100,7 +108,8 @@ class ColumnParallelLinear(Layer):
weight_attr
=
None
,
weight_attr
=
None
,
has_bias
=
None
,
has_bias
=
None
,
gather_output
=
True
,
gather_output
=
True
,
name
=
None
):
name
=
None
,
fuse_matmul_bias
=
False
):
super
(
ColumnParallelLinear
,
self
).
__init__
()
super
(
ColumnParallelLinear
,
self
).
__init__
()
self
.
model_parallel_group
=
tp
.
_HYBRID_PARALLEL_GROUP
.
get_model_parallel_group
(
self
.
model_parallel_group
=
tp
.
_HYBRID_PARALLEL_GROUP
.
get_model_parallel_group
(
...
@@ -147,6 +156,18 @@ class ColumnParallelLinear(Layer):
...
@@ -147,6 +156,18 @@ class ColumnParallelLinear(Layer):
else
:
else
:
self
.
bias
=
None
self
.
bias
=
None
self
.
linear
=
F
.
linear
if
fuse_matmul_bias
:
if
not
is_fused_matmul_bias_supported
():
raise
NotImplementedError
(
"You set fuse_matmul_bias=True in ColumnParallelLinear, "
"however, the paddle you are using not support this operation. "
"Please set fuse_matmul_bias=False or use paddle compiled "
"with cuda 11.6 or higher."
)
from
paddle.incubate.nn.functional
import
fused_linear
self
.
linear
=
fused_linear
def
forward
(
self
,
x
):
def
forward
(
self
,
x
):
# use inner api to process identity
# use inner api to process identity
if
self
.
is_mp
:
if
self
.
is_mp
:
...
@@ -155,7 +176,7 @@ class ColumnParallelLinear(Layer):
...
@@ -155,7 +176,7 @@ class ColumnParallelLinear(Layer):
else
:
else
:
input_parallel
=
x
input_parallel
=
x
output_parallel
=
F
.
linear
(
input_parallel
,
output_parallel
=
self
.
linear
(
input_parallel
,
self
.
weight
,
self
.
weight
,
self
.
bias
,
self
.
bias
,
name
=
self
.
_name
)
name
=
self
.
_name
)
...
@@ -176,7 +197,8 @@ class RowParallelLinear(Layer):
...
@@ -176,7 +197,8 @@ class RowParallelLinear(Layer):
weight_attr
=
None
,
weight_attr
=
None
,
has_bias
=
True
,
has_bias
=
True
,
input_is_parallel
=
False
,
input_is_parallel
=
False
,
name
=
None
):
name
=
None
,
fuse_matmul_bias
=
False
):
super
(
RowParallelLinear
,
self
).
__init__
()
super
(
RowParallelLinear
,
self
).
__init__
()
self
.
in_features
=
in_features
self
.
in_features
=
in_features
...
@@ -225,6 +247,18 @@ class RowParallelLinear(Layer):
...
@@ -225,6 +247,18 @@ class RowParallelLinear(Layer):
else
:
else
:
self
.
bias
=
None
self
.
bias
=
None
self
.
linear
=
F
.
linear
if
fuse_matmul_bias
:
if
not
is_fused_matmul_bias_supported
():
raise
NotImplementedError
(
"You set fuse_matmul_bias=True in RowParallelLinear, "
"however, the paddle you are using not support this operation. "
"Please set fuse_matmul_bias=False or use paddle compiled "
"with cuda 11.6 or higher."
)
from
paddle.incubate.nn.functional
import
fused_linear
self
.
linear
=
fused_linear
def
forward
(
self
,
x
):
def
forward
(
self
,
x
):
if
self
.
input_is_parallel
or
(
not
self
.
is_mp
):
if
self
.
input_is_parallel
or
(
not
self
.
is_mp
):
input_parallel
=
x
input_parallel
=
x
...
@@ -233,18 +267,22 @@ class RowParallelLinear(Layer):
...
@@ -233,18 +267,22 @@ class RowParallelLinear(Layer):
input_parallel
=
paddle
.
distributed
.
collective
.
_c_split
(
input_parallel
=
paddle
.
distributed
.
collective
.
_c_split
(
x
,
group
=
self
.
model_parallel_group
)
x
,
group
=
self
.
model_parallel_group
)
output_parallel
=
F
.
linear
(
input_parallel
,
self
.
weight
,
name
=
self
.
_name
)
if
self
.
is_mp
:
if
self
.
is_mp
:
output_parallel
=
self
.
linear
(
input_parallel
,
self
.
weight
,
name
=
self
.
_name
)
output_
=
paddle
.
distributed
.
collective
.
_mp_allreduce
(
output_
=
paddle
.
distributed
.
collective
.
_mp_allreduce
(
output_parallel
,
output_parallel
,
group
=
self
.
model_parallel_group
,
group
=
self
.
model_parallel_group
,
use_calc_stream
=
True
,
use_calc_stream
=
True
,
use_model_parallel
=
True
)
use_model_parallel
=
True
)
output
=
output_
+
self
.
bias
if
self
.
bias
is
not
None
else
output_
else
:
else
:
output_
=
output_parallel
output
=
self
.
linear
(
input_parallel
,
self
.
weight
,
self
.
bias
,
name
=
self
.
_name
)
output
=
output_
+
self
.
bias
if
self
.
bias
is
not
None
else
output_
return
output
return
output
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录