[JIT] Fix stateful lambda stuff and simplify code in custom C++ binding API
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/32658
Test Plan: Imported from OSS
Differential Revision: D19584701
Pulled By: jamesr66a
fbshipit-source-id: d556c7db2f32900eb1122348402789b59516a7d7