[BE]: Apply FURB118 (prev): replaces unnecessary lambdas with operator. (#116027)

This replaces a bunch of unnecessary lambdas with the operator package. This is semantically equivalent, but the operator package is faster, and arguably more readable. When the FURB rules are taken out of preview, I will enable it as a ruff check.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/116027
Approved by: https://github.com/malfet
This commit is contained in:
Aaron Gokaslan
2023-12-20 19:35:04 +00:00
committed by PyTorch MergeBot
parent 2d2016fdf8
commit 6de28e92d2
29 changed files with 115 additions and 107 deletions

View File

@ -1,3 +1,4 @@
import operator
import threading
import time
from functools import reduce
@ -75,9 +76,7 @@ class AgentBase:
batch (bool): Whether to process and respond to observer requests as a batch or 1 at a time
"""
self.batch = batch
self.policy = Policy(
reduce((lambda x, y: x * y), state_size), nlayers, out_features
)
self.policy = Policy(reduce(operator.mul, state_size), nlayers, out_features)
self.optimizer = optim.Adam(self.policy.parameters(), lr=1e-2)
self.batch_size = batch_size