Skip to content

Commit

Permalink
feat(pir): reg dgc
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyewww committed Mar 17, 2024
1 parent 9eb80b4 commit 2dc683d
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
2 changes: 2 additions & 0 deletions paddle/fluid/pir/dialect/op_generator/ops_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
'decayed_adagrad',
'distributed_push_sparse',
'distributed_lookup_table',
'dgc',
'dgc_',
'dpsgd',
'embedding_grad_sparse',
'ftrl',
Expand Down
7 changes: 7 additions & 0 deletions paddle/fluid/pir/dialect/operator/ir/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@
optional : in_accum, in_state, out_scale, out_accum, out_state
inplace : (scale -> out_scale, in_accum -> out_accum, in_state -> out_state)

- op : dgc
args : (Tensor u, Tensor v, Tensor grad, Tensor param, Tensor current_step, Tensor nranks, float[] sparsity, , float m=0.9, bool use_nesterov=true, float rampup_begin_step=0.0, float rampup_step=0.0, float regular_coeff=0.0, int regular_type=0)
output : Tensor(u_out), Tensor(v_out), Tensor(encode_grad), Tensor(grad_out), Tensor(k), Tensor(gather_buff)
kernel :
func : dgc
inplace: (u -> u_out), (v -> v_out), (grad -> grad_out)

- op : disable_check_model_nan_inf
args: (Tensor x, int flag = 0)
output: Tensor(out)
Expand Down
6 changes: 6 additions & 0 deletions paddle/phi/api/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3649,6 +3649,12 @@
outputs:
{param_out : ParamOut, moment_out : MomentOut}

- op: dgc
inputs:
{u: U, v: V, grad: Grad}
outputs:
{u_out: U_out, v_out: V_out, encode_grad: EncodeGrad, grad_out: Grad_out, gather_buff: GatherBuff}

- op: distribute_fpn_proposals
inputs :
{fpn_rois: FpnRois, rois_num: RoisNum}
Expand Down
2 changes: 1 addition & 1 deletion test/ir/pir/translator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST
test_distributed_lookup_table_translate)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST
test_distributed_push_sparse_translator)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_distributed_fused_lamb_init)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_dgc_translate)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_nop_translator)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_partial_send_translator)
list(APPEND DISTRIBUTED_OP_TRANSLATOR_TEST test_partial_recv_translator)
Expand Down
77 changes: 77 additions & 0 deletions test/ir/pir/translator/test_dgc_translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import test_op_translator

import paddle
from paddle.base.layer_helper import LayerHelper


class TestDgcOpTranslator(test_op_translator.TestOpTranslator):
def append_op(self):
self.op_type = "dgc"
g_array_size = 102400
u = paddle.ones(shape=(g_array_size,), dtype='float32')
v = paddle.ones(shape=(g_array_size,), dtype='float32')
grad = paddle.ones(shape=(g_array_size,), dtype='float32')
param = paddle.ones(shape=(g_array_size,), dtype='float32')
current_step = paddle.to_tensor([0.0], dtype='float32')
nranks = paddle.to_tensor([2.0], dtype='float32')

u_out = paddle.ones(shape=(g_array_size,), dtype='float32')
v_out = paddle.ones(shape=(g_array_size,), dtype='float32')
encode_grad = paddle.ones(shape=(g_array_size,), dtype='float32')
grad_out = paddle.ones(shape=(g_array_size,), dtype='float32')
k = paddle.to_tensor([0.0], dtype='float32')
gather_buff = paddle.ones(shape=(g_array_size,), dtype='float32')
attrs = {
'm': 0.9,
'use_nesterov': True,
'sparsity': [],
'padding_idx': -1,
'rampup_begin_step': 0.0,
'rampup_step': 0.0,
'regular_coeff': 0.0,
'regular_type': 0,
}
helper = LayerHelper(self.op_type)
helper.append_op(
type=self.op_type,
inputs={
"U": u,
"V": v,
"Grad": grad,
"Param": param,
"current_step": current_step,
"nranks": nranks,
},
outputs={
"U_out": u_out,
"V_out": v_out,
"EncodeGrad": encode_grad,
"Grad_out": grad_out,
"k": k,
"GatherBuff": gather_buff,
},
attrs=attrs,
)

def test_translator(self):
self.check()


if __name__ == "__main__":
unittest.main()

0 comments on commit 2dc683d

Please sign in to comment.