Add option to load historic operators in IR when the operator is deprecated (#71148)

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

Test Plan: Imported from OSS

Reviewed By: gmagogsfm

Differential Revision: D33521300

Pulled By: tugsbayasgalan

fbshipit-source-id: a0607dba5e7233590384326537017eb0b18da419
This commit is contained in:
Tugsbayasgalan (Tugsuu) Manlaibaatar
2022-01-12 11:05:35 -08:00
committed by Facebook GitHub Bot
parent 8f4cec2231
commit 70951884d4
6 changed files with 111 additions and 6 deletions

View File

@ -4,6 +4,8 @@
#include <test/cpp/jit/test_utils.h>
#include <vector>
namespace torch {
namespace jit {
@ -58,5 +60,40 @@ TEST(UpgraderUtils, FindIfOpIsCurrent) {
test_only_remove_entry("foo");
}
TEST(UpgraderUtils, CanLoadHistoricOp) {
std::vector<UpgraderEntry> dummy_entry = {
{4, "foo__0_3", "foo.bar()"},
{8, "foo__4_7", "foo.foo()"},
};
std::vector<std::string> schemas = {"foo.bar()", "foo.foo()"};
// symbol based look up
test_only_add_entry("old_op_not_exist.first", dummy_entry[0]);
test_only_add_entry("old_op_not_exist.second", dummy_entry[1]);
auto oldSchemas = loadPossibleHistoricOps("old_op_not_exist", 2);
EXPECT_EQ(oldSchemas.size(), 2);
for (const auto& entry : oldSchemas) {
EXPECT_TRUE(
std::find(schemas.begin(), schemas.end(), entry) != schemas.end());
}
auto oldSchemasWithCurrentVersion =
loadPossibleHistoricOps("old_op_not_exist", 9);
EXPECT_EQ(oldSchemasWithCurrentVersion.size(), 0);
test_only_remove_entry("old_op_not_exist.first");
test_only_remove_entry("old_op_not_exist.first");
// it is ok to have old schemas without overload
test_only_add_entry("old_op_not_exist_no_overload", dummy_entry[0]);
auto oldSchemasNoOverload =
loadPossibleHistoricOps("old_op_not_exist_no_overload", 2);
EXPECT_EQ(oldSchemasNoOverload.size(), 1);
EXPECT_EQ(oldSchemasNoOverload[0], "foo.bar()");
test_only_remove_entry("old_op_not_exist_no_overload");
}
} // namespace jit
} // namespace torch