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

Fix dropout functor error #9808

Merged
merged 10 commits into from
Jan 31, 2023
Merged

Fix dropout functor error #9808

merged 10 commits into from
Jan 31, 2023

Conversation

clackhan
Copy link
Contributor

修复dropout1d/2d/3d中的错误,打开相关测试, 修复 https://github.com/Oneflow-Inc/OneTeam/issues/1893 中的问题。

@@ -2846,31 +2846,29 @@ Maybe<Tensor> DropoutImpl(const std::shared_ptr<one::Tensor>& input, const float
if (p == 1) {
std::shared_ptr<Tensor> other =
JUST(Constant(*input->shape(), Scalar(0.0), input->dtype(), JUST(input->device())));
return InplaceMul(input, other);
return Mul(input, other);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

若使用inplace版mul,则后向计算检查会报错。

}
std::shared_ptr<Tensor> noise = JUST(MakeFeatureNoise(input));
noise =
JUST(BernoulliProb(noise, 1.0 - p, noise->dtype(), JUST(one::DefaultAutoGenerator()), false));
noise = JUST(InplaceScalarDiv(noise, Scalar(1.0 - p)));
noise = JUST(InplaceMul(input, noise));
return noise;
return JUST(Mul(input, noise));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

同上

Comment on lines +2863 to 2864
CHECK_EQ_OR_RETURN(p < 0 || p > 1.0, false)
<< "dropout probability has to be between 0 and 1, but got " << p;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里之前应该是写错了,结果应该是 false

"Note that dropout1d exists to provide channel-wise dropout on inputs with 1 "
"spatial dimension, a channel dimension, and an optional batch dimension "
"(i.e. 2D or 3D inputs).";
bool is_batched = (input_dim == 3);
std::shared_ptr<one::Tensor> result;
std::shared_ptr<one::Tensor> result = input;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

需要先给result赋值为input,否则is_batchedtrue时,DropoutImpl输入为空。

Comment on lines +2889 to +2895
LOG(WARNING)
<< "dropout2d: Received a " << input_dim
<< "-D input to dropout2d, which is deprecated "
"and will result in an error in a future release. To retain the behavior "
"and silence this warning, please use dropout instead. Note that dropout2d "
"exists to provide channel-wise dropout on inputs with 2 spatial dimensions, "
"a channel dimension, and an optional batch dimension (i.e. 3D or 4D inputs).";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里对齐pytorch,弹warning,不报错

"a channel dimension, and an optional batch dimension (i.e. 3D or 4D inputs).";
}
if (input_dim == 3) {
LOG(WARNING)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

同上

"exists to provide channel-wise dropout on inputs with 3 spatial dimensions, "
"a channel dimension, and an optional batch dimension (i.e. 4D or 5D inputs).";
if (input_dim != 4 && input_dim != 5) {
LOG(WARNING)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

同上

device = random_device()
x = random_tensor(ndim=random(), dim0=random(1, 8)).to(device)
m = torch.nn.Dropout(p=0, inplace=random_bool())
m = torch.nn.Dropout(p=0, inplace=False)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

设置inplace为false,因为不能对 requires_grad = True 的叶子节点,做 inplace 修改

Comment on lines +375 to +376
@autotest(n=5, check_graph=False)
def test_dropout_eval(test_case):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

在graph模式下(build函数中),m.eval()时非法的,故这几个用例关闭graph测试

@github-actions
Copy link
Contributor

Static analysis with clang failed. PR label automerge has been removed

@clackhan clackhan removed the request for review from oneflow-ci-bot January 31, 2023 00:47
@github-actions
Copy link
Contributor

Static analysis with clang failed. PR label automerge has been removed

@clackhan clackhan requested review from oneflow-ci-bot and removed request for oneflow-ci-bot January 31, 2023 00:51
@github-actions
Copy link
Contributor

Static analysis with clang failed. PR label automerge has been removed

@github-actions
Copy link
Contributor

CI failed when running job: cuda-module. PR label automerge has been removed

@github-actions
Copy link
Contributor

Speed stats:

@github-actions
Copy link
Contributor

Speed stats:

@github-actions
Copy link
Contributor

Speed stats:
GPU Name: GeForce GTX 1080 









❌ OneFlow resnet50 time: 142.3ms (= 14226.3ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 164.1ms (= 16414.6ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.15 (= 164.1ms / 142.3ms)

OneFlow resnet50 time: 87.7ms (= 8769.0ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 108.9ms (= 10888.6ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.24 (= 108.9ms / 87.7ms)

OneFlow resnet50 time: 59.6ms (= 11911.3ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 79.7ms (= 15934.0ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.34 (= 79.7ms / 59.6ms)

OneFlow resnet50 time: 46.2ms (= 9241.1ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 70.8ms (= 14170.0ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.53 (= 70.8ms / 46.2ms)

OneFlow resnet50 time: 41.3ms (= 8257.8ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 75.5ms (= 15100.0ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.83 (= 75.5ms / 41.3ms)

@github-actions
Copy link
Contributor

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/9808/

@mergify mergify bot merged commit 795d19b into master Jan 31, 2023
@mergify mergify bot deleted the fix_dropout_functor_error branch January 31, 2023 15:38
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.

4 participants