Revert D30038175: Improve IMethod::getArgumentNames to deal with empty argument names list
Test Plan: revert-hammer
Differential Revision:
D30038175 (https://github.com/pytorch/pytorch/commit/64b3ab64078c2400656544a8f4e6ccfc56009a89)
Original commit changeset: 46f08dda9418
fbshipit-source-id: 604735d2300487a0b75890b330d7ba5b3e7145b2
diff --git a/torch/csrc/api/include/torch/imethod.h b/torch/csrc/api/include/torch/imethod.h
index 019fdb3..78d7a9e 100644
--- a/torch/csrc/api/include/torch/imethod.h
+++ b/torch/csrc/api/include/torch/imethod.h
@@ -38,7 +38,6 @@
virtual void setArgumentNames(std::vector<std::string>& argumentNames) const = 0;
private:
- bool isArgumentNamesInitialized_ { false };
std::vector<std::string> argumentNames_;
};
diff --git a/torch/csrc/api/src/imethod.cpp b/torch/csrc/api/src/imethod.cpp
index 8d27208..20cdb35 100644
--- a/torch/csrc/api/src/imethod.cpp
+++ b/torch/csrc/api/src/imethod.cpp
@@ -4,11 +4,11 @@
const std::vector<std::string>& IMethod::getArgumentNames()
{
- if (isArgumentNamesInitialized_) {
+ // TODO(jwtan): Deal with empty parameter list.
+ if (!argumentNames_.empty()) {
return argumentNames_;
}
- isArgumentNamesInitialized_ = true;
setArgumentNames(argumentNames_);
return argumentNames_;
}
diff --git a/torch/csrc/deploy/deploy.cpp b/torch/csrc/deploy/deploy.cpp
index b90b95d..115af19 100644
--- a/torch/csrc/deploy/deploy.cpp
+++ b/torch/csrc/deploy/deploy.cpp
@@ -78,18 +78,11 @@
}
// Pre-registered modules.
- // Since torch::deploy::Obj.toIValue cannot infer empty list, we hack it to
- // return None for empty list.
// TODO(jwtan): Make the discovery of these modules easier.
register_module_source(
"GetArgumentNamesModule",
"from inspect import signature\n"
- "from typing import Callable, Optional\n"
- "def getArgumentNames(function: Callable) -> Optional[list]:\n"
- " names = list(signature(function).parameters.keys())\n"
- " if len(names) == 0:\n"
- " return None\n"
- " return names\n");
+ "def getArgumentNames(function): return list(signature(function).parameters.keys())\n");
TORCH_DEPLOY_SAFE_CATCH_RETHROW
}
@@ -298,10 +291,6 @@
auto iArgumentNames =
session.global("GetArgumentNamesModule", "getArgumentNames")({method})
.toIValue();
- if (iArgumentNames.isNone()) {
- return;
- }
-
TORCH_INTERNAL_ASSERT(iArgumentNames.isList());
auto argumentNames = iArgumentNames.toListRef();
diff --git a/torch/csrc/jit/python/pybind_utils.h b/torch/csrc/jit/python/pybind_utils.h
index d76c8c2..dd2f785 100644
--- a/torch/csrc/jit/python/pybind_utils.h
+++ b/torch/csrc/jit/python/pybind_utils.h
@@ -279,6 +279,7 @@
// Try to infer the type of a Python object
// The type cannot be inferred if:
+// input is a None
// input is an empty container (list, dict)
// input is an list with element types that cannot be unified
// input is an dict with key or value types that cannot be unified