Skip to content

Commit

Permalink
Revert "[JIT] add id function (#34975)" (#35209)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #35209

This reverts commit 62f11f0.

Test Plan: Imported from OSS

Differential Revision: D20596847

Pulled By: albanD

fbshipit-source-id: e6777e42356aac772e59f0466a92cc13258218c1
  • Loading branch information
albanD authored and facebook-github-bot committed Mar 23, 2020
1 parent 2c69fa9 commit 0e0386b
Show file tree
Hide file tree
Showing 10 changed files with 2 additions and 100 deletions.
1 change: 0 additions & 1 deletion aten/src/ATen/core/interned_strings.h
Expand Up @@ -78,7 +78,6 @@ namespace c10 {
_(prim, device) \
_(prim, dtype) \
_(prim, shape) \
_(prim, id) \
_(prim, requires_grad) \
_(prim, MakeTestTensor) /* test */ \
_(prim, AutogradAdd) \
Expand Down
28 changes: 1 addition & 27 deletions aten/src/ATen/core/jit_type.h
Expand Up @@ -53,8 +53,7 @@ using OptNameList = c10::optional<std::vector<std::string>>;
_(LayoutType) \
_(ScalarTypeType) \
_(AnyListType) \
_(AnyTupleType) \
_(AnyClassType)
_(AnyTupleType)

enum class TypeKind {
#define DEFINE_TYPE(T) T,
Expand Down Expand Up @@ -1951,31 +1950,6 @@ struct CAFFE2_API AnyTupleType : public Type {
: Type(TypeKind::AnyTupleType) {}
};

// the common supertype of all classes,
// ClassType <: AnyClassType for all classes
struct AnyClassType;
using AnyClassTypePtr = std::shared_ptr<AnyClassType>;
struct CAFFE2_API AnyClassType : public Type {
static AnyClassTypePtr create() {
return AnyClassTypePtr(
new AnyClassType()); // NOLINT(modernize-make-shared)
}
bool operator==(const Type& rhs) const override {
return rhs.kind() == kind();
}
std::string python_str() const override {
return "Class Type";
}
std::string str() const override {
return "AnyClassType";
}
static const TypeKind Kind = TypeKind::AnyClassType;
// global singleton
static AnyClassTypePtr get();
private:
AnyClassType()
: Type(TypeKind::AnyClassType) {}
};

inline bool IValue::isDoubleList() const {
// note: avoids calling type() to avoid extra referencing counting for the returned type.
Expand Down
7 changes: 0 additions & 7 deletions aten/src/ATen/core/type.cpp
Expand Up @@ -214,10 +214,6 @@ AnyTupleTypePtr AnyTupleType::get() {
return value;
}

AnyClassTypePtr AnyClassType::get() {
static auto value = AnyClassType::create();
return value;
}

c10::optional<TypePtr> unifyTypes(const TypePtr& t1, const TypePtr& t2) {
// check direct subtyping relation
Expand Down Expand Up @@ -755,9 +751,6 @@ ClassTypePtr ClassType::refine(at::ArrayRef<TypePtr> refined_slots) const {
}

bool ClassType::isSubtypeOfExt(const TypePtr rhs, std::ostream* why_not) const {
if (rhs->cast<AnyClassType>()) {
return true;
}
// to improve performance, this check can be cached
if (auto iface = rhs->cast<InterfaceType>()) {
// ClassType is not a subtype of InterfaceType if the InterfaceType is a
Expand Down
21 changes: 0 additions & 21 deletions test/backward_compatibility/check_backward_compatibility.py
Expand Up @@ -21,7 +21,6 @@
# We export some functions and classes for test_jit.py directly from libtorch.so,
# it's not important to have BC for them
('_TorchScriptTesting.*', datetime.date(9999, 1, 1)),
('prim::id*', datetime.date(2020, 4, 1)),
('aten::pop*', datetime.date(2020, 4, 1)),
('aten::insert*', datetime.date(2020, 4, 1)),
('aten::Delete*', datetime.date(2020, 4, 1)),
Expand Down Expand Up @@ -124,13 +123,6 @@
]


# The nightly will fail to parse newly added syntax to schema declarations
# Add new schemas that will fail the nightly here
dont_parse_list = [
("prim::id", datetime.date(2020, 4, 1)),
]


def white_listed(schema, white_list):
for item in white_list:
if item[1] < datetime.date.today():
Expand All @@ -141,16 +133,6 @@ def white_listed(schema, white_list):
return False


def dont_parse(schema_line):
for item in dont_parse_list:
if item[1] < datetime.date.today():
continue
regexp = re.compile(item[0])
if regexp.search(schema_line):
return True
return False


def check_bc(new_schema_dict):
existing_schemas = torch._C._jit_get_all_schemas()
is_bc = True
Expand Down Expand Up @@ -203,9 +185,6 @@ def check_bc(new_schema_dict):
# TODO Fix type __torch__.torch.classes.xxx
continue

if dont_parse(line.strip()):
print("Not parsing schema line: ", line.strip())
continue
s = parse_schema(line.strip())
slist = new_schema_dict.get(s.name, [])
slist.append(s)
Expand Down
23 changes: 0 additions & 23 deletions test/test_jit.py
Expand Up @@ -15919,29 +15919,6 @@ def str_hash(x):
tester(float_hash, (20.0, 21.00001, 22.443))
tester(str_hash, ("", "hello", "a"))

def test_id(self):
with self.assertRaisesRegex(RuntimeError, "Expected a value"):
@torch.jit.script
def test_id_scalars():
return id(2) == id(None)

@torch.jit.script
class FooTest(object):
def __init__(self, x):
self.foo = x

def getFooTest(self):
return self.foo

def test_id_class_types():
a = id(FooTest(torch.tensor(3)))
b = id(FooTest(torch.tensor(2)))
c = id(None)
return a != b and b != c

script = torch.jit.script(test_id_class_types)
self.assertEqual(script(), test_id_class_types())

def test_mutable_dce(self):
@torch.jit.script
def foo():
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/frontend/ir_emitter.cpp
Expand Up @@ -463,7 +463,6 @@ struct Environment {
"__round__",
std::make_shared<BuiltinFunction>(aten::round, at::nullopt))},
{"hash", std::make_shared<BuiltinFunction>(aten::hash, at::nullopt)},
{"id", std::make_shared<BuiltinFunction>(prim::id, at::nullopt)},
{"min", std::make_shared<BuiltinFunction>(prim::min, at::nullopt)},
{"max", std::make_shared<BuiltinFunction>(prim::max, at::nullopt)},
{"abs", std::make_shared<BuiltinFunction>(prim::abs, at::nullopt)},
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/frontend/schema_type_parser.cpp
Expand Up @@ -54,7 +54,6 @@ TypePtr SchemaTypeParser::parseBaseType() {
{"None", NoneType::get()},
{"Capsule", CapsuleType::get()},
{"Any", at::AnyType::get()},
{"AnyClassType", at::AnyClassType::get()},
};
auto tok = L.cur();
if (!L.nextIf(TK_NONE)) {
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/python/pybind_utils.h
Expand Up @@ -620,7 +620,6 @@ inline IValue toIValue(
case TypeKind::QSchemeType:
case TypeKind::AnyListType:
case TypeKind::AnyTupleType:
case TypeKind::AnyClassType:
break;
}
throw py::cast_error(c10::str("toIValue() cannot handle converting to type: ", type->python_str()));
Expand Down
15 changes: 0 additions & 15 deletions torch/csrc/jit/runtime/register_prim_ops.cpp
@@ -1,5 +1,4 @@
#include <aten/src/ATen/Context.h>
#include <c10/core/DeviceType.h>
#include <torch/csrc/autograd/autograd.h>
#include <torch/csrc/autograd/edge.h>
#include <torch/csrc/autograd/function.h>
Expand Down Expand Up @@ -3048,20 +3047,6 @@ RegisterOperators reg2({
return 0;
},
aliasAnalysisFromSchema()),
Operator(
"prim::id(AnyClassType? x) -> int",
[](Stack& stack) {
IValue a;
pop(stack, a);
if (a.isNone()) {
push(stack, 0);
} else {
push(stack, reinterpret_cast<int64_t>(a.internalToPointer()));
}
return 0;
},
aliasAnalysisFromSchema()),

#define DEFINE_DIVMOD_MIXED_OP(type_a, type_b) \
Operator( \
"aten::divmod(" #type_a " x," #type_b " y) -> (float, float)", \
Expand Down
4 changes: 1 addition & 3 deletions torch/csrc/jit/serialization/unpickler.cpp
Expand Up @@ -75,15 +75,13 @@ void restoreAccurateTypeTags(const IValue& root, const TypePtr& type_tag) {
case AnyType::Kind:
case AnyListType::Kind:
case AnyTupleType::Kind:
case AnyClassType::Kind:
// if Any type does show up, we no longer have a way to precisely
// recover the type information since the w.value may be an untagged
// List/Dict. We should prevent objects being serialized from having the
// Any type and if we do allow it in functions limit it to non-heap
// locations.
TORCH_INTERNAL_ASSERT(
false,
"AnyType, AnyTupleType, AnyListType, and AnyClassType should not show up in the static type of objects");
false, "AnyType, AnyTupleType, and AnyListType should not show up in the static type of objects");
case TupleType::Kind: {
auto t = w.value.toTuple();
auto ttype = w.static_type->expect<TupleType>();
Expand Down

0 comments on commit 0e0386b

Please sign in to comment.