8000 Add assertion to align with cuda by shiyang-weng · Pull Request #153233 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Add assertion to align with cuda #153233

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations 8000
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions aten/src/ATen/native/Normalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,11 @@ std::tuple<Tensor, Tensor> batch_norm_update_stats_cpu(

std::tuple<Tensor&, Tensor&, Tensor&> batch_norm_cpu_out(const Tensor& self, const std::optional<Tensor>& weight_opt, const std::optional<Tensor>& bias_opt, const std::optional<Tensor>& running_mean_opt, const std::optional<Tensor>& running_var_opt,
bool train, double momentum, double eps, Tensor& out, Tensor& save_mean, Tensor& save_var) {
const bool has_running_mean = (running_mean_opt.has_value() && running_mean_opt->defined());
const bool has_running_var = (running_var_opt.has_value() && running_var_opt->defined());
TORCH_CHECK_VALUE(has_running_mean == has_running_var,
"running_mean and running_var must either both be None or neither be None");

// See [Note: hacky wrapper removal for optional tensor]
c10::MaybeOwned<Tensor> weight_maybe_owned = at::borrow_from_optional_tensor(weight_opt);
const Tensor& weight = *weight_maybe_owned;
Expand Down
3 changes: 2 additions & 1 deletion aten/src/ATen/native/cuda/Normalization.cu
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ void batch_norm_calc_invstd(const Tensor& out_invstd, const Tensor& running_var,
std::tuple<Tensor&, Tensor&, Tensor&> batch_norm_cuda_out(const Tensor& self, const std::optional<Tensor>& weight_opt, const std::optional<Tensor>& bias_opt, const std::optional<Tensor>& running_mean_opt, const std::optional<Tensor>& running_var_opt, bool train, double momentum, double epsilon, Tensor& output, Tensor& save_mean, Tensor& save_invstd) {
const bool has_running_mean = (running_mean_opt.has_value() && running_mean_opt->defined());
const bool has_running_var = (running_var_opt.has_value() && running_var_opt->defined());
TORCH_CHECK(has_running_mean == has_running_var);
TORCH_CHECK_VALUE(has_running_mean == has_running_var,
"running_mean and running_var must either both be None or neither be None");

if (train) {
batch_norm_mean_var(self, save_mean, save_invstd);
Expand Down
9 changes: 6 additions & 3 deletions aten/src/ATen/native/mps/operations/Normalization.mm
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ static void get_shapes(MPSShape* input_shape_readonly,

const bool has_running_mean = (running_mean_opt.has_value() && running_mean_opt->defined());
const bool has_running_var = (running_var_opt.has_value() && running_var_opt->defined());
TORCH_CHECK(has_running_mean == has_running_var);
TORCH_CHECK_VALUE(has_running_mean == has_running_var,
"running_mean and running_var must either both be None or neither be None");

const bool has_weight = (weight_opt.has_value() && weight_opt->defined());
const bool has_bias = (bias_opt.has_value() && bias_opt->defined());
Expand Down Expand Up @@ -587,10 +588,12 @@ Check if running mean exists (maybe do this check before making graph)

const bool has_running_mean = (running_mean_opt.has_value() && running_mean_opt->defined());
const bool has_running_var = (running_var_opt.has_value() && running_var_opt->defined());
TORCH_CHECK(has_running_mean == has_running_var);
TORCH_CHECK_VALUE(has_running_mean == has_running_var,
"running_mean and running_var must either both be None or neither be None");
const bool has_save_mean = (save_mean_opt.has_value() && save_mean_opt->defined());
const bool has_save_var = (save_var_opt.has_value() && save_var_opt->defined());
TORCH_CHECK(has_save_mean == has_save_var);
TORCH_CHECK_VALUE(has_save_mean == has_save_var,
"save_mean and save_var must either both be None or neither be None");

const bool has_weight = (weight_opt.has_value() && weight_opt->defined());

Expand Down
Loading
0