[BE][Ez]: Optimize unnecessary lambda with operator (#154722)

Automated edits performed by FURB118. Operator is implemented in C and way faster when passed to another C method like sorted, max etc as a `key=`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/154722
Approved by: https://github.com/jansel
This commit is contained in:
Aaron Gokaslan
2025-05-30 23:47:06 +00:00
committed by PyTorch MergeBot
parent 0f3db20132
commit bbda22e648
12 changed files with 31 additions and 16 deletions

View File

@ -1,6 +1,7 @@
# mypy: allow-untyped-defs
# Copyright (c) Meta Platforms, Inc. and affiliates
import logging
import operator
from typing import Any, Optional
import torch
@ -46,7 +47,7 @@ class _LossReducer(_CustomReducer):
pass
sum_reducer = _LossReducer(torch.tensor(0.0), lambda a, b: a + b)
sum_reducer = _LossReducer(torch.tensor(0.0), operator.add)
# Default chunking dimension is 0. This is used for the case where the user did
# not specify a chunking dimension.