[inductor] Refactor wrapper.py (#108653)
Summary: Cherry-pick refactoring from https://github.com/pytorch/pytorch/pull/105331 to make the code review easier.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/108653
Approved by: https://github.com/ezyang, https://github.com/khabinov