[TorchScript] Support user defined classes as constants (#5062)

Summary:
Pull Request resolved: https://github.com/pytorch/glow/pull/5062

Pull Request resolved: https://github.com/pytorch/pytorch/pull/45556

User defined classes can be used as constants.  This is useful when freezing and removing the module from the graph.

Test Plan: waitforsadcastle

Reviewed By: eellison

Differential Revision: D23994974

fbshipit-source-id: 5b4a5c91158aa7f22df39d71f2658afce1d29317
This commit is contained in:
Bram Wasti
2020-11-16 19:16:55 -08:00
committed by Facebook GitHub Bot
parent 3611d26a25
commit 43a9d6fb6e
17 changed files with 144 additions and 26 deletions

View File

@ -873,7 +873,8 @@ struct PythonPrintImpl {
void printConstant(TaggedStringStream& stmt, const IValue& v) {
const auto customFormatter = [&](std::ostream& ss, const IValue& v) {
if (v.isTensor() || containsNonASCIIString(v)) {
if (v.isTensor() || containsNonASCIIString(v) || v.isObject()) {
TORCH_INTERNAL_ASSERT(!v.type()->is_module());
ss << "CONSTANTS.c" << getOrAddConstant(v);
return true;
}