Developer Tools

trunk/9c9debb684b50213e24f910695124a5f25ea9314: Fix avg_pool3d meta divisor_override=0 check (#179362)

A Python bug bypassed zero-divisor check, risking silent errors in 3D pooling.

Deep Dive

PyTorch, the popular deep learning framework with 99.5k GitHub stars, has merged a critical fix for a bug in the `avg_pool3d` operation's meta kernel. The issue, identified in pull request #179362, stemmed from a Python-specific logic error in the `divisor_override` parameter validation. The C++ implementations in `aten/src/ATen/native/AveragePool3d.cpp` correctly check that `divisor_override` is not zero using `has_value()` semantics, but the Python meta kernel used `not divisor_override` which evaluates to `True` for both `None` and `0`, incorrectly rejecting valid zero values and bypassing the `!= 0` check.

The fix replaces `not divisor_override` with `divisor_override is None`, matching the C++ behavior and ensuring consistent error handling across both implementations. The `avg_pool3d` function is used in 3D convolutional neural networks for tasks like video analysis and medical imaging. Without this fix, setting `divisor_override=0` would raise a confusing error or potentially allow division by zero, leading to silent numerical errors.

Key Points
  • Fixed Python meta kernel using `not divisor_override` instead of `divisor_override is None`
  • C++ implementations in `AveragePool3d.cpp` already had proper validation with `has_value()`
  • Bug could cause silent errors or confusing error messages for `divisor_override=0`

Why It Matters

Ensures consistent error handling in PyTorch's 3D pooling, preventing silent bugs in production models.