[PyTorch] Migrate hacky wrapper removal to borrow_from_optional_tensor (#56648)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/56648
Generated with
```
fastmod -m "^((?P<indent>\s*)// See \[Note: hacky wrapper removal for optional tensor\])
\s*const Tensor& (?P<varname>[A-Za-z_]+) = c10::value_or_else\((?P<optionalname>[A-Za-z_]+), \[\] \{return Tensor\(\);\}\);" \
'${1}
${indent}c10::MaybeOwned<Tensor> ${varname}_maybe_owned = c10::borrow_from_optional_tensor(${optionalname});
${indent}const Tensor& ${varname} = *${varname}_maybe_owned;'
```
ghstack-source-id: 127112928
Test Plan: CI
Reviewed By: wenleix
Differential Revision: D27925837
fbshipit-source-id: 720a4f2e3b96e14c93466698c9c4a3b9c8446a69