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

Abierto Apto para principiantes
#27 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
74/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, pytorch

Línea de trabajo

Lee L2/036_convnextv2_layer_with_nhwc_persistence_backward/reference.py, especialmente el cálculo hacia atrás en las líneas 155–161 y la reducción hacia delante en la línea 47. Comprueba cómo el gradiente a través de gf_mean gestiona la dimensión de canales y, después, compara la referencia con autograd en float64 para los casos descritos en el issue. La tarea estará terminada cuando la referencia coincida con la verdad de referencia en todas las cargas de trabajo reportadas.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
340
Forks
37
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de NVIDIA/SOL-ExecBench

Todos los issues de NVIDIA/SOL-ExecBench

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.