Skip to content

Instantly share code, notes, and snippets.

@NegatioN
Last active December 1, 2020 16:30
Show Gist options
  • Save NegatioN/cc8143d351ba8776d26b40e159780cf7 to your computer and use it in GitHub Desktop.
Save NegatioN/cc8143d351ba8776d26b40e159780cf7 to your computer and use it in GitHub Desktop.
How to input python-esque kwargs to a pytorch scripted c++ model
torch::jit::IValue myIvalue;
torch::jit::IValue myIvalue2;
torch::jit::script::Module module;
std::unordered_map<std::string, torch::jit::IValue> umap = {{"x", myIvalue}, {"opt", myIvalue2}};
auto result = module.get_method("forward")({}, umap);
// shows all potential arguments to model forward
std::cout << module.get_method("forward").function().getSchema().arguments() << std::endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment