Skip to content

Commit 8543751

Browse files
authored
【Hackathon 6th Fundable Projects 3 No.98】dgc_clip_by_norm (#65152)
* Fix * ci * Fix * Fix
1 parent d730da7 commit 8543751

File tree

12 files changed

+192
-256
lines changed

12 files changed

+192
-256
lines changed

paddle/fluid/operators/clip_by_norm_op.h

Lines changed: 0 additions & 91 deletions
This file was deleted.

paddle/fluid/operators/dgc_clip_by_norm_op.cc

Lines changed: 0 additions & 72 deletions
This file was deleted.

paddle/fluid/operators/dgc_clip_by_norm_op.cu

Lines changed: 0 additions & 19 deletions
This file was deleted.

paddle/fluid/operators/dgc_clip_by_norm_op.h

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "paddle/phi/core/kernel_registry.h"
16+
#include "paddle/phi/kernels/impl/dgc_clip_by_norm_kernel_impl.h"
17+
PD_REGISTER_KERNEL(
18+
dgc_clip_by_norm, CPU, ALL_LAYOUT, phi::DGCClipByNormKernel, float) {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "paddle/phi/core/kernel_registry.h"
16+
#include "paddle/phi/kernels/impl/dgc_clip_by_norm_kernel_impl.h"
17+
PD_REGISTER_KERNEL(
18+
dgc_clip_by_norm, GPU, ALL_LAYOUT, phi::DGCClipByNormKernel, float) {}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
#include "glog/logging.h"
17+
#include "paddle/phi/kernels/clip_by_norm_kernel.h"
18+
19+
namespace phi {
20+
21+
template <typename T, typename Context>
22+
void DGCClipByNormKernel(const Context& dev_ctx,
23+
const DenseTensor& x_in,
24+
const DenseTensor& current_step_in,
25+
float max_norm,
26+
float rampup_begin_step,
27+
DenseTensor* out) {
28+
if (static_cast<int>(rampup_begin_step) < 0) {
29+
return;
30+
}
31+
32+
auto current_step_tensor = &current_step_in;
33+
auto* current_step = current_step_tensor->data<T>();
34+
35+
VLOG(10) << "current_step:" << *current_step
36+
<< ", rampup_begin_step:" << rampup_begin_step;
37+
38+
if (static_cast<int>(*current_step) < static_cast<int>(rampup_begin_step)) {
39+
VLOG(10) << "current_step:" << *current_step
40+
<< " < rampup_begin_step:" << rampup_begin_step
41+
<< " so does't use dgc_clip_by_norm";
42+
return;
43+
}
44+
45+
auto* x = &x_in;
46+
auto* y = out;
47+
return phi::ClipByNormKernel<T>(dev_ctx, *x, max_norm, y);
48+
}
49+
} // namespace phi
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "paddle/phi/core/kernel_registry.h"
16+
#include "paddle/phi/kernels/selected_rows/impl/dgc_clip_by_norm_kernel_impl.h"
17+
PD_REGISTER_KERNEL(
18+
dgc_clip_by_norm_sr, CPU, ALL_LAYOUT, phi::sr::DGCClipByNormKernel, float) {
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "paddle/phi/core/kernel_registry.h"
16+
#include "paddle/phi/kernels/selected_rows/impl/dgc_clip_by_norm_kernel_impl.h"
17+
PD_REGISTER_KERNEL(
18+
dgc_clip_by_norm_sr, GPU, ALL_LAYOUT, phi::sr::DGCClipByNormKernel, float) {
19+
}

0 commit comments

Comments
 (0)