-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
Add assertion to align with cuda #153233
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/153233
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 5fd22bf with merge base c1055f4 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This comment was marked as outdated.
This comment was marked as outdated.
@pytorchbot label "module: error checking" |
@pytorchbot label "module: norms and normalization" |
e402021
to
136ab31
Compare
import torch
print(f"PyTorch Version: {torch.__version__}")
# Common parameters for torch.batch_norm
weight_param = None
bias_param = None
is_training_param = True # Error occurs with True or False
momentum_param = 0.1
eps_param = 1e-5
cudnn_enabled_param = True # Also occurs with False on GPU
# --- Scenario 1: running_mean is Tensor, running_var is None ---
print("\n--- Scenario 1: running_mean is Tensor, running_var is None ---")
# Input tensor
input_tensor_shape = (3, 4, 5) # N, C, D*
num_features = input_tensor_shape[1]
# CPU
print(" CPU (Scenario 1):")
try:
input_tensor_cpu = torch.randn(input_tensor_shape)
running_mean_param_cpu = torch.randn(num_features)
running_var_param_cpu = None
torch.batch_norm(
input_tensor_cpu,
weight_param,
bias_param,
running_mean_param_cpu,
running_var_param_cpu,
is_training_param,
momentum_param,
eps_param,
cudnn_enabled_param
)
print(" CPU: Error not triggered.")
except ValueError as e:
print(f" CPU Error: {e}")
if "Expected has_running_mean == has_running_var to be true, but got false" in str(e):
print(" CPU: Successfully triggered the target error (unexpected based on current behavior).")
# GPU
if torch.cuda.is_available():
print(" GPU (Scenario 1):")
try:
input_tensor_gpu = torch.randn(input_tensor_shape).cuda()
running_mean_param_gpu = torch.randn(num_features).cuda()
running_var_param_gpu = None
torch.batch_norm(
input_tensor_gpu,
weight_param,
bias_param,
running_mean_param_gpu,
running_var_param_gpu,
is_training_param,
momentum_param,
eps_param,
cudnn_enabled_param
)
print(" GPU: Error not triggered (unexpected for this specific error message).")
except ValueError as e:
print(f" GPU Error: {e}")
if "Expected has_running_mean == has_running_var to be true, but got false" in str(e):
print(" GPU: Successfully triggered the target error.")
else:
print(" GPU (Scenario 1): CUDA not available, skipping GPU test.")
# --- Scenario 2: running_mean is None, running_var is Tensor ---
print("\n--- Scenario 2: running_mean is None, running_var is Tensor ---")
# CPU
print(" CPU (Scenario 2):")
try:
input_tensor_cpu = torch.randn(input_tensor_shape)
running_mean_param_cpu = None
running_var_param_cpu = torch.randn(num_features)
torch.batch_norm(
input_tensor_cpu,
weight_param,
bias_param,
running_mean_param_cpu,
running_var_param_cpu,
is_training_param,
momentum_param,
eps_param,
cudnn_enabled_param
)
print(" CPU: Error not triggered.")
except ValueError as e:
print(f" CPU Error: {e}")
if "Expected has_running_mean == has_running_var to be true, but got false" in str(e):
print(" CPU: Successfully triggered the target error (unexpected based on current behavior).")
# GPU
if torch.cuda.is_available():
print(" GPU (Scenario 2):")
try:
input_tensor_gpu = torch.randn(input_tensor_shape).cuda()
running_mean_param_gpu = None
running_var_param_gpu = torch.randn(num_features).cuda()
torch.batch_norm(
input_tensor_gpu,
weight_param,
bias_param,
running_mean_param_gpu,
running_var_param_gpu,
is_training_param,
momentum_param,
eps_param,
cudnn_enabled_param
)
print(" GPU: Error not triggered (unexpected for this specific error message).")
except ValueError as e:
print(f" GPU Error: {e}")
if "Expected has_running_mean == has_running_var to be true, but got false" in str(e):
print(" GPU: Successfully triggered the target error.")
else:
print(" GPU (Scenario 2): CUDA not available, skipping GPU test.") Change to use ValueError. --- Scenario 2: running_mean is None, running_var is Tensor --- |
Could you help review this pr? @Skylion007 |
Could someone help review this pr? |
@shiyang-weng do you mind adding the test? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it'll pass the tests, sure
This is error checking issue. Not related to functionality and performance |
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Fixes #153137
Aligned batch_norm_cpu_out assertion to batch_norm_cuda_out.
cc @malfet