forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ivalue.h
698 lines (607 loc) · 19.9 KB
/
ivalue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
#pragma once
#include <ATen/core/TensorBody.h>
#include <ATen/core/blob.h>
#include <c10/util/C++17.h>
#include <c10/util/intrusive_ptr.h>
#include <torch/csrc/WindowsTorchApiMacro.h>
namespace torch {
namespace jit {
class CustomClassHolder : public c10::intrusive_ptr_target {};
struct Function;
namespace script {
struct CompilationUnit;
struct Module;
}
} // namespace jit
} // namespace torch
namespace c10 {
template<class Key, class Value> class Dict;
template<class T> class List;
struct IValue;
struct ClassType;
struct Type;
using TypePtr = std::shared_ptr<Type>;
namespace ivalue {
struct Tuple;
struct Future;
struct ConstantString;
struct GenericDict;
struct Object;
struct PyObjectHolder;
}
// IValue is the generic tagged union used by the interpreter to hold
// all value types.
// It is a 16-byte object with an 8-byte payload and an 8-byte tag.
// The tag is currently 4 bytes to determine the type, and 1 byte
// to mark whether that type is a subtype of c10::intrusive_ptr_target and needs
// retain/release calls.
#define TORCH_FORALL_TAGS(_) \
_(None) \
_(Tensor) \
_(Double) \
_(Int) \
_(Bool) \
_(Tuple) \
_(String) \
_(Blob) \
_(GenericList) \
_(GenericDict) \
_(Future) \
_(Device) \
_(Object) \
_(PyObject) \
_(Uninitialized) \
_(Capsule)
// [doxygen private]
// These methods are not actually private but we don't want to document them, so
// they are marked `@private`, which hides them on the doxygen documentation for
// this page.
/// IValue (Interpreter Value) is a tagged union over the types supported by the
/// TorchScript interpreter. IValues contain their values as an `IValue::Payload`,
/// which holds primitive types (`int64_t`, `bool`, `double`, `Device`), as
/// values and all other types as a `c10::intrusive_ptr`.
///
/// IValues are used as inputs to and outputs from the TorchScript interpreter.
/// To retrieve the value contained within an IValue, use the `.toX()` methods,
/// where `X` is the type you are trying to get. Note that neither the `.toX()`
/// methods nor the templated `.to<T>` functions do any kind of casting, they
/// only unwrap the contained value. For example:
///
/// \rst
/// .. code-block:: cpp
///
/// // Make the IValue
/// torch::IValue my_ivalue(26);
/// std::cout << my_ivalue << "\n";
///
/// // Unwrap the IValue
/// int64_t my_int = my_ivalue.toInt()
/// std::cout << my_int << "\n";
///
/// // This will throw an error!
/// // `my_ivalue` is tagged as an int and cannot be used as another type
/// torch::Tensor my_tensor = my_ivalue.toTensor()
/// \endrst
struct CAFFE2_API IValue final {
IValue(const IValue& rhs)
: IValue(rhs.payload, rhs.tag, rhs.is_intrusive_ptr) {
if (is_intrusive_ptr) {
c10::raw::intrusive_ptr::incref(payload.as_intrusive_ptr);
}
}
IValue(IValue&& rhs) noexcept : IValue() {
swap(rhs);
}
/// @private [doxygen private]
~IValue() {
if (is_intrusive_ptr) {
c10::raw::intrusive_ptr::decref(payload.as_intrusive_ptr);
}
}
IValue& operator=(IValue&& rhs) & noexcept {
IValue(std::move(rhs)).swap(*this); // this also sets rhs to None
return *this;
}
IValue& operator=(IValue const& rhs) & {
IValue(rhs).swap(*this);
return *this;
}
void dump() const;
/// @private [doxygen private]
bool isAliasOf(const IValue& rhs) const {
if (this->tag != rhs.tag) {
// Trivially don't alias if the type is different
return false;
}
if (!this->is_intrusive_ptr) {
// Primitive types don't alias anything
return false;
}
AT_ASSERT(rhs.is_intrusive_ptr);
// Tensors should be compared based on internal storage
if (this->isTensor()) {
const auto thisTensor = this->toTensor();
const auto rhsTensor = rhs.toTensor();
return thisTensor.is_alias_of(rhsTensor);
}
// Other types can be compared by their ptr value
return this->payload.as_intrusive_ptr == rhs.payload.as_intrusive_ptr;
}
/// @private [doxygen private]
size_t use_count() const noexcept {
if (!is_intrusive_ptr) {
return 1;
}
return c10::raw::intrusive_ptr::use_count(payload.as_intrusive_ptr);
}
/// @private [doxygen private]
void swap(IValue & rhs) noexcept {
std::swap(payload, rhs.payload);
std::swap(is_intrusive_ptr, rhs.is_intrusive_ptr);
std::swap(tag, rhs.tag);
}
// Accessors for subtypes are arranged together below
// While some of these accessors could be generated through templates,
// we prefer to write them manually for clarity
IValue(at::Tensor t)
: tag(Tag::Tensor), is_intrusive_ptr(t.defined()) {
// Note: the undefined tensor is not refcounted, so while it
// is tagged as a tensor, is_intrusive_ptr is set to false.
// This is not an optional optimization: our incref call
// *will not* do the right thing when called on an
// undefined tensor.
payload.as_intrusive_ptr = t.unsafeReleaseTensorImpl();
}
bool isTensor() const { return Tag::Tensor == tag; }
at::Tensor toTensor() &&;
at::Tensor toTensor() const &;
at::TensorImpl* unsafeToTensorImpl() const {
return static_cast<at::TensorImpl*>(payload.as_intrusive_ptr);
}
const IValue& toIValue() const {
return *this;
}
IValue& toIValue() {
return *this;
}
/// @private [doxygen private]
IValue(intrusive_ptr<caffe2::Blob> blob)
: tag(Tag::Blob), is_intrusive_ptr(true) {
// TODO (after Tensor merge) If we pass in a Blob holding a Tensor, extract
// and store it as a Tensor instead.
payload.as_intrusive_ptr = blob.release();
}
/// @private [doxygen private]
bool isBlob() const {
return Tag::Blob == tag;
}
/// @private [doxygen private]
c10::intrusive_ptr<caffe2::Blob> toBlob() &&;
/// @private [doxygen private]
c10::intrusive_ptr<caffe2::Blob> toBlob() const &;
// Capsule
IValue(intrusive_ptr<torch::jit::CustomClassHolder> blob);
bool isCapsule() const {
return Tag::Capsule == tag;
}
c10::intrusive_ptr<torch::jit::CustomClassHolder> toCapsule() &&;
c10::intrusive_ptr<torch::jit::CustomClassHolder> toCapsule() const &;
// Tuple
IValue(c10::intrusive_ptr<ivalue::Tuple> v);
template <
typename... Args,
std::enable_if_t<
!guts::disjunction<
std::is_lvalue_reference<Args>...,
guts::negation<std::is_constructible<IValue, Args>>...>::
value,
std::nullptr_t> = nullptr>
IValue(const std::tuple<Args...>& t);
bool isTuple() const { return Tag::Tuple == tag; }
c10::intrusive_ptr<ivalue::Tuple> toTuple() &&;
c10::intrusive_ptr<ivalue::Tuple> toTuple() const &;
// Double
IValue(double d)
: tag(Tag::Double), is_intrusive_ptr(false) {
payload.as_double = d;
}
bool isDouble() const { return Tag::Double == tag; }
double toDouble() const {
AT_ASSERT(isDouble());
return payload.as_double;
}
// Future
IValue(c10::intrusive_ptr<ivalue::Future> v);
bool isFuture() const { return Tag::Future == tag; }
c10::intrusive_ptr<ivalue::Future> toFuture() &&;
c10::intrusive_ptr<ivalue::Future> toFuture() const &;
// Int
IValue(int64_t i)
: tag(Tag::Int), is_intrusive_ptr(false) {
payload.as_int = i;
}
// allow you to pass literals (3, 4) without ambiguity
IValue(int32_t i)
: IValue(static_cast<int64_t>(i)) {}
bool isInt() const { return Tag::Int == tag; }
int64_t toInt() const {
AT_ASSERT(isInt());
return payload.as_int;
}
// Bool
IValue(bool b)
: tag(Tag::Bool), is_intrusive_ptr(false) {
payload.as_bool = b;
}
bool isBool() const { return Tag::Bool == tag; }
bool toBool() const {
AT_ASSERT(isBool());
return payload.as_bool;
}
// IntList
bool isIntList() const;
c10::List<int64_t> toIntList() &&;
c10::List<int64_t> toIntList() const &;
std::vector<int64_t> toIntVector() const;
// ConstantString
IValue(c10::intrusive_ptr<ivalue::ConstantString> v);
IValue(std::string v);
IValue(const char* v): IValue(std::string(v)) {}
bool isString() const { return Tag::String == tag; }
c10::intrusive_ptr<ivalue::ConstantString> toString() &&;
c10::intrusive_ptr<ivalue::ConstantString> toString() const &;
const std::string& toStringRef() const;
// DoubleList
bool isDoubleList() const;
c10::List<double> toDoubleList() &&;
c10::List<double> toDoubleList() const &;
std::vector<double> toDoubleVector() const;
// BoolList
bool isBoolList() const;
c10::List<bool> toBoolList() &&;
c10::List<bool> toBoolList() const &;
//TensorList
bool isTensorList() const;
c10::List<at::Tensor> toTensorList() &&;
c10::List<at::Tensor> toTensorList() const &;
std::vector<at::Tensor> toTensorVector() const;
//GenericList
IValue(c10::List<IValue> v);
bool isList() const { return Tag::GenericList == tag; }
c10::List<IValue> toList() &&;
c10::List<IValue> toList() const &;
c10::ArrayRef<IValue> toListRef() const;
template<class T>
IValue(c10::List<T> v);
template<class T>
IValue(at::ArrayRef<T> v);
template<class T>
IValue(const std::vector<T>& v);
// GenericDict
IValue(c10::Dict<IValue, IValue> v);
bool isGenericDict() const { return Tag::GenericDict == tag; }
c10::Dict<IValue, IValue> toGenericDict() &&;
c10::Dict<IValue, IValue> toGenericDict() const &;
template<class Key, class Value>
IValue(c10::Dict<Key, Value> v);
template<class Key, class Value>
/// \cond DOXYGEN_CANNOT_HANDLE_CONSTRUCTORS_WITH_MACROS_SO_EXCLUDE_THIS_LINE_FROM_DOXYGEN
C10_DEPRECATED_MESSAGE("IValues based on std::unordered_map<K, V> are slow and deprecated. Please use c10::Dict<K, V> instead.")
/// \endcond
IValue(std::unordered_map<Key, Value> v);
template<class T>
IValue(c10::optional<T> v);
IValue(c10::nullopt_t);
// ClassType
IValue(c10::intrusive_ptr<ivalue::Object> v);
bool isObject() const { return tag == Tag::Object; }
c10::intrusive_ptr<ivalue::Object> toObject() &&;
c10::intrusive_ptr<ivalue::Object> toObject() const & ;
const ivalue::Object& toObjectRef() const;
torch::jit::script::Module toModule() const;
bool isModule() const;
// PyObject
IValue(c10::intrusive_ptr<ivalue::PyObjectHolder> v);
bool isPyObject() const { return tag == Tag::PyObject; }
c10::intrusive_ptr<ivalue::PyObjectHolder> toPyObjectHolder() &&;
c10::intrusive_ptr<ivalue::PyObjectHolder> toPyObjectHolder() const &;
PyObject* toPyObject() const;
// None
IValue() : payload{0}, tag(Tag::None), is_intrusive_ptr(false) {}
bool isNone() const {
return Tag::None == tag;
}
std::string toNone() const {
AT_ASSERT(isNone());
return "None";
}
static IValue uninitialized() {
auto i = IValue();
i.tag = Tag::Uninitialized;
return i;
}
// Scalar, which gets encoded as either an Int or a Double
IValue(at::Scalar s)
: IValue() {
if(s.isFloatingPoint()) {
*this = s.toDouble();
} else {
*this = s.toLong();
}
}
bool isScalar() const {
return isDouble() || isInt();
}
at::Scalar toScalar() const {
if(isDouble())
return toDouble();
else if(isInt())
return toInt();
throw std::runtime_error("IValue is not a Scalar");
}
// Device
IValue(c10::Device d)
: tag(Tag::Device), is_intrusive_ptr(false) {
payload.as_device.type = d.type();
payload.as_device.index = d.index();
}
bool isDevice() const { return Tag::Device == tag; }
c10::Device toDevice() const {
AT_ASSERT(isDevice());
return c10::Device(payload.as_device.type, payload.as_device.index);
}
// ScalarType
IValue(ScalarType t)
: IValue(static_cast<std::underlying_type<ScalarType>::type>(t)) {}
at::ScalarType toScalarType() const {
return static_cast<at::ScalarType>(toInt());
}
// Layout
IValue(Layout l)
: IValue(static_cast<std::underlying_type<Layout>::type>(l)) {}
at::Layout toLayout() const {
return static_cast<at::Layout>(toInt());
}
// MemoryFormat
IValue(MemoryFormat m)
: IValue(static_cast<std::underlying_type<MemoryFormat>::type>(m)) {}
at::MemoryFormat toMemoryFormat() const {
return static_cast<at::MemoryFormat>(toInt());
}
// QScheme
IValue(at::QScheme qscheme)
: tag(Tag::Int), is_intrusive_ptr(false) {
payload.as_int = static_cast<int64_t>(qscheme);
}
at::QScheme toQScheme() const {
return static_cast<at::QScheme>(toInt());
}
// for debugging
std::string tagKind() const {
switch(tag) {
#define DEFINE_CASE(x) case Tag::x: return #x;
TORCH_FORALL_TAGS(DEFINE_CASE)
#undef DEFINE_CASE
}
return "InvalidTag(" + c10::guts::to_string(static_cast<int>(tag)) + ")";
}
// generic v.to<at::Tensor>() implementations
// that can be used in special functions like pop/push
// that use template meta-programming.
// prefer the directly named methods when you can,
// since they are simpler to understand
// Note: if you get linker errors saying one of these is missing,
// change it to ... && = delete; and you will see better error messages for why
// However, we cannot commit this because some compiler versions barf on it.
template<typename T>
T to() &&;
template<typename T>
T to() const &;
// ToOptional: convert a IValue to the Optional obj that accepts both T and None
template<typename T>
optional<T> toOptional();
/// @private [doxygen private]
/// this is a shallow comparison of two IValues to test the object identity
bool isSameIdentity(const IValue& rhs) const;
// Computes the "official" string representation of an IValue. This produces a
// TorchScript expression that can be used to recreate an IValue with the same
// value (e.g. when we are printing constants in the serializer).
//
// Callers can use `customFormatter` to override how `repr()` prints out an
// IValue. This is useful if you have some other environment where you can
// look up values, and you want to print a reference to that environment (like
// the serializer's constant table).
//
// repr() is not necessarily defined on all objects!
std::ostream& repr(
std::ostream& stream,
std::function<bool(std::ostream&, const IValue& v)> customFormatter)
const;
// Computes an "informal" string representation of an IValue. This should be
// used for debugging, or servicing `print()`-like functions.
// This is different from `repr()` in that there is no expectation that we can
// exactly reconstruct an IValue from the output; feel free to use a
// concise/pretty form
CAFFE2_API friend std::ostream& operator<<(
std::ostream& out,
const IValue& v);
bool isPtrType() const {
return is_intrusive_ptr;
}
/// @private [doxygen private]
const void* internalToPointer() const {
TORCH_INTERNAL_ASSERT(isPtrType(), "Can only call internalToPointer() for pointer types");
return payload.as_intrusive_ptr;
}
TypePtr type() const;
private:
// NOTE: IValue tags are intentionally private. In the future we may encode
// this value different (e.g. using NaN boxing), and this would make it more
// costly to determine the tag for all types vs just determining if something
// is a particular type. Instead we want clients to use the `isX` methods when
// possible. If for perf. reasons you really, absolutely, must have a jump
// table, then we can revisit this.
enum class Tag : uint32_t {
#define DEFINE_TAG(x) x,
TORCH_FORALL_TAGS(DEFINE_TAG)
#undef DEFINE_TAG
};
template<class T, class NullType = c10::detail::intrusive_target_default_null_type<T>>
c10::intrusive_ptr<T, NullType> moveToIntrusivePtr();
template<typename T, class NullType = c10::detail::intrusive_target_default_null_type<T>>
c10::intrusive_ptr<T, NullType> toIntrusivePtr() const;
void clearToNone() {
payload.as_int = 0;
tag = Tag::None;
is_intrusive_ptr = false;
}
union Payload {
int64_t as_int;
double as_double;
bool as_bool;
c10::intrusive_ptr_target* as_intrusive_ptr;
struct {
DeviceType type;
DeviceIndex index;
} as_device;
};
IValue(Payload p, Tag t, bool i)
: payload(p), tag(t), is_intrusive_ptr(i) {}
Payload payload;
Tag tag;
bool is_intrusive_ptr;
friend struct WeakIValue;
};
struct CAFFE2_API WeakIValue final {
WeakIValue()
: payload{0}
, tag(IValue::Tag::None)
, is_intrusive_ptr(false) {}
WeakIValue(const WeakIValue& rhs)
: payload(rhs.payload),
tag(rhs.tag),
is_intrusive_ptr(rhs.is_intrusive_ptr) {
if (is_intrusive_ptr) {
c10::raw::weak_intrusive_ptr::incref(payload.as_intrusive_ptr);
}
}
WeakIValue(const IValue& rhs)
: payload(rhs.payload),
tag(rhs.tag),
is_intrusive_ptr(rhs.is_intrusive_ptr) {
if (is_intrusive_ptr) {
c10::raw::weak_intrusive_ptr::incref(payload.as_intrusive_ptr);
}
}
WeakIValue(WeakIValue&& rhs) noexcept : WeakIValue() {
swap(rhs);
}
~WeakIValue() {
if (is_intrusive_ptr) {
c10::raw::weak_intrusive_ptr::decref(payload.as_intrusive_ptr);
}
}
WeakIValue & operator=(WeakIValue && rhs) & noexcept {
WeakIValue(std::move(rhs)).swap(*this); // this also sets rhs to None
return *this;
}
WeakIValue & operator=(WeakIValue const & rhs) & {
WeakIValue(rhs).swap(*this);
return *this;
}
void swap(WeakIValue & rhs) noexcept {
std::swap(payload, rhs.payload);
std::swap(is_intrusive_ptr, rhs.is_intrusive_ptr);
std::swap(tag, rhs.tag);
}
bool isSameIdentity(const WeakIValue& rhs) const {
return payload.as_int == rhs.payload.as_int && tag == rhs.tag &&
is_intrusive_ptr == rhs.is_intrusive_ptr;
}
IValue lock() const {
if (!is_intrusive_ptr) {
return IValue(payload, tag, false);
}
auto temp = c10::weak_intrusive_ptr<c10::intrusive_ptr_target>::reclaim(
payload.as_intrusive_ptr);
IValue::Payload pl;
pl.as_intrusive_ptr = temp.lock().release();
temp.release();
if (!pl.as_intrusive_ptr) {
return IValue();
} else {
return IValue(pl, tag, true);
}
}
size_t use_count() const noexcept {
if (!is_intrusive_ptr) {
return 1;
}
auto temp = c10::weak_intrusive_ptr<c10::intrusive_ptr_target>::reclaim(
payload.as_intrusive_ptr);
size_t result = temp.use_count();
temp.release();
return result;
}
size_t weak_use_count() const noexcept {
if (!is_intrusive_ptr) {
return 1;
}
auto temp = c10::weak_intrusive_ptr<c10::intrusive_ptr_target>::reclaim(
payload.as_intrusive_ptr);
size_t result = temp.weak_use_count();
temp.release();
return result;
}
size_t hash() const {
return payload.as_int;
}
private:
IValue::Payload payload;
IValue::Tag tag;
bool is_intrusive_ptr;
};
// An owning pointer to a Class. Just a pair of shared_ptrs to the class type
// and its owning CU, so that the class type is guaranteed to stay alive as long
// as we hold this object.
struct StrongTypePtr {
StrongTypePtr(
std::shared_ptr<torch::jit::script::CompilationUnit> cu,
std::shared_ptr<ClassType> type)
: cu_(std::move(cu)), type_(type) {
TORCH_INTERNAL_ASSERT(cu_);
TORCH_INTERNAL_ASSERT(type_);
}
std::shared_ptr<torch::jit::script::CompilationUnit> cu_;
std::shared_ptr<ClassType> type_;
};
TORCH_API std::unordered_map<std::string, c10::StrongTypePtr>& getCustomClassTypeMap();
#ifndef C10_MOBILE
template<typename T>
c10::StrongTypePtr getCustomClassType() {
auto tmap = c10::getCustomClassTypeMap();
auto res = tmap.find(typeid(T).name());
if (res == tmap.end()) {
throw c10::Error("Can't find class id in custom class type map", "");
}
return res->second;
}
template<typename T>
inline bool isCustomClassRegistered() {
auto tmap = c10::getCustomClassTypeMap();
return tmap.find(typeid(T).name()) != tmap.end();
}
#else // C10_MOBILE
template<typename T>
c10::StrongTypePtr getCustomClassType() {
throw c10::Error("Custom class is not supported on mobile.", "");
}
template<typename T>
inline bool isCustomClassRegistered() {
return false;
}
#endif // C10_MOBILE
TORCH_API std::unordered_map<std::string, std::function<PyObject*(void*)>>&
getClassConverter();
}
#include <ATen/core/ivalue_inl.h>