Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add op rrelu #9736

Merged
merged 41 commits into from
Feb 2, 2023
Merged

Conversation

youxiudeshouyeren
Copy link
Contributor

@youxiudeshouyeren youxiudeshouyeren commented Jan 11, 2023

Comment on lines +70 to +93
test_case.assertTrue(
np.allclose(
(flow.where(flow_tensor >= 0, 1, 0)).cpu().detach().numpy(),
(flow.where(flow_div == 1.0, 1, 0)).cpu().detach().numpy(),
)
)
test_case.assertTrue(
np.allclose(
(flow.where(flow_tensor < 0, 1, 0)).cpu().detach().numpy(),
(
flow.where(
flow.logical_and(
flow.logical_and(flow_div >= rate, flow_div <= (rate + 0.5)),
flow_tensor < 0,
),
1,
0,
)
)
.cpu()
.detach()
.numpy(),
)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里测试的是原来大于等于0的位置,还是原数据;小于0的位置,元素乘的因子在输入参数的区间内部。

oneflow/user/kernels/rrelu_kernel.cu Outdated Show resolved Hide resolved
oneflow/user/kernels/rrelu_kernel.cu Outdated Show resolved Hide resolved
oneflow/core/autograd/gradient_funcs/rrelu.cpp Outdated Show resolved Hide resolved
oneflow/core/functional/functional_api.yaml Outdated Show resolved Hide resolved
oneflow/core/functional/impl/activation_functor.cpp Outdated Show resolved Hide resolved
python/oneflow/framework/docstr/activation.py Outdated Show resolved Hide resolved
oneflow/core/functional/impl/activation_functor.cpp Outdated Show resolved Hide resolved
oneflow/core/functional/functional_api.yaml Outdated Show resolved Hide resolved
python/oneflow/nn/functional/__init__.py Outdated Show resolved Hide resolved
python/oneflow/test/modules/test_rrelu.py Show resolved Hide resolved
Comment on lines +38 to +41
OF_LAUNCH_BOUNDS_2(block_size_bound, grid_size_bound)
__global__
void RReluKernel(int64_t numel, uint64_t seed, uint64_t offset, const T* in_ptr, T* out_ptr,
T* noise_data_ptr, Distribution dist_func, Transform transform_func) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里没有必要再实现一遍,可以使用DistributionElementwiseGridStrideKernel模板函数,二者实现一样的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RReLU需要传递三个指针进去,并且还存在判断,DistributionElementwiseGridStrideKernel好像不能实现。单修改transform_func的话,也需要修改DistributionElementwiseGridStrideKernel中transform_func那部分的接口,因为DistributionElementwiseGridStrideKernel只是赋值了随机数,没有判断大小和乘法的那部分。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里没有必要再实现一遍,可以使用DistributionElementwiseGridStrideKernel模板函数,二者实现一样的

DistributionElementwiseGridStrideKernel在运行时只给transform_func传递了一个random_val的随机数,我这里需要input进行条件判断,out指针来进行和随机数的乘法,没办法直接用DistributionElementwiseGridStrideKernel模板函数

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里没有必要再实现一遍,可以使用DistributionElementwiseGridStrideKernel模板函数,二者实现一样的

DistributionElementwiseGridStrideKernel在运行时只给transform_func传递了一个random_val的随机数,我这里需要input进行条件判断,out指针来进行和随机数的乘法,没办法直接用DistributionElementwiseGridStrideKernel模板函数

明白了,这里有两个输出

oneflow/user/kernels/rrelu_kernel.cu Outdated Show resolved Hide resolved
oneflow/core/functional/functional_api.yaml Outdated Show resolved Hide resolved
@youxiudeshouyeren youxiudeshouyeren enabled auto-merge (squash) January 31, 2023 03:58
@youxiudeshouyeren youxiudeshouyeren merged commit 76c8e67 into Oneflow-Inc:master Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants