Skip to content

Commit a8933f8

Browse files
shoumikhinAnthony Shoumikhin
andauthored
fix(runtime): give the TensorRT engine class an __eq__ (#4584)
Co-authored-by: Anthony Shoumikhin <shoumikhin@gmail.com>
1 parent 1df1187 commit a8933f8

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

core/runtime/register_jit_hooks.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ static auto TORCHTRT_UNUSED TRTEngineTSRegistrtion =
7070
.def("__str__", &TRTEngine::to_str)
7171
.def("__repr__", &TRTEngine::to_str)
7272
.def("__obj_flatten__", &TRTEngine::__obj_flatten__)
73+
// Reporting "real" below puts the engine itself into torch's fake tensor
74+
// dispatch cache key, and that cache compares keys with ==. Without this the
75+
// second lookup raises "'__eq__' is not implemented", which breaks any
76+
// re-export of a compiled module. Two handles to one engine are one engine.
77+
.def(
78+
"__eq__",
79+
[](const c10::intrusive_ptr<TRTEngine>& self, const c10::intrusive_ptr<TRTEngine>& other) -> bool {
80+
return self.get() == other.get();
81+
})
7382
// Reporting "real" makes torch's tracing_with_real skip fakification and hand
7483
// the engine itself to the meta kernel, which reads only
7584
// get_serialized_metadata() -- nothing executes or mutates it. Otherwise each

0 commit comments

Comments
 (0)