Skip to content

Commit 611eb6a

Browse files
committed
[Phi] move truncated_gaussian_random, delete useless codes
1 parent 53193c4 commit 611eb6a

File tree

4 files changed

+1
-156
lines changed

4 files changed

+1
-156
lines changed

paddle/fluid/operators/truncated_gaussian_random_op.cc

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,6 @@ limitations under the License. */
2323
namespace paddle {
2424
namespace operators {
2525

26-
template <typename T>
27-
class CPUTruncatedGaussianRandomKernel : public framework::OpKernel<T> {
28-
public:
29-
void Compute(const framework::ExecutionContext& context) const override {
30-
float mean = context.Attr<float>("mean");
31-
float std = context.Attr<float>("std");
32-
auto* tensor = context.Output<framework::Tensor>("Out");
33-
T* data = tensor->mutable_data<T>(context.GetPlace());
34-
35-
std::uniform_real_distribution<T> dist(std::numeric_limits<float>::min(),
36-
1.0);
37-
TruncatedNormal<T> truncated_normal(mean, std);
38-
int64_t size = tensor->numel();
39-
40-
unsigned int seed = static_cast<unsigned int>(context.Attr<int>("seed"));
41-
auto engine = framework::GetCPURandomEngine(seed);
42-
for (int64_t i = 0; i < size; ++i) {
43-
data[i] = truncated_normal(dist(*engine));
44-
}
45-
}
46-
};
47-
4826
class TruncatedGaussianRandomOp : public framework::OperatorWithKernel {
4927
public:
5028
using framework::OperatorWithKernel::OperatorWithKernel;

paddle/fluid/operators/truncated_gaussian_random_op.cu

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

paddle/phi/kernels/cpu/truncated_gaussian_random_kernel.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ void TruncatedGaussianRandomKernel(const Context& dev_ctx,
3333
int seed,
3434
DataType dtype,
3535
DenseTensor* out) {
36-
// float mean = context.Attr<float>("mean");
37-
// float std = context.Attr<float>("std");
38-
// auto* tensor = context.Output<framework::Tensor>("Out");
39-
4036
auto tensor = out;
4137

4238
T* data = dev_ctx.template Alloc<T>(tensor);
@@ -46,7 +42,6 @@ void TruncatedGaussianRandomKernel(const Context& dev_ctx,
4642
TruncatedNormal<T> truncated_normal(mean, std);
4743
int64_t size = tensor->numel();
4844

49-
// unsigned int seed = static_cast<unsigned int>(context.Attr<int>("seed"));
5045
auto engine = paddle::framework::GetCPURandomEngine(seed);
5146
for (int64_t i = 0; i < size; ++i) {
5247
data[i] = truncated_normal(dist(*engine));

paddle/phi/kernels/gpu/truncated_gaussian_random_kernel.cu

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,17 @@ void TruncatedGaussianRandomKernel(const Context& dev_ctx,
9393
int seed,
9494
DataType dtype,
9595
DenseTensor* out) {
96-
// auto* tensor = context.Output<framework::Tensor>("Out");
97-
9896
auto tensor = out;
9997

10098
T* data = dev_ctx.template Alloc<T>(tensor);
10199

102-
// unsigned int seed = static_cast<unsigned int>(context.Attr<int>("seed"));
103100
bool seed_flag = false;
104101
if (seed == 0) {
105102
std::random_device rd;
106103
seed = rd();
107104
seed_flag = true;
108105
}
109-
// T mean = static_cast<T>(context.Attr<float>("mean"));
110-
// T std = static_cast<T>(context.Attr<float>("std"));
106+
111107
thrust::counting_iterator<int64_t> index_sequence_begin(0);
112108
int64_t size = tensor->numel();
113109

0 commit comments

Comments
 (0)