xref: /aosp_15_r20/external/pytorch/torch/jit/_pickle.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1# mypy: allow-untyped-defs
2# These functions are referenced from the pickle archives produced by
3# ScriptModule.save()
4
5
6# These (`build_*`) functions used to be used by `pickler.cpp` to specify
7# the type of the list for certain special types, but now all lists get
8# a type attached and restored via `restore_type_tag` below. The legacy
9# functions should stick around for backwards-compatibility.
10
11
12def build_intlist(data):
13    return data
14
15
16def build_tensorlist(data):
17    return data
18
19
20def build_doublelist(data):
21    return data
22
23
24def build_boollist(data):
25    return data
26
27
28def build_tensor_from_id(data):
29    if isinstance(data, int):
30        # just the id, can't really do anything
31        return data
32
33
34def restore_type_tag(value, type_str):
35    # The type_ptr is used by the jit unpickler to restore the full static type
36    # to container types like list when they are re-loaded, but this doesn't
37    # matter for Python, so just return the plain value
38    return value
39