[Profiler] set_class util (part 1 of Record Optimizer) (#84779)
Summary:
Part 1 of Record Optimizer param_groups and states (https://github.com/pytorch/pytorch/pull/84063)
- nnModule and Optimizer have duplicated parts
- create a util function to avoid duplication
Test Plan: buck run mode/opt //caffe2/test:profiler
Differential Revision: D39397210
Pull Request resolved: https://github.com/pytorch/pytorch/pull/84779
Approved by: https://github.com/robieta