Skip to content

Patching bn inference #2016

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

Merged
merged 2 commits into from
Sep 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions torch/csrc/jit/codegen/cuda/ops/normalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,10 @@ ForwardNormResult batch_norm(
auto invstd_bcast = broadcast(unbiased_invstd, broadcast_mask);

// During inference, mean/invstd output are empty tensors
mean = TensorViewBuilder().shape(std::vector<int64_t>{0}).build();
invstd = TensorViewBuilder().shape(std::vector<int64_t>{0}).build();
// on CPU, but not on CUDA. We need to make sure we have the same
// behavior as with eager mode on CUDA.
mean = set(running_mean);
invstd = unbiased_invstd;
y = mul(x_sub_mean, invstd_bcast);
}

Expand Down Expand Up @@ -840,8 +842,10 @@ ForwardNormResult instance_norm(
broadcast(unbiased_invstd, channels_only_broadcast_mask);

// During inference, mean/invstd output are empty tensors
mean = TensorViewBuilder().shape(std::vector<int64_t>{0}).build();
invstd = TensorViewBuilder().shape(std::vector<int64_t>{0}).build();
// on CPU, but not on CUDA. We need to make sure we have the same
// behavior as with eager mode on CUDA.
mean = set(running_mean);
invstd = unbiased_invstd;
y = mul(x_sub_mean, invstd_bcast);
}

Expand Down