L2/036: GRN backward in `reference.py` is missing a channel-dim sum, so mathematically correct implementations fail grading

Đang mở Phù hợp với người mới
#27 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, pytorch

Hướng nghiên cứu

Đọc L2/036_convnextv2_layer_with_nhwc_persistence_backward/reference.py, đặc biệt là phép tính backward ở các dòng 155–161 và phép reduction forward ở dòng 47. Kiểm tra cách gradient đi qua gf_mean xử lý chiều kênh, sau đó so sánh phần tham chiếu với autograd float64 trên các trường hợp được mô tả trong issue. Công việc được xem là hoàn tất khi phần tham chiếu khớp với ground truth trên tất cả workload được báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

In L2/036_convnextv2_layer_with_nhwc_persistence_backward, the reference backward pass computes the gradient w.r.t. gf_mean without summing over the channel dimension. Because the reference is the ground truth for grading, a submission that implements the backward pass correctly is scored as wrong, while a submission that reproduces this error scores full marks.

Dataset revision: nvidia/SOL-ExecBench @ 63699402f003496acc3af4eb534a5304a8ac1ea9
Evaluator: NVIDIA/SOL-ExecBench @ a9fa080

The bug

L2/036_convnextv2_layer_with_nhwc_persistence_backward/reference.py, lines 155–161:

grad_global_features = grad_norm_features / (gf_mean + eps)
grad_gf_mean = -grad_norm_features * global_features / ((gf_mean + eps) ** 2)   # line 157

# Gradient through gf_mean = global_features.mean(dim=-1, keepdim=True)
C_expanded = global_features.shape[-1]
grad_global_features = grad_global_features + grad_gf_mean / C_expanded          # line 161

In the forward pass (line 47), gf_mean = global_features.mean(dim=-1, keepdim=True), so gf_mean has shape (B, 1, 1, 1) while global_features has shape (B, 1, 1, C).

The chain rule therefore requires the gradient w.r.t. gf_mean to be the sum over the channel dimension, i.e. shape (B, 1, 1, 1), which is then divided by C and broadcast back to every channel. Line 157 instead keeps the per-channel terms at shape (B, 1, 1, C), so line 161 gives each channel its own term / C rather than the sum of all channel terms / C.

This is a shape/chain-rule argument that can be checked by inspection: the gradient of a reduction over dim=-1 cannot itself retain that dimension.

Suggested fix
grad_gf_mean = (-grad_norm_features * global_features / ((gf_mean + eps) ** 2)).sum(dim=-1, keepdim=True)

Evidence

Measured on CPU with torch 2.11.0+cu130, using float64 autograd on the reference forward as ground truth and applying the evaluator's own comparison rule (compute_error_stats at a9fa080, required matched ratio 0.99):

  • All 14 workloads from workload.jsonl × 2 seeds = 28 cases.

  • The float64-autograd ground truth fails against the current reference in 4 of 28 cases, every failure in the grad_dwconv_bias output (the GRN error propagates into grad_x and from there into the depthwise-conv bias gradient). Worst matched ratio 0.9297 against the 0.99 threshold:

    B H W seed failing output matched ratio
    1 14 14 0 grad_dwconv_bias 0.9297
    2 28 28 1 grad_dwconv_bias 0.9375
    32 28 28 0 grad_dwconv_bias 0.9609
    1 56 56 0 grad_dwconv_bias 0.9844
  • With the one-line fix applied, the reference agrees with the float64 ground truth across all 28 cases, maximum absolute deviation 0.00516 (largest at B=32, H=56, W=56).

The two checks are independent — a symbolic chain-rule argument and a numerical float64 comparison — and they agree.

Impact

Grading draws random seeds per evaluation, so a correct implementation is very likely to hit at least one failing case and be scored incorrect, while an implementation that reproduces the missing sum passes. The task itself remains solvable against the current reference (we observe submissions passing all workloads), so this does not make the problem unusable — but it inverts the correctness signal for anyone who derives the backward pass from first principles.

Environment

  • Dataset: nvidia/SOL-ExecBench, revision 63699402f003496acc3af4eb534a5304a8ac1ea9 (also current main at the time of writing)
  • Evaluator: NVIDIA/SOL-ExecBench @ a9fa0804c793 (also current main at the time of writing)
  • PyTorch 2.11.0+cu130, CPU, float64 autograd as ground truth
  • Comparison: evaluator's compute_error_stats, required_matched_ratio = 0.99

Happy to share the audit script if that is useful.

Ngôn ngữ chính
Python
Star
340
Fork
37
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NVIDIA/SOL-ExecBench

Tất cả issue của NVIDIA/SOL-ExecBench

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.