Use torch::variant for enums in C++ API
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26837
Test Plan: Imported from OSS
Differential Revision: D17579438
Pulled By: yf225
fbshipit-source-id: 9ac59df28a317fdb3be2cc02c65962ad99117127