Simplify by using yield from (#97831)
The issues were found by SIM104 flake8-simplify in a local run.
I'll take a look on adding the check to the CI separately.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/97831
Approved by: https://github.com/Skylion007