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

Dev logical_xor module #5694

Merged
merged 28 commits into from
Aug 11, 2021
Merged

Dev logical_xor module #5694

merged 28 commits into from
Aug 11, 2021

Conversation

zfu82
Copy link
Contributor

@zfu82 zfu82 commented Aug 2, 2021

image

@CLAassistant
Copy link

CLAassistant commented Aug 2, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@hengzi hengzi left a comment

Choose a reason for hiding this comment

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

添加API文档截图,参考 #5636

@hengzi hengzi added fmt-only and removed fmt-only labels Aug 5, 2021
@zfu82 zfu82 marked this pull request as ready for review August 5, 2021 07:40
Comment on lines 64 to 66
logical_and() -> Tensor

See :func:`oneflow.logical_and`
Copy link
Contributor

Choose a reason for hiding this comment

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

logical_and -> logical_xor


>>> input1 = flow.Tensor(np.array([1, 0, 1]).astype(np.float32), dtype=flow.float32)
>>> input2 = flow.Tensor(np.array([1, 1, 0]).astype(np.float32), dtype=flow.float32)
>>> out = flow.logical_and(input1, input2)
Copy link
Contributor

Choose a reason for hiding this comment

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

logical_and -> logical_xor
运行这个文件看下是否有报错

Comment on lines 61 to 63
def logical_or_op_tensor(input, other):
"""
logical_or() -> Tensor
Copy link
Contributor

Choose a reason for hiding this comment

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

logical_or -> logical_xor

See :func:`oneflow.logical_xor`

"""
return LogicalXor()(input, other)
Copy link
Contributor

Choose a reason for hiding this comment

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

之前因为功能的局限,才不得不用实例化 Module 的方式调用。现在有了 flow.F 下的 functional call,尽量直接调用。
可以参考这个PR 进行修改 #5754

@@ -128,6 +128,7 @@ def custom_exit(returncode):
import oneflow.compatible.single_client.nn.modules.greater_equal
Copy link
Contributor

Choose a reason for hiding this comment

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

single_client 下的文件不用修改,都复原吧。

template<typename T>
struct BinaryFuncOR final {
static OF_DEVICE_FUNC const int8_t Invoke(const T x, const T y) { return x || y; }
};
template<typename T>
struct BinaryFuncAny final {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个 struct 是不是不需要了

Copy link
Contributor

Choose a reason for hiding this comment

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

这里是从上面移到下面了,还是需要的

@@ -141,6 +141,7 @@ def Sync():
import oneflow.nn.modules.greater_equal
import oneflow.nn.modules.logical_and
import oneflow.nn.modules.logical_or
import oneflow.nn.modules.logical_xor
Copy link
Contributor

Choose a reason for hiding this comment

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

这个是当作 package 导入,没有必要,顺便把上面的 logical_andlogical_orlogical_xor 也给删了吧。


"""
if other.dtype != input.dtype:
other = flow.cast(other, input.dtype)
Copy link
Contributor

Choose a reason for hiding this comment

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

在这里加个以shape 的检查吧。类似

assert input.shape == other.shape, "shape of input and other should be same"

因为你这个算子内部是支持 broadcast 的,但是文档和 pytorch 对齐,是element-wise的。

或者,如果想作为 pytorch 超集,就在文档钟说明支持 broadcast。并且在 doctest、test 里添加相关的例子。

@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 10, 2021 16:29
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 10, 2021 17:50
@oneflow-ci-bot oneflow-ci-bot self-requested a review August 10, 2021 19:16
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 10, 2021 23:43
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot August 11, 2021 01:12
@oneflow-ci-bot oneflow-ci-bot self-requested a review August 11, 2021 02:48
@github-actions
Copy link
Contributor

Speed stats:
GPU Name: GeForce GTX 1080 

PyTorch resnet50 time: 138.5ms (= 6927.0ms / 50, input_shape=[16, 3, 224, 224], backward is enabled)
OneFlow resnet50 time: 125.9ms (= 6296.8ms / 50, input_shape=[16, 3, 224, 224], backward is enabled)
Relative speed: 1.10 (= 138.5ms / 125.9ms)

PyTorch resnet50 time: 82.1ms (= 4106.6ms / 50, input_shape=[8, 3, 224, 224], backward is enabled)
OneFlow resnet50 time: 73.0ms (= 3651.0ms / 50, input_shape=[8, 3, 224, 224], backward is enabled)
Relative speed: 1.12 (= 82.1ms / 73.0ms)

PyTorch resnet50 time: 57.1ms (= 2852.6ms / 50, input_shape=[4, 3, 224, 224], backward is enabled)
OneFlow resnet50 time: 51.4ms (= 2570.8ms / 50, input_shape=[4, 3, 224, 224], backward is enabled)
Relative speed: 1.11 (= 57.1ms / 51.4ms)

PyTorch resnet50 time: 47.8ms (= 2388.8ms / 50, input_shape=[2, 3, 224, 224], backward is enabled)
OneFlow resnet50 time: 42.0ms (= 2102.2ms / 50, input_shape=[2, 3, 224, 224], backward is enabled)
Relative speed: 1.14 (= 47.8ms / 42.0ms)

PyTorch resnet50 time: 42.5ms (= 2126.7ms / 50, input_shape=[1, 3, 224, 224], backward is enabled)
OneFlow resnet50 time: 41.3ms (= 2064.7ms / 50, input_shape=[1, 3, 224, 224], backward is enabled)
Relative speed: 1.03 (= 42.5ms / 41.3ms)

@oneflow-ci-bot oneflow-ci-bot merged commit 6e18a5f into master Aug 11, 2021
@oneflow-ci-bot oneflow-ci-bot deleted the dev_logical_xor_module branch August 11, 2021 04:34
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