Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/63995
JIT methods already have name() in their interface, and Py methods have names in their implementation. I'm adding this for a particular case where someone tried to use name() on a JIT method that we're replacing with an IMethod.
Test Plan: add case to imethod API test
Reviewed By: suo
Differential Revision:
D30559401
fbshipit-source-id:
76236721f5cd9a9d9d488ddba12bfdd01d679a2c
auto pyModel = package.load_pickle("model", "model.pkl");
torch::deploy::PythonMethodWrapper pyMethod(pyModel, "forward");
+ EXPECT_EQ(scriptMethod.name(), "forward");
+ EXPECT_EQ(pyMethod.name(), "forward");
+
auto input = torch::ones({10, 20});
auto outputPy = pyMethod({input});
auto outputScript = scriptMethod({input});
std::vector<c10::IValue> args,
const IValueMap& kwargs = IValueMap()) const = 0;
+ virtual const std::string& name() const = 0;
+
// Returns an ordered list of argument names, possible in both
// script and python methods. This is a more portable dependency
// than a ScriptMethod FunctionSchema, which has more information
std::string method_name)
: model_(std::move(model)), method_name_(std::move(method_name)) {}
+ const std::string& name() const override {
+ return method_name_;
+ }
+
c10::IValue operator()(
std::vector<c10::IValue> args,
const IValueMap& kwargs = IValueMap()) const override {
return function_->graph();
}
- const std::string& name() const {
+ const std::string& name() const override {
return function_->name();
}