Developer Tools

PyTorch's new PR adds premul_sum and min/max gradients to all_reduce

Claude Opus 4.6 co-authored this PyTorch PR adding premul_sum to all_reduce—check the details.

Deep Dive

PyTorch has merged PR #190942, 'Add more ops support for functional all_reduce,' which significantly expands the capabilities of its collective communication API. The change, co-authored with Claude Opus 4.6, addresses longstanding gaps in the functional all_reduce implementation. The first major enhancement is premul_sum support, allowing a multiplication factor to be applied to tensors before the reduction operation completes. This makes the schema's reduce_op argument more flexible—now typed as Any—so callers can pass a ReduceOp object directly with a supplementary scalar factor, enabling operations like scaled summation in a single collective step.

The second improvement adds backward support for min and max operations. Previously, gradients for these reduce ops were not implemented, forcing users to work around the limitation. The new approach compares the output value with each input locally to route gradients accurately, completing gradient propagation for the full set of reduction operations. The PR also parameterizes all existing all_reduce tests to cover these changes, ensuring the new functionality is robust across different configurations. For distributed training, this means more efficient stateful optimizations (like gradient clipping or scaling) and smoother auto-differentiation through collective ops—a practical win for high-performance PyTorch workloads.

Key Points
  • Adds premul_sum support to functional all_reduce forward/backward by making reduce_op schema type Any
  • Implements min and max backward via local output-input comparison to route gradients correctly
  • Co-authored with Claude Opus 4.6; part of PyTorch PR #190942, approved by d4l3k

Why It Matters

Expanding PyTorch's all_reduce ops simplifies distributed training and unlocks optimized gradient flows in production AI.

📬 Get the top 10 AI stories daily