ZTWHHH commited on
Commit
68d68ef
·
verified ·
1 Parent(s): 2fa976f

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/CUDAPluggableAllocator.h +142 -0
  2. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Event.h +18 -0
  3. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Module.h +12 -0
  4. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Stream.h +19 -0
  5. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/THCP.h +10 -0
  6. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/comm.h +52 -0
  7. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/device_set.h +10 -0
  8. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/memory_snapshot.h +26 -0
  9. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/nccl.h +218 -0
  10. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_comm.h +7 -0
  11. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_nccl.h +13 -0
  12. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/jit_log.h +128 -0
  13. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/jit_opt_limit.h +39 -0
  14. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/add_if_then_else.h +11 -0
  15. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/canonicalize.h +22 -0
  16. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/check_strict_fusion.h +12 -0
  17. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/mkldnn_rewrite.h +34 -0
  18. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/normalize_ops.h +18 -0
  19. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/pass_manager.h +136 -0
  20. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/refine_tuple_types.h +12 -0
  21. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/remove_expands.h +11 -0
  22. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/replacement_of_old_operators.h +16 -0
  23. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/variadic_ops.h +31 -0
  24. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/resource_guard.h +27 -0
  25. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/export.h +280 -0
  26. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/export_bytecode.h +46 -0
  27. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/flatbuffer_serializer.h +94 -0
  28. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/flatbuffer_serializer_jit.h +11 -0
  29. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import.h +157 -0
  30. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_export_constants.h +21 -0
  31. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_export_functions.h +16 -0
  32. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_export_helpers.h +32 -0
  33. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_legacy.h +23 -0
  34. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_read.h +31 -0
  35. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_source.h +103 -0
  36. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/mobile_bytecode_generated.h +0 -0
  37. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/onnx.h +12 -0
  38. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/pickle.h +107 -0
  39. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/pickler.h +429 -0
  40. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/python_print.h +58 -0
  41. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/source_range_serialization.h +68 -0
  42. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/storage_context.h +85 -0
  43. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/type_name_uniquer.h +33 -0
  44. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/unpickler.h +203 -0
  45. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/utils/byte_order.h +227 -0
  46. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/utils/disable_torch_function.h +41 -0
  47. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/utils/pythoncapi_compat.h +716 -0
  48. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/utils/tensor_apply.h +21 -0
  49. videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/utils/tensor_qschemes.h +11 -0
  50. vllm/lib/python3.10/site-packages/dns/__init__.py +70 -0
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/CUDAPluggableAllocator.h ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <c10/core/Allocator.h>
4
+ #include <c10/cuda/CUDAGraphsC10Utils.h>
5
+ #include <c10/cuda/CUDAMacros.h>
6
+ #include <c10/cuda/CUDAStream.h>
7
+
8
+ #include <c10/cuda/CUDACachingAllocator.h>
9
+
10
+ #include <array>
11
+ #include <mutex>
12
+
13
+ namespace torch::cuda::CUDAPluggableAllocator {
14
+
15
+ #if defined(TORCH_HIP_VERSION)
16
+ using streamType = c10::hip::HIPStream;
17
+ #else
18
+ using streamType = c10::cuda::CUDAStream;
19
+ #endif
20
+
21
+ std::shared_ptr<c10::cuda::CUDACachingAllocator::CUDAAllocator>
22
+ getCurrentAllocator();
23
+ std::shared_ptr<c10::cuda::CUDACachingAllocator::CUDAAllocator>
24
+ createCustomAllocator(
25
+ std::function<void*(size_t, int, cudaStream_t)> alloc_fn,
26
+ std::function<void(void*, size_t, int, cudaStream_t)> free_fn);
27
+ void changeCurrentAllocator(
28
+ const std::shared_ptr<c10::cuda::CUDACachingAllocator::CUDAAllocator>&
29
+ allocator);
30
+
31
+ struct _AllocationMetadata {
32
+ _AllocationMetadata();
33
+ _AllocationMetadata(size_t size, int device_idx, cudaStream_t stream);
34
+ size_t size;
35
+ int device_idx;
36
+ cudaStream_t stream;
37
+ };
38
+
39
+ struct CUDAPluggableAllocator
40
+ : public c10::cuda::CUDACachingAllocator::CUDAAllocator {
41
+ CUDAPluggableAllocator(
42
+ std::function<void*(size_t, int, cudaStream_t)> alloc_fn,
43
+ std::function<void(void*, size_t, int, cudaStream_t)> free_fn);
44
+
45
+ CUDAPluggableAllocator(CUDAPluggableAllocator& other);
46
+
47
+ void set_init_fn(std::function<void(int)> init_fn);
48
+
49
+ void set_reset_fn(std::function<void()> reset_fn);
50
+
51
+ void set_memory_fraction_fn(
52
+ std::function<void(double, int)> memory_fraction_fn);
53
+
54
+ void set_base_alloc_fn(std::function<void*(void*, size_t*)> base_alloc_fn);
55
+
56
+ void set_record_stream_fn(
57
+ std::function<void(void* ptr, cudaStream_t stream)> record_stream_fn);
58
+
59
+ void set_begin_allocate_stream_to_pool(
60
+ std::function<void(int, cudaStream_t, c10::cuda::MempoolId_t)>
61
+ capture_begin_fn);
62
+
63
+ void set_end_allocate_stream_to_pool_fn(
64
+ std::function<void(int, cudaStream_t)> capture_about_to_end_fn);
65
+
66
+ void set_release_pool(
67
+ std::function<void(int, c10::cuda::MempoolId_t)> capture_destroy_fn);
68
+
69
+ void* malloc(size_t size, int device, cudaStream_t stream);
70
+
71
+ c10::DataPtr allocate(size_t size) const override;
72
+ c10::DeleterFnPtr raw_deleter() const override;
73
+
74
+ void* raw_alloc(size_t nbytes) override;
75
+ void* raw_alloc_with_stream(size_t nbytes, cudaStream_t stream) override;
76
+ void raw_delete(void* ptr) override;
77
+ void init(int device_count) override;
78
+ bool initialized() override;
79
+ void setMemoryFraction(double fraction, int device) override;
80
+ void emptyCache() override;
81
+ void cacheInfo(int dev_id, size_t* largestBlock) override;
82
+ void* getBaseAllocation(void* ptr, size_t* size) override;
83
+
84
+ void recordStream(const c10::DataPtr&, streamType stream) override;
85
+
86
+ c10::cuda::CUDACachingAllocator::DeviceStats getDeviceStats(
87
+ int device) override;
88
+ void resetAccumulatedStats(int device) override;
89
+ void resetPeakStats(int device) override;
90
+ c10::cuda::CUDACachingAllocator::SnapshotInfo snapshot() override;
91
+ void beginAllocateStreamToPool(
92
+ int device,
93
+ cudaStream_t stream,
94
+ c10::cuda::MempoolId_t mempool_id) override;
95
+ void endAllocateStreamToPool(int device, cudaStream_t stream) override;
96
+ void releasePool(int device, c10::cuda::MempoolId_t mempool_id) override;
97
+ std::shared_ptr<void> getIpcDevPtr(std::string handle) override;
98
+ void recordHistory(
99
+ bool enabled,
100
+ c10::cuda::CUDACachingAllocator::CreateContextFn context_recorder,
101
+ size_t alloc_trace_max_entries,
102
+ c10::cuda::CUDACachingAllocator::RecordContext when) override;
103
+ void attachOutOfMemoryObserver(
104
+ c10::cuda::CUDACachingAllocator::OutOfMemoryObserver observer) override;
105
+ void attachAllocatorTraceTracker(
106
+ c10::cuda::CUDACachingAllocator::AllocatorTraceTracker tracker) override;
107
+ std::shared_ptr<c10::cuda::CUDACachingAllocator::AllocatorState>
108
+ getCheckpointState(int device, at::cuda::MempoolId_t id) override;
109
+ c10::cuda::CUDACachingAllocator::CheckpointDelta setCheckpointPoolState(
110
+ int device,
111
+ std::shared_ptr<c10::cuda::CUDACachingAllocator::AllocatorState> pps)
112
+ override;
113
+ void enablePeerAccess(int dev, int dev_to_access) override;
114
+ cudaError_t memcpyAsync(
115
+ void* dst,
116
+ int dstDevice,
117
+ const void* src,
118
+ int srcDevice,
119
+ size_t count,
120
+ cudaStream_t stream,
121
+ bool p2p_enabled) override;
122
+ std::string name() override;
123
+
124
+ protected:
125
+ std::function<void*(size_t, int, cudaStream_t)> alloc_fn_;
126
+ std::function<void(void*, size_t, int, cudaStream_t)> free_fn_;
127
+ std::function<void(int)> init_fn_;
128
+ std::function<void()> reset_fn_;
129
+ std::function<void(double, int)> memory_fraction_fn_;
130
+ std::function<void*(void*, size_t*)> base_alloc_fn_;
131
+ std::function<void(void* ptr, cudaStream_t stream)> record_stream_fn_;
132
+ std::function<void(int, cudaStream_t, c10::cuda::MempoolId_t)>
133
+ begin_allocate_stream_to_pool_fn_;
134
+ std::function<void(int, cudaStream_t)> end_allocate_stream_to_pool_fn_;
135
+ std::function<void(int, c10::cuda::MempoolId_t)> relase_pool_fn_;
136
+ std::mutex allocator_mutex_;
137
+ // We do the bookeeping here in order to simplify custom allocators
138
+ std::unordered_map<void*, _AllocationMetadata> allocation_metadata_;
139
+
140
+ bool initialized_ = false;
141
+ };
142
+ } // namespace torch::cuda::CUDAPluggableAllocator
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Event.h ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef THCP_EVENT_INC
2
+ #define THCP_EVENT_INC
3
+
4
+ #include <ATen/cuda/CUDAEvent.h>
5
+ #include <torch/csrc/python_headers.h>
6
+
7
+ struct THCPEvent {
8
+ PyObject_HEAD at::cuda::CUDAEvent cuda_event;
9
+ };
10
+ extern PyObject* THCPEventClass;
11
+
12
+ void THCPEvent_init(PyObject* module);
13
+
14
+ inline bool THCPEvent_Check(PyObject* obj) {
15
+ return THCPEventClass && PyObject_IsInstance(obj, THCPEventClass);
16
+ }
17
+
18
+ #endif // THCP_EVENT_INC
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Module.h ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef THCP_CUDA_MODULE_INC
2
+ #define THCP_CUDA_MODULE_INC
3
+
4
+ void THCPModule_setDevice(int idx);
5
+ PyObject* THCPModule_getDevice_wrap(PyObject* self);
6
+ PyObject* THCPModule_setDevice_wrap(PyObject* self, PyObject* arg);
7
+ PyObject* THCPModule_getDeviceName_wrap(PyObject* self, PyObject* arg);
8
+ PyObject* THCPModule_getDriverVersion(PyObject* self);
9
+ PyObject* THCPModule_isDriverSufficient(PyObject* self);
10
+ PyObject* THCPModule_getCurrentBlasHandle_wrap(PyObject* self);
11
+
12
+ #endif
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Stream.h ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef THCP_STREAM_INC
2
+ #define THCP_STREAM_INC
3
+
4
+ #include <c10/cuda/CUDAStream.h>
5
+ #include <torch/csrc/Stream.h>
6
+ #include <torch/csrc/python_headers.h>
7
+
8
+ struct THCPStream : THPStream {
9
+ at::cuda::CUDAStream cuda_stream;
10
+ };
11
+ extern PyObject* THCPStreamClass;
12
+
13
+ void THCPStream_init(PyObject* module);
14
+
15
+ inline bool THCPStream_Check(PyObject* obj) {
16
+ return THCPStreamClass && PyObject_IsInstance(obj, THCPStreamClass);
17
+ }
18
+
19
+ #endif // THCP_STREAM_INC
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/THCP.h ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef THCP_H
2
+ #define THCP_H
3
+
4
+ #include <torch/csrc/THP.h>
5
+ #include <torch/csrc/cuda/Event.h>
6
+ #include <torch/csrc/cuda/Module.h>
7
+ #include <torch/csrc/cuda/Stream.h>
8
+ #include <torch/csrc/python_headers.h>
9
+
10
+ #endif
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/comm.h ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/ATen.h>
4
+ #include <ATen/cuda/ATenCUDAGeneral.h>
5
+ #include <ATen/cuda/CUDAContext.h>
6
+ #include <c10/util/Optional.h>
7
+ #include <torch/csrc/Export.h>
8
+
9
+ #include <cstddef>
10
+ #include <vector>
11
+
12
+ namespace torch::cuda {
13
+
14
+ using tensor_list2d = std::vector<std::vector<at::Tensor>>;
15
+
16
+ TORCH_CUDA_CU_API std::vector<at::Tensor>& broadcast_out(
17
+ const at::Tensor& tensor,
18
+ std::vector<at::Tensor>& out_tensors);
19
+ TORCH_CUDA_CU_API std::vector<at::Tensor> broadcast(
20
+ const at::Tensor& tensor,
21
+ at::IntArrayRef devices);
22
+ TORCH_CUDA_CU_API tensor_list2d broadcast_coalesced(
23
+ at::TensorList tensors,
24
+ at::IntArrayRef devices,
25
+ size_t buffer_size);
26
+
27
+ TORCH_CUDA_CU_API std::vector<at::Tensor>& scatter_out(
28
+ const at::Tensor& tensor,
29
+ std::vector<at::Tensor>& out_tensors,
30
+ int64_t dim = 0,
31
+ const c10::optional<std::vector<c10::optional<at::cuda::CUDAStream>>>&
32
+ streams = c10::nullopt);
33
+
34
+ TORCH_CUDA_CU_API std::vector<at::Tensor> scatter(
35
+ const at::Tensor& tensor,
36
+ at::IntArrayRef devices,
37
+ const c10::optional<std::vector<int64_t>>& chunk_sizes = c10::nullopt,
38
+ int64_t dim = 0,
39
+ const c10::optional<std::vector<c10::optional<at::cuda::CUDAStream>>>&
40
+ streams = c10::nullopt);
41
+
42
+ TORCH_CUDA_CU_API at::Tensor& gather_out(
43
+ at::TensorList tensors,
44
+ at::Tensor& out_tensor,
45
+ int64_t dim);
46
+
47
+ TORCH_CUDA_CU_API at::Tensor gather(
48
+ at::TensorList tensors,
49
+ int64_t dim,
50
+ c10::optional<int32_t> destination_index);
51
+
52
+ } // namespace torch::cuda
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/device_set.h ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <bitset>
4
+
5
+ namespace torch {
6
+
7
+ static constexpr size_t MAX_CUDA_DEVICES = 64;
8
+ using device_set = std::bitset<MAX_CUDA_DEVICES>;
9
+
10
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/memory_snapshot.h ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <c10/util/Optional.h>
4
+ #include <torch/csrc/Export.h>
5
+ #include <string>
6
+
7
+ namespace torch::cuda {
8
+
9
+ // C++-only versions of these, for python use
10
+ // those defined in cuda/Module.cpp which also record python state.
11
+ TORCH_CUDA_CU_API void _record_memory_history(
12
+ bool enabled,
13
+ bool record_context = true,
14
+ int64_t trace_alloc_max_entries = 1,
15
+ bool trace_alloc_record_context = false,
16
+ bool record_cpp_context = false);
17
+
18
+ TORCH_CUDA_CU_API void _record_memory_history(
19
+ c10::optional<std::string> enabled = "all",
20
+ c10::optional<std::string> context = "all",
21
+ std::string stacks = "all",
22
+ size_t max_entries = UINT64_MAX);
23
+
24
+ TORCH_CUDA_CU_API std::string _memory_snapshot_pickled();
25
+
26
+ } // namespace torch::cuda
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/nccl.h ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/ATen.h>
4
+ #include <ATen/cuda/CUDAContext.h>
5
+ #include <c10/util/Optional.h>
6
+
7
+ #include <cstddef>
8
+ #include <vector>
9
+
10
+ // NCCL BFloat16 is enabled only for CUDA 11+ and NCCL versions 2.10+, or for
11
+ // HIP 3.1+
12
+ #if defined(__CUDA_BF16_TYPES_EXIST__)
13
+ #define HAS_NCCL_BF16_DATATYPE \
14
+ ((NCCL_MAJOR > 2) || (NCCL_MAJOR == 2) && (NCCL_MINOR >= 10))
15
+ #elif defined(USE_ROCM) && (TORCH_HIP_VERSION >= 301)
16
+ #define HAS_NCCL_BF16_DATATYPE 1
17
+ #else
18
+ #define HAS_NCCL_BF16_DATATYPE 0
19
+ #endif
20
+
21
+ namespace torch::cuda::nccl {
22
+
23
+ /* The following are copied from <nccl.h> and redefined in torch::cuda::nccl
24
+ * namespace */
25
+ /* pytorch should only use the following definition within pytorch scope */
26
+
27
+ /* Opaque handle to communicator to ncclComm*, this will reinterpret as ncclComm
28
+ * in nccl.cpp */
29
+ typedef void* ncclComm_t;
30
+
31
+ /** redefine nccl unique ID in torch scope. this should be identical to native
32
+ * nccl impp. */
33
+ #define NCCL_UNIQUE_ID_BYTES 128
34
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
35
+ typedef struct {
36
+ char internal[NCCL_UNIQUE_ID_BYTES];
37
+ } ncclUniqueId;
38
+
39
+ /* Error type */
40
+ enum class ncclResult {
41
+ Success = 0,
42
+ UnhandledCudaError = 1,
43
+ SystemError = 2,
44
+ InternalError = 3,
45
+ InvalidArgument = 4,
46
+ InvalidUsage = 5,
47
+ NumResults = 6,
48
+ InProgress = 7
49
+ };
50
+
51
+ /* Reduction operation selector */
52
+ enum class ncclRedOp { Sum = 0, Prod = 1, Max = 2, Min = 3, NumOps = 4 };
53
+
54
+ /* Data types */
55
+ enum class ncclDataType {
56
+ Int8 = 0,
57
+ Char = 0,
58
+ Uint8 = 1,
59
+ Int32 = 2,
60
+ Int = 2,
61
+ Uint32 = 3,
62
+ Int64 = 4,
63
+ Uint64 = 5,
64
+ Float16 = 6,
65
+ Half = 6,
66
+ Float32 = 7,
67
+ Float = 7,
68
+ Float64 = 8,
69
+ Double = 8,
70
+ Bfloat16 = 9,
71
+ NumTypes = 10
72
+ };
73
+
74
+ // RAII helper class to manage NCCL group API and CUDA free mutex.
75
+ // The destructor is allowed to throw since this helper class only
76
+ // manages group and lock lifetimes.
77
+ struct AutoNcclGroup {
78
+ AutoNcclGroup();
79
+ AutoNcclGroup(std::vector<ncclComm_t>& comms, bool comm_nonblocking);
80
+ ~AutoNcclGroup() noexcept(false);
81
+ std::vector<ncclComm_t> comms_;
82
+ bool comm_nonblocking_;
83
+ };
84
+
85
+ // NOTE: this is exposed only so that python_nccl.cpp can some of these helpers.
86
+ // Don't use them outside of these files.
87
+ namespace detail {
88
+
89
+ TORCH_CUDA_CPP_API void throw_nccl_error(ncclResult status);
90
+
91
+ static inline void NCCL_CHECK(ncclResult status) {
92
+ if (status != ncclResult::Success) {
93
+ throw_nccl_error(status);
94
+ }
95
+ }
96
+
97
+ TORCH_CUDA_CPP_API at::ArrayRef<ncclComm_t> get_communicators(
98
+ at::TensorList inputs);
99
+ TORCH_CUDA_CPP_API void check_inputs(
100
+ at::TensorList inputs,
101
+ at::TensorList outputs,
102
+ int input_multiplier,
103
+ int output_multiplier);
104
+ TORCH_CUDA_CPP_API void check_inputs(
105
+ at::TensorList inputs,
106
+ const at::Tensor& output,
107
+ int root,
108
+ int input_multiplier,
109
+ int output_multiplier);
110
+
111
+ } // namespace detail
112
+
113
+ using comm_list = std::vector<ncclComm_t>;
114
+ using stream_list = std::vector<c10::optional<at::cuda::CUDAStream>>;
115
+
116
+ TORCH_CUDA_CPP_API std::uint64_t version();
117
+ TORCH_CUDA_CPP_API const char* version_suffix();
118
+
119
+ bool is_available(at::TensorList tensors);
120
+
121
+ TORCH_CUDA_CPP_API void get_unique_id(ncclUniqueId& id);
122
+ TORCH_CUDA_CPP_API ncclComm_t
123
+ comm_init_rank(int nranks, const ncclUniqueId& comm_id, int rank);
124
+ TORCH_CUDA_CPP_API void comm_destroy(ncclComm_t comm);
125
+
126
+ TORCH_CUDA_CPP_API void broadcast(
127
+ at::TensorList tensors,
128
+ const stream_list& streams = {},
129
+ const comm_list& user_comms = {});
130
+
131
+ size_t get_max_count();
132
+
133
+ TORCH_CUDA_CPP_API void reduce(
134
+ const std::vector<at::Tensor>& inputs,
135
+ at::Tensor& output,
136
+ int32_t root = 0,
137
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
138
+ const stream_list& streams = {},
139
+ const comm_list& user_comms = {});
140
+
141
+ TORCH_CUDA_CPP_API void reduce(
142
+ std::vector<at::Tensor>& inputs,
143
+ int32_t root = 0,
144
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
145
+ const stream_list& streams = {},
146
+ const comm_list& user_comms = {});
147
+
148
+ TORCH_CUDA_CPP_API void all_reduce(
149
+ const std::vector<at::Tensor>& inputs,
150
+ std::vector<at::Tensor>& outputs,
151
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
152
+ const stream_list& streams = {},
153
+ const comm_list& user_comms = {});
154
+
155
+ TORCH_CUDA_CPP_API void reduce_scatter(
156
+ const std::vector<at::Tensor>& inputs,
157
+ std::vector<at::Tensor>& outputs,
158
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
159
+ const stream_list& streams = {},
160
+ const comm_list& user_comms = {});
161
+
162
+ TORCH_CUDA_CPP_API void scatter(
163
+ const std::vector<at::Tensor>& inputs,
164
+ at::Tensor& outputs,
165
+ ncclComm_t comm,
166
+ at::cuda::CUDAStream& stream,
167
+ int32_t root = 0);
168
+
169
+ TORCH_CUDA_CPP_API void all_gather(
170
+ const std::vector<at::Tensor>& inputs,
171
+ std::vector<at::Tensor>& outputs,
172
+ const stream_list& streams = {},
173
+ const comm_list& user_comms = {});
174
+
175
+ TORCH_CUDA_CPP_API void gather(
176
+ const at::Tensor& inputs,
177
+ std::vector<at::Tensor>& outputs,
178
+ ncclComm_t comm,
179
+ at::cuda::CUDAStream& stream,
180
+ int32_t root = 0);
181
+
182
+ TORCH_CUDA_CPP_API void all2all_single_equal_split(
183
+ at::Tensor& input,
184
+ at::Tensor& output,
185
+ int size,
186
+ ncclComm_t comm,
187
+ at::cuda::CUDAStream& stream);
188
+
189
+ TORCH_CUDA_CPP_API void all2all_single_unequal_split(
190
+ void* sendbuff,
191
+ const size_t* sendcounts,
192
+ const size_t* senddispls,
193
+ void* recvbuff,
194
+ const size_t* recvcounts,
195
+ const size_t* recvdispls,
196
+ size_t size,
197
+ c10::ScalarType type,
198
+ ncclComm_t comm,
199
+ at::cuda::CUDAStream& stream);
200
+
201
+ TORCH_CUDA_CPP_API void all2all(
202
+ std::vector<at::Tensor>& outputTensors,
203
+ std::vector<at::Tensor>& inputTensors,
204
+ ncclComm_t _comm,
205
+ at::cuda::CUDAStream& stream);
206
+
207
+ TORCH_CUDA_CPP_API void send(
208
+ const at::Tensor& input,
209
+ ncclComm_t comm,
210
+ at::cuda::CUDAStream stream,
211
+ int dst);
212
+
213
+ TORCH_CUDA_CPP_API void recv(
214
+ at::Tensor& output,
215
+ ncclComm_t comm,
216
+ at::cuda::CUDAStream stream,
217
+ int src);
218
+ } // namespace torch::cuda::nccl
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_comm.h ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ namespace torch::cuda::python {
4
+
5
+ void initCommMethods(PyObject* module);
6
+
7
+ } // namespace torch::cuda::python
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_nccl.h ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/python_headers.h>
4
+
5
+ PyObject* THCPModule_nccl_version(PyObject* self, PyObject* args);
6
+ PyObject* THCPModule_nccl_version_suffix(PyObject* self, PyObject* args);
7
+ PyObject* THCPModule_nccl_unique_id(PyObject* self, PyObject* args);
8
+ PyObject* THCPModule_nccl_init_rank(PyObject* self, PyObject* args);
9
+ PyObject* THCPModule_nccl_reduce(PyObject* self, PyObject* args);
10
+ PyObject* THCPModule_nccl_all_reduce(PyObject* self, PyObject* args);
11
+ PyObject* THCPModule_nccl_broadcast(PyObject* self, PyObject* args);
12
+ PyObject* THCPModule_nccl_all_gather(PyObject* self, PyObject* args);
13
+ PyObject* THCPModule_nccl_reduce_scatter(PyObject* self, PyObject* args);
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/jit_log.h ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #include <torch/csrc/Export.h>
3
+ #include <memory>
4
+ #include <ostream>
5
+ #include <string>
6
+ #include <unordered_map>
7
+
8
+ // `TorchScript` offers a simple logging facility that can enabled by setting an
9
+ // environment variable `PYTORCH_JIT_LOG_LEVEL`.
10
+
11
+ // Logging is enabled on a per file basis. To enable logging in
12
+ // `dead_code_elimination.cpp`, `PYTORCH_JIT_LOG_LEVEL` should be
13
+ // set to `dead_code_elimination.cpp` or, simply, to `dead_code_elimination`
14
+ // (i.e. `PYTORCH_JIT_LOG_LEVEL=dead_code_elimination`).
15
+
16
+ // Multiple files can be logged by separating each file name with a colon `:` as
17
+ // in the following example,
18
+ // `PYTORCH_JIT_LOG_LEVEL=dead_code_elimination:guard_elimination`
19
+
20
+ // There are 3 logging levels available for your use ordered by the detail level
21
+ // from lowest to highest.
22
+
23
+ // * `GRAPH_DUMP` should be used for printing entire graphs after optimization
24
+ // passes
25
+ // * `GRAPH_UPDATE` should be used for reporting graph transformations (i.e.
26
+ // node deletion, constant folding, etc)
27
+ // * `GRAPH_DEBUG` should be used for providing information useful for debugging
28
+ // the internals of a particular optimization pass or analysis
29
+
30
+ // The default logging level is `GRAPH_DUMP` meaning that only `GRAPH_DUMP`
31
+ // statements will be enabled when one specifies a file(s) in
32
+ // `PYTORCH_JIT_LOG_LEVEL`.
33
+
34
+ // `GRAPH_UPDATE` can be enabled by prefixing a file name with an `>` as in
35
+ // `>alias_analysis`.
36
+ // `GRAPH_DEBUG` can be enabled by prefixing a file name with an `>>` as in
37
+ // `>>alias_analysis`.
38
+ // `>>>` is also valid and **currently** is equivalent to `GRAPH_DEBUG` as there
39
+ // is no logging level that is higher than `GRAPH_DEBUG`.
40
+
41
+ namespace torch {
42
+ namespace jit {
43
+
44
+ struct Node;
45
+ struct Graph;
46
+
47
+ enum class JitLoggingLevels {
48
+ GRAPH_DUMP = 0,
49
+ GRAPH_UPDATE,
50
+ GRAPH_DEBUG,
51
+ };
52
+
53
+ TORCH_API std::string get_jit_logging_levels();
54
+
55
+ TORCH_API void set_jit_logging_levels(std::string level);
56
+
57
+ TORCH_API void set_jit_logging_output_stream(std::ostream& out_stream);
58
+
59
+ TORCH_API std::ostream& get_jit_logging_output_stream();
60
+
61
+ TORCH_API std::string getHeader(const Node* node);
62
+
63
+ TORCH_API std::string log_function(const std::shared_ptr<Graph>& graph);
64
+
65
+ TORCH_API ::torch::jit::JitLoggingLevels jit_log_level();
66
+
67
+ // Prefix every line in a multiline string \p IN_STR with \p PREFIX.
68
+ TORCH_API std::string jit_log_prefix(
69
+ const std::string& prefix,
70
+ const std::string& in_str);
71
+
72
+ TORCH_API std::string jit_log_prefix(
73
+ ::torch::jit::JitLoggingLevels level,
74
+ const char* fn,
75
+ int l,
76
+ const std::string& in_str);
77
+
78
+ TORCH_API bool is_enabled(
79
+ const char* cfname,
80
+ ::torch::jit::JitLoggingLevels level);
81
+
82
+ TORCH_API std::ostream& operator<<(
83
+ std::ostream& out,
84
+ ::torch::jit::JitLoggingLevels level);
85
+
86
+ #define JIT_LOG(level, ...) \
87
+ if (is_enabled(__FILE__, level)) { \
88
+ ::torch::jit::get_jit_logging_output_stream() \
89
+ << ::torch::jit::jit_log_prefix( \
90
+ level, __FILE__, __LINE__, ::c10::str(__VA_ARGS__)); \
91
+ }
92
+
93
+ // tries to reconstruct original python source
94
+ #define SOURCE_DUMP(MSG, G) \
95
+ JIT_LOG( \
96
+ ::torch::jit::JitLoggingLevels::GRAPH_DUMP, \
97
+ MSG, \
98
+ "\n", \
99
+ ::torch::jit::log_function(G));
100
+ // use GRAPH_DUMP for dumping graphs after optimization passes
101
+ #define GRAPH_DUMP(MSG, G) \
102
+ JIT_LOG( \
103
+ ::torch::jit::JitLoggingLevels::GRAPH_DUMP, MSG, "\n", (G)->toString());
104
+ // use GRAPH_UPDATE for reporting graph transformations (i.e. node deletion,
105
+ // constant folding, CSE)
106
+ #define GRAPH_UPDATE(...) \
107
+ JIT_LOG(::torch::jit::JitLoggingLevels::GRAPH_UPDATE, __VA_ARGS__);
108
+ // use GRAPH_DEBUG to provide information useful for debugging a particular opt
109
+ // pass
110
+ #define GRAPH_DEBUG(...) \
111
+ JIT_LOG(::torch::jit::JitLoggingLevels::GRAPH_DEBUG, __VA_ARGS__);
112
+ // use GRAPH_EXPORT to export a graph so that the IR can be loaded by a script
113
+ #define GRAPH_EXPORT(MSG, G) \
114
+ JIT_LOG( \
115
+ ::torch::jit::JitLoggingLevels::GRAPH_DEBUG, \
116
+ MSG, \
117
+ "\n<GRAPH_EXPORT>\n", \
118
+ (G)->toString(), \
119
+ "</GRAPH_EXPORT>");
120
+
121
+ #define GRAPH_DUMP_ENABLED \
122
+ (is_enabled(__FILE__, ::torch::jit::JitLoggingLevels::GRAPH_DUMP))
123
+ #define GRAPH_UPDATE_ENABLED \
124
+ (is_enabled(__FILE__, ::torch::jit::JitLoggingLevels::GRAPH_UPDATE))
125
+ #define GRAPH_DEBUG_ENABLED \
126
+ (is_enabled(__FILE__, ::torch::jit::JitLoggingLevels::GRAPH_DEBUG))
127
+ } // namespace jit
128
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/jit_opt_limit.h ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #include <torch/csrc/Export.h>
3
+ #include <string>
4
+ #include <unordered_map>
5
+
6
+ // `TorchScript` offers a simple optimization limit checker
7
+ // that can be configured through environment variable `PYTORCH_JIT_OPT_LIMIT`.
8
+ // The purpose is to limit how many optimization you can make per pass.
9
+ // This is useful for debugging any passes.
10
+
11
+ // Opt limit checker is enabled on a per file basis (hence per pass). For
12
+ // example, in `constant_propagation.cpp`, `PYTORCH_JIT_OPT_LIMIT` should be set
13
+ // to `constant_propagation=<opt_limit>` or, simply, to
14
+ // `constant_propagation=<opt_limit>` where <opt_limit> is the number of
15
+ // optimizations you want to make for the pass. (i.e.
16
+ // `PYTORCH_JIT_OPT_LIMIT="constant_propagation=<opt_limit>"`).
17
+
18
+ // Multiple files can be configured by separating each file name with a colon
19
+ // `:` as in the following example,
20
+ // `PYTORCH_JIT_OPT_LIMIT="constant_propagation=<opt_limit>:dead_code_elimination=<opt_limit>"`
21
+
22
+ // You can call opt limiter by calling JIT_OPT_ALLOWED. It will return true if
23
+ // we haven't reached the optimization limit yet. Otherwise, it will return
24
+ // false. Typical usage:
25
+
26
+ // if (!JIT_OPT_ALLOWED) {
27
+ // GRAPH_DUMP(...); //supplied from jit_log
28
+ // return;
29
+ // }
30
+
31
+ namespace torch {
32
+ namespace jit {
33
+
34
+ TORCH_API bool opt_limit(const char* pass_name);
35
+
36
+ #define JIT_OPT_ALLOWED opt_limit(__FILE__)
37
+
38
+ } // namespace jit
39
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/add_if_then_else.h ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/ir/ir.h>
4
+
5
+ namespace torch {
6
+ namespace jit {
7
+
8
+ TORCH_API bool AddIfThenElseOp(std::shared_ptr<Graph>& graph);
9
+
10
+ } // namespace jit
11
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/canonicalize.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/ir/ir.h>
4
+
5
+ namespace torch {
6
+ namespace jit {
7
+
8
+ TORCH_API std::shared_ptr<Graph> Canonicalize(
9
+ const std::shared_ptr<Graph>& graph,
10
+ bool keep_unique_names = true);
11
+
12
+ TORCH_API void CanonicalizeOutputs(std::shared_ptr<Graph>& graph);
13
+
14
+ TORCH_API c10::optional<const Use> firstOrLastUse(Value* v, bool find_first);
15
+
16
+ TORCH_API bool isBeforeOrAfter(
17
+ const Use& a,
18
+ const Use& b,
19
+ bool checking_before);
20
+
21
+ } // namespace jit
22
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/check_strict_fusion.h ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #pragma once
3
+
4
+ #include <torch/csrc/jit/ir/ir.h>
5
+
6
+ namespace torch {
7
+ namespace jit {
8
+
9
+ TORCH_API void CheckStrictFusion(std::shared_ptr<Graph>& graph);
10
+
11
+ } // namespace jit
12
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/mkldnn_rewrite.h ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/Config.h>
4
+ #include <torch/csrc/jit/api/module.h>
5
+ #include <torch/csrc/jit/ir/ir.h>
6
+ #include <torch/csrc/jit/passes/subgraph_rewrite.h>
7
+
8
+ #if AT_MKLDNN_ENABLED()
9
+
10
+ #include <ideep/tensor.hpp>
11
+
12
+ #endif // AT_MKLDNN_ENABLED()
13
+
14
+ namespace torch {
15
+ namespace jit {
16
+
17
+ #if AT_MKLDNN_ENABLED()
18
+
19
+ namespace mkldnn {
20
+
21
+ const static std::map<std::string, std::vector<torch::jit::MatchFilter>>
22
+ fusion_rewrite_map = {
23
+ {"none", {}},
24
+ {"relu", {}},
25
+ };
26
+
27
+ } // namespace mkldnn
28
+
29
+ #endif // AT_MKLDNN_ENABLED()
30
+
31
+ void FuseConvWithEltwise(std::shared_ptr<Graph>& graph);
32
+
33
+ } // namespace jit
34
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/normalize_ops.h ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/ir/ir.h>
4
+
5
+ namespace torch {
6
+ namespace jit {
7
+
8
+ // This pass converts aten ops to a normalized form. It is
9
+ // run immediately after IR generation in both the tracer and compiler,
10
+ // so downstream consumers of the IR do not need handle ops in their
11
+ // pre-normalized form.
12
+ // Currently only handles normalization of op aliases.
13
+ TORCH_API void NormalizeOps(const std::shared_ptr<Graph>& graph);
14
+
15
+ const std::unordered_map<Symbol, Symbol>& getOperatorAliasMap();
16
+
17
+ } // namespace jit
18
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/pass_manager.h ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/ir/ir.h>
4
+
5
+ /* `getCustomPrePasses()` returns a vector of passes that will be executed
6
+ * after differentiation but before any fusion. This is the de-facto location
7
+ * for compiler backends to insert passes.
8
+ *
9
+ * `getCustomPostPasses()` returns a vector of passes that will be
10
+ * executed after differentiation and after fusion (if any). This is the
11
+ * location for fusion cleanup passes if they are needed.
12
+ *
13
+ * Static registration of a pass can be done by creating a global
14
+ * `Register{Pre,Post}Pass r(Pass)` variable in a compilation unit.
15
+ *
16
+ * pass_manager.h uses a Meyer's singleton to store a vector of `Pass`es, which
17
+ * modify the IR graph in place.
18
+ */
19
+
20
+ namespace torch {
21
+ namespace jit {
22
+
23
+ // A pass modifies a Graph in place.
24
+ using GraphPass = std::function<void(std::shared_ptr<Graph>&)>;
25
+
26
+ // Since Passes are std::functions, we associate a UUID to each pass, this way
27
+ // if we want to deregister a pass, we have something to reference it by.
28
+ using GraphPassNameType = unsigned int;
29
+
30
+ // Graph pass entries have a name associated with them
31
+ using GraphPassEntry = std::pair<GraphPass, GraphPassNameType>;
32
+
33
+ // Return currently registered passes. Passes are stored in a static vector
34
+ TORCH_API std::vector<std::pair<GraphPass, GraphPassNameType>>&
35
+ getCustomPostPasses();
36
+ TORCH_API std::vector<std::pair<GraphPass, GraphPassNameType>>&
37
+ getCustomPrePasses();
38
+
39
+ TORCH_API GraphPassNameType registerPostPass(GraphPass p);
40
+ TORCH_API GraphPassNameType registerPrePass(GraphPass p);
41
+
42
+ // Look up pass by name passed in, remove it from registered passes
43
+ TORCH_API void clearPostPass(GraphPassNameType p);
44
+ TORCH_API void clearPrePass(GraphPassNameType p);
45
+
46
+ // Remove all passes
47
+ TORCH_API void clearAllPostPasses();
48
+ TORCH_API void clearAllPrePasses();
49
+
50
+ // LEGACY CALL
51
+ struct TORCH_API RegisterPostPass {
52
+ RegisterPostPass(GraphPass p);
53
+ };
54
+
55
+ using RegisterPass = RegisterPostPass;
56
+
57
+ /*
58
+ * PassManager is a wrapper on the register/clear PostPass functions above. It
59
+ * will register the pass provided in "registerPass" and will hold on to its
60
+ * associated name that way clearPass can be later called and will delete the
61
+ * pass used to register when called.
62
+ *
63
+ * PassManager is templated because we want static variables based on a
64
+ * particular GraphPass. When deriving from PassManager, you should send as the
65
+ * template parameter your derived class as you would for the curiously
66
+ * recurring template pattern. This template parameter isn't actually used and
67
+ * is simply done to prevent static members from being shared across derived
68
+ * types.
69
+ */
70
+ template <typename DerivedType>
71
+ struct C10_EXPORT PassManager {
72
+ private:
73
+ // We want this class to be abstract because it's
74
+ virtual void abstract() = 0;
75
+
76
+ protected:
77
+ /*
78
+ * isRegistered() will return if a pass has been registered
79
+ * isRegistered(true) will change the value of the internal static bool
80
+ *
81
+ * There's an internal static bool to this function to keep track of the
82
+ * state, this is so when functions are derived from this class, they don't
83
+ * have to worry about initializing the static members.
84
+ */
85
+ static bool isRegistered(bool flip_bit = false) {
86
+ static bool val = false;
87
+ if (flip_bit)
88
+ val = !val;
89
+ return val;
90
+ }
91
+
92
+ /*
93
+ * name() will return the name of the registered pass
94
+ * name(pass_name, true) will set the name of the pass
95
+ * Similarly to isRegistered we use an internal static variable to hold the
96
+ * name.
97
+ */
98
+ static GraphPassNameType passID(
99
+ GraphPassNameType PassID = 0,
100
+ bool set = false) {
101
+ static GraphPassNameType pass_id = 0;
102
+ if (set)
103
+ pass_id = PassID;
104
+ return pass_id;
105
+ }
106
+
107
+ public:
108
+ // registerPass(pass) will register the pass provided and set the
109
+ // name/isRegistered functions appropriately, it returns a bool value
110
+ // indicating whether the given pass is already registered previously.
111
+ static bool registerPass(GraphPass p) {
112
+ if (!isRegistered()) {
113
+ // If we don't already have a registered pass, register pass
114
+ // hold on to its name, change isRegistered to true
115
+ passID(registerPostPass(std::move(p)), true);
116
+ isRegistered(true);
117
+ return false;
118
+ }
119
+ return true;
120
+ }
121
+
122
+ // Calls ClearPostPass(passID())
123
+ static void clearPass() {
124
+ // If the pass is registered, clear it and change isRegistered to false.
125
+ if (isRegistered()) {
126
+ clearPostPass(passID());
127
+ isRegistered(true);
128
+ }
129
+ }
130
+
131
+ // clang-tidy requires virtual destructor;
132
+ virtual ~PassManager() = default;
133
+ };
134
+
135
+ } // namespace jit
136
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/refine_tuple_types.h ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/ir/ir.h>
4
+
5
+ namespace torch {
6
+ namespace jit {
7
+
8
+ // updates the types of tuples according to the type of their current inputs.
9
+ TORCH_API void RefineTupleTypes(std::shared_ptr<Graph>& graph);
10
+
11
+ } // namespace jit
12
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/remove_expands.h ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/ir/ir.h>
4
+
5
+ namespace torch {
6
+ namespace jit {
7
+
8
+ TORCH_API void RemoveExpands(const std::shared_ptr<Graph>& graph);
9
+
10
+ }
11
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/replacement_of_old_operators.h ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/ir/ir.h>
4
+
5
+ namespace torch {
6
+ namespace jit {
7
+
8
+ // Find the valid upgrader graph for the upgrader and cache the result
9
+ // for later lookups. Will error out if there is no valid upgrader graph
10
+ // provided for the upgrader name.
11
+ std::shared_ptr<Graph> getUpgraderGraph(const std::string& upgrader_name);
12
+
13
+ TORCH_API void ReplaceOldOperatorsWithUpgraders(std::shared_ptr<Graph> graph);
14
+
15
+ } // namespace jit
16
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/passes/variadic_ops.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/ir/ir.h>
4
+
5
+ namespace torch {
6
+ namespace jit {
7
+
8
+ // Try to replace an op that takes a list input with another op that takes a
9
+ // variadic number of arguments.
10
+ TORCH_API bool UseVariadicOp(
11
+ const std::shared_ptr<Graph>& graph,
12
+ NodeKind op,
13
+ NodeKind variadic_op);
14
+
15
+ TORCH_API bool RemoveListMutationAndUseVariadicOp(
16
+ const std::shared_ptr<Graph>& graph,
17
+ NodeKind op,
18
+ NodeKind variadic_op);
19
+
20
+ // Convenient functions for replacing aten::stack/aten::cat with their
21
+ // variadic versions.
22
+ TORCH_API bool UseVariadicCat(const std::shared_ptr<Graph>& graph);
23
+ TORCH_API bool RemoveListMutationAndUseVariadicCat(
24
+ const std::shared_ptr<Graph>& graph);
25
+
26
+ TORCH_API bool UseVariadicStack(const std::shared_ptr<Graph>& graph);
27
+ TORCH_API bool RemoveListMutationAndUseVariadicStack(
28
+ const std::shared_ptr<Graph>& graph);
29
+
30
+ } // namespace jit
31
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/resource_guard.h ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #include <functional>
3
+
4
+ namespace torch {
5
+ namespace jit {
6
+
7
+ class ResourceGuard {
8
+ std::function<void()> _destructor;
9
+ bool _released;
10
+
11
+ public:
12
+ ResourceGuard(std::function<void()> destructor)
13
+ : _destructor(std::move(destructor)), _released(false) {}
14
+
15
+ // NOLINTNEXTLINE(bugprone-exception-escape)
16
+ ~ResourceGuard() {
17
+ if (!_released)
18
+ _destructor();
19
+ }
20
+
21
+ void release() {
22
+ _released = true;
23
+ }
24
+ };
25
+
26
+ } // namespace jit
27
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/export.h ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <caffe2/serialize/inline_container.h>
4
+ #include <torch/csrc/jit/api/module.h>
5
+ #include <torch/csrc/jit/ir/ir.h>
6
+ #include <torch/csrc/jit/serialization/export_bytecode.h>
7
+ #include <torch/csrc/jit/serialization/flatbuffer_serializer.h>
8
+ #include <torch/csrc/jit/serialization/pickler.h>
9
+ #include <torch/csrc/jit/serialization/python_print.h>
10
+ #include <torch/csrc/jit/serialization/storage_context.h>
11
+ #include <torch/csrc/jit/serialization/type_name_uniquer.h>
12
+ #include <torch/csrc/onnx/onnx.h>
13
+ #include <ostream>
14
+
15
+ namespace ONNX_NAMESPACE {
16
+ class ModelProto;
17
+ }
18
+
19
+ namespace torch {
20
+ namespace jit {
21
+
22
+ // This map is used to keep track of parameters that should be exported
23
+ // externally. When `defer_weight_export` is true, the returned map contains
24
+ // kv pairs that map {external reference name} -> {at::Tensor to be exported}.
25
+ // It is the responsibility of the caller to export these appropriately.
26
+ //
27
+ // For example, when exporting to a zip archive, the caller may write out files
28
+ // for each entry in the export map, with the filename being the key and the
29
+ // file contents being the raw tensor data.
30
+ using RawDataExportMap = std::unordered_map<std::string, at::Tensor>;
31
+
32
+ using SymbolDimMap = std::map<c10::ShapeSymbol, std::string>;
33
+
34
+ using NodeNameMap = std::unordered_map<const Node*, std::string>;
35
+
36
+ // Used for modularized export settling function and node attributes.
37
+ using NodeAttrNameMap = std::
38
+ unordered_map<const Node*, std::unordered_map<std::string, std::string>>;
39
+
40
+ TORCH_API std::tuple<
41
+ std::shared_ptr<::ONNX_NAMESPACE::ModelProto>,
42
+ RawDataExportMap,
43
+ SymbolDimMap,
44
+ bool,
45
+ NodeNameMap>
46
+ export_onnx(
47
+ const std::shared_ptr<Graph>& graph,
48
+ const std::map<std::string, at::Tensor>& initializers,
49
+ int64_t onnx_opset_version,
50
+ const std::unordered_map<
51
+ std::string,
52
+ std::unordered_map<int64_t, std::string>>& dynamic_axes,
53
+ bool defer_weight_export = false,
54
+ ::torch::onnx::OperatorExportTypes operator_export_type =
55
+ ::torch::onnx::OperatorExportTypes::ONNX,
56
+ bool strip_doc_string = true,
57
+ bool keep_initializers_as_inputs = true,
58
+ const std::map<std::string, int>& custom_opsets = {},
59
+ bool add_node_names = true,
60
+ bool use_external_data_format = false,
61
+ const std::string& onnx_file_path = std::string(),
62
+ const NodeAttrNameMap& node_attr_to_name = {});
63
+
64
+ TORCH_API std::string serialize_model_proto_to_string(
65
+ const std::shared_ptr<::ONNX_NAMESPACE::ModelProto>& model_proto);
66
+
67
+ TORCH_API void check_onnx_proto(const std::string& proto_string);
68
+
69
+ // Serializer for both oldsyle and unified format TorchScript serialization
70
+ class TORCH_API ScriptModuleSerializer {
71
+ public:
72
+ explicit ScriptModuleSerializer(
73
+ caffe2::serialize::PyTorchStreamWriter& export_writer)
74
+ : writer_(export_writer), current_source_range_tag_(0) {}
75
+
76
+ void writeFiles(const std::string& code_dir);
77
+ void serialize(
78
+ const Module& module,
79
+ const ExtraFilesMap& extra_files,
80
+ bool bytecode_format,
81
+ bool save_mobile_debug_info);
82
+ void serialize_unified_format(Module& module, uint64_t script_module_id);
83
+ SerializationStorageContext& storage_context();
84
+
85
+ ~ScriptModuleSerializer() = default;
86
+
87
+ private:
88
+ void convertNamedType(const c10::NamedTypePtr& class_type);
89
+ void convertTypes(const at::NamedTypePtr& root_type);
90
+ void writeExtraFiles(const Module& module, const ExtraFilesMap& extra_files);
91
+ void writeByteCode(const Module& module, bool save_mobile_debug_info);
92
+ void writeArchive(
93
+ const IValue& value,
94
+ const std::string& archive_name,
95
+ const std::string& archive_dir,
96
+ const std::string& tensor_dir,
97
+ bool use_storage_context = false,
98
+ bool skip_tensor_data = false);
99
+ void updateSourceRangeTags(const SourceRangeRecords& ranges);
100
+
101
+ caffe2::serialize::PyTorchStreamWriter& writer_;
102
+ std::vector<at::IValue> constant_table_;
103
+
104
+ std::unordered_set<c10::NamedTypePtr> converted_types_;
105
+ PrintDepsTable class_deps_;
106
+ TypeNameUniquer type_name_uniquer_;
107
+ // qualifier, e.g. '__torch__.Bar' -> PythonPrint for the file that will be
108
+ // created
109
+ OrderedDict<std::string, PythonPrint> file_streams_;
110
+ // Used to keep references of storages around during serialization to solve
111
+ // for ABA memory reuse problem hit when storages are created/destroyed
112
+ // during serialization process. Also used to coordinate sharing of storages
113
+ // between Script and eager modules in torch.package.
114
+ SerializationStorageContext storage_context_;
115
+
116
+ // Uniquely identifies a SourceRange in a model.
117
+ // SourceRanges are associated with Nodes of Graphs.
118
+ // However for mobile deployment we dont intend to ship
119
+ // full JIT with capabilities of reading code and constructing
120
+ // graphs.
121
+ // Instead we serialize the Code generated from graph of the methods.
122
+ // Code is serialized in bytecode format that contains instructions
123
+ // corresponding to the nodes of the graph. Since original graph is gone, the
124
+ // question is how do we identify where the ops, in serialized bytecode, come
125
+ // from in original model code. We do this in two parts.
126
+ // 1. Associate a unique tag to SourceRange.
127
+ // 2. Serialize this unique_tag.
128
+ // 2.1 Meaning save <byte_offset, source_range_tag, source range> instead of
129
+ // <byte_offset, source range>
130
+ // 3. During serializing model for mobile, i.e. bytecode generation,
131
+ // save unique tag of SourceRange corresponding to the Node.
132
+ // 4. During deserialization, read all the debug_pkl, to construct a map
133
+ // of <unique_tag, SourceRange> and use tag saved with OPs in bytecode
134
+ // to lookup the source range.
135
+ // Strictly speaking we will serialize InlinedCallStack directly, which
136
+ // contains SourceRange. This way we have access to entire callstack and not
137
+ // just source information about where the node is, since bytecode inlines the
138
+ // graph before saving it.
139
+ SourceRangeTagMap source_range_tags_;
140
+ int64_t current_source_range_tag_;
141
+ };
142
+
143
+ // For testing purposes
144
+ TORCH_API std::string pretty_print_onnx(
145
+ const std::shared_ptr<Graph>& graph,
146
+ const std::map<std::string, at::Tensor>& initializers,
147
+ int64_t onnx_opset_version,
148
+ bool defer_weight_export,
149
+ ::torch::onnx::OperatorExportTypes operator_export_type =
150
+ ::torch::onnx::OperatorExportTypes::ONNX,
151
+ bool google_printer = false,
152
+ bool keep_initializers_as_inputs = true,
153
+ const std::map<std::string, int>& custom_opsets = {},
154
+ bool add_node_names = true);
155
+
156
+ TORCH_API void ExportModule(
157
+ const Module& module,
158
+ std::ostream& out,
159
+ const ExtraFilesMap& metadata = ExtraFilesMap(),
160
+ bool bytecode_format = false,
161
+ bool save_mobile_debug_info = false,
162
+ bool use_flatbuffer = false);
163
+
164
+ TORCH_API void ExportModule(
165
+ const Module& module,
166
+ const std::string& filename,
167
+ const ExtraFilesMap& metadata = ExtraFilesMap(),
168
+ bool bytecode_format = false,
169
+ bool save_mobile_debug_info = false,
170
+ bool use_flatbuffer = false);
171
+
172
+ TORCH_API void ExportModule(
173
+ const Module& module,
174
+ const std::function<size_t(const void*, size_t)>& writer_func,
175
+ const ExtraFilesMap& metadata = ExtraFilesMap(),
176
+ bool bytecode_format = false,
177
+ bool save_mobile_debug_info = false,
178
+ bool use_flatbuffer = false);
179
+
180
+ // Write the bytes of a pickle archive and the tensors referenced inside that
181
+ // archive
182
+ TORCH_API void writeArchiveAndTensors(
183
+ const std::string& archive_name,
184
+ const char* pickle_bytes,
185
+ size_t size,
186
+ const std::vector<at::Tensor>& tensors,
187
+ caffe2::serialize::PyTorchStreamWriter& out);
188
+
189
+ // Surrounding system can install an additional hook to produce extra files
190
+ // with metadata based on environment every time a module is serialized.
191
+ using ExportModuleExtraFilesHook = std::function<ExtraFilesMap(const Module&)>;
192
+ TORCH_API void SetExportModuleExtraFilesHook(ExportModuleExtraFilesHook hook);
193
+
194
+ /**
195
+ * Generates new bytecode for a Script module and returns what the op list
196
+ * would be for a LiteScriptModule based off the current code base. If you
197
+ * have a LiteScriptModule and want to get the currently present
198
+ * list of ops call _export_operator_list instead.
199
+ */
200
+ TORCH_API std::vector<std::string> export_opnames(const Module& m);
201
+
202
+ struct TORCH_API BytecodeEmitMode {
203
+ static bool is_default_value_for_unspecified_arg_enabled();
204
+ static void set_default_value_for_unspecified_arg_enabled(bool enabled);
205
+
206
+ static bool is_default_args_before_out_args_enabled();
207
+ static void set_default_args_before_out_args_enabled(bool enabled);
208
+
209
+ static bool is_emit_promoted_ops_enabled();
210
+ static void set_default_emit_promoted_ops_enabled(bool enabled);
211
+ };
212
+
213
+ // RAII guard to switch the way JIT emits the bytecode for inputs.
214
+ // default_value_for_unspecified_arg:
215
+ // true: instruction of default argument values (like LOADC) is emitted.
216
+ // false: instruction of default argument values are not emitted. Instead
217
+ // they are fetched from operator schema.
218
+ // default_args_before_out_args (to forward compatibile support
219
+ // operators allowing out arguments and default arguments):
220
+ // true: the number of specified arguments will deserialized to (#all_args -
221
+ // #default_args). false: the number of specified arguments will deserialized to
222
+ // (#all_args).
223
+ struct TORCH_API BytecodeEmitModeGuard {
224
+ BytecodeEmitModeGuard(
225
+ bool enable_default_value_for_unspecified_arg,
226
+ bool enable_default_args_before_out_args,
227
+ bool enable_emit_promoted_ops)
228
+ : prev_default_value_for_unspecified_arg_mode(
229
+ BytecodeEmitMode::is_default_value_for_unspecified_arg_enabled()),
230
+ prev_default_args_before_out_args(
231
+ BytecodeEmitMode::is_default_args_before_out_args_enabled()),
232
+ prev_default_emit_promoted_ops(
233
+ BytecodeEmitMode::is_emit_promoted_ops_enabled()) {
234
+ BytecodeEmitMode::set_default_value_for_unspecified_arg_enabled(
235
+ enable_default_value_for_unspecified_arg);
236
+ BytecodeEmitMode::set_default_args_before_out_args_enabled(
237
+ enable_default_args_before_out_args);
238
+ BytecodeEmitMode::set_default_emit_promoted_ops_enabled(
239
+ enable_emit_promoted_ops);
240
+ }
241
+ ~BytecodeEmitModeGuard() {
242
+ BytecodeEmitMode::set_default_value_for_unspecified_arg_enabled(
243
+ prev_default_value_for_unspecified_arg_mode);
244
+ BytecodeEmitMode::set_default_args_before_out_args_enabled(
245
+ prev_default_args_before_out_args);
246
+ BytecodeEmitMode::set_default_emit_promoted_ops_enabled(
247
+ prev_default_emit_promoted_ops);
248
+ }
249
+ bool prev_default_value_for_unspecified_arg_mode;
250
+ bool prev_default_args_before_out_args;
251
+ bool prev_default_emit_promoted_ops;
252
+ };
253
+
254
+ TORCH_API IValue to_tuple(std::vector<IValue> ivalues);
255
+ TORCH_API IValue
256
+ Table(const std::vector<std::pair<std::string, IValue>>& entries);
257
+
258
+ // TODO remove these switches once interface call is rolled out.
259
+ TORCH_API void enableMobileInterfaceCallExport();
260
+ bool getMobileInterfaceCallExport();
261
+
262
+ TORCH_API CompilationOptions getOptionsFromGlobal();
263
+
264
+ TORCH_API void save_jit_module(
265
+ const Module& module,
266
+ const std::string& filename,
267
+ const ExtraFilesMap& extra_files = ExtraFilesMap());
268
+
269
+ TORCH_API DetachedBuffer::UniqueDetachedBuffer save_jit_module_to_bytes(
270
+ const Module& module,
271
+ const ExtraFilesMap& extra_files = ExtraFilesMap());
272
+
273
+ TORCH_API void save_jit_module_to_write_func(
274
+ const Module& module,
275
+ const ExtraFilesMap& extra_files,
276
+ bool save_mobile_debug_info,
277
+ const std::function<size_t(const void*, size_t)>& writer_func);
278
+
279
+ } // namespace jit
280
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/export_bytecode.h ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <tuple>
4
+ #include <unordered_map>
5
+
6
+ #include <ATen/core/function_schema.h>
7
+ #include <ATen/core/ivalue.h>
8
+ #include <ATen/core/jit_type.h>
9
+ #include <ATen/core/qualified_name.h>
10
+ #include <torch/csrc/jit/backends/backend_debug_handler.h>
11
+ #include <torch/csrc/jit/mobile/function.h>
12
+ #include <torch/csrc/jit/mobile/module.h>
13
+ #include <torch/csrc/jit/runtime/interpreter.h>
14
+ #include <torch/csrc/jit/serialization/type_name_uniquer.h>
15
+
16
+ namespace torch {
17
+ namespace jit {
18
+
19
+ struct TORCH_API CompilationOptions {
20
+ bool incl_interface_call = false;
21
+ bool enable_default_value_for_unspecified_arg = false;
22
+ bool enable_default_args_before_out_args = true;
23
+ bool enable_emit_promoted_ops = true;
24
+ int model_version = caffe2::serialize::kProducedBytecodeVersion;
25
+ };
26
+
27
+ TORCH_API mobile::Module jitModuleToMobile(
28
+ const Module& module,
29
+ const CompilationOptions& options);
30
+
31
+ mobile::Code compileGraphToMobileCode(
32
+ const std::string& name,
33
+ const std::shared_ptr<Graph>& graph,
34
+ const CompilationOptions& compilation_options,
35
+ BackendDebugInfoRecorder& debug_info_recorder);
36
+
37
+ TORCH_API std::unique_ptr<mobile::Function> convertJitFunctionToMobileFunction(
38
+ const GraphFunction& function,
39
+ const CompilationOptions& options);
40
+
41
+ TORCH_API IValue convertMobileFunctionToCodeTable(
42
+ const mobile::Function& func,
43
+ const CompilationOptions& compilation_options);
44
+
45
+ } // namespace jit
46
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/flatbuffer_serializer.h ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <functional>
4
+ #include <memory>
5
+ #include <string>
6
+ #include <unordered_map>
7
+ #include <vector>
8
+
9
+ #include <ATen/core/ivalue.h>
10
+ #include <c10/macros/Macros.h>
11
+ #include <torch/csrc/jit/mobile/module.h>
12
+
13
+ /**
14
+ * Defines the public API for serializing mobile modules to flatbuffer.
15
+ * Note that this header must not include or depend on flatbuffer-defined
16
+ * types, to avoid leaking those details to PyTorch clients.
17
+ */
18
+
19
+ namespace torch {
20
+ namespace jit {
21
+
22
+ /// Maps file names to file contents.
23
+ using ExtraFilesMap = std::unordered_map<std::string, std::string>;
24
+
25
+ /**
26
+ * Represents a span of data. Typically owned by a UniqueDetachedBuffer.
27
+ */
28
+ class TORCH_API DetachedBuffer final {
29
+ public:
30
+ /// Creates a new DetachedBuffer with an optional data owner. This interface
31
+ /// is provided to let users create objects of this type for testing.
32
+ DetachedBuffer(void* data, size_t size, void* internal_data_owner = nullptr)
33
+ : data_(data), size_(size), data_owner_(internal_data_owner) {}
34
+
35
+ /// Returns a pointer to the data.
36
+ C10_NODISCARD void* data() {
37
+ return data_;
38
+ }
39
+ /// Returns a pointer to the data.
40
+ C10_NODISCARD const void* data() const {
41
+ return data_;
42
+ }
43
+ /// Returns the size of the data, in bytes.
44
+ C10_NODISCARD size_t size() const {
45
+ return size_;
46
+ }
47
+
48
+ /// Wrapper type that typically owns data_owner_.
49
+ using UniqueDetachedBuffer =
50
+ std::unique_ptr<DetachedBuffer, std::function<void(DetachedBuffer*)>>;
51
+
52
+ private:
53
+ /// Deletes the owner, if present, and the buf itself.
54
+ /// Note: we could have provided a movable type with a destructor that did
55
+ /// this work, but the unique wrapper was easier in practice.
56
+ static void destroy(DetachedBuffer* buf);
57
+
58
+ /// Provides access to destroy() for implementation and testing.
59
+ friend struct DetachedBufferFriend;
60
+ friend struct DetachedBufferTestingFriend;
61
+
62
+ /// Pointer to the data. Not owned by this class.
63
+ void* data_;
64
+ /// The size of `data_`, in bytes.
65
+ size_t size_;
66
+ /// Opaque pointer to the underlying owner of `data_`. This class
67
+ /// (DetachedBuffer) does not own the owner or the data. It will typically be
68
+ /// owned by a UniqueDetachedBuffer that knows how to delete the owner along
69
+ /// with this class.
70
+ void* data_owner_;
71
+ };
72
+
73
+ TORCH_API void save_mobile_module(
74
+ const mobile::Module& module,
75
+ const std::string& filename,
76
+ const ExtraFilesMap& extra_files = ExtraFilesMap(),
77
+ const ExtraFilesMap& jit_sources = ExtraFilesMap(),
78
+ const std::vector<IValue>& jit_constants = {});
79
+
80
+ TORCH_API DetachedBuffer::UniqueDetachedBuffer save_mobile_module_to_bytes(
81
+ const mobile::Module& module,
82
+ const ExtraFilesMap& extra_files = ExtraFilesMap(),
83
+ const ExtraFilesMap& jit_sources = ExtraFilesMap(),
84
+ const std::vector<IValue>& jit_constants = {});
85
+
86
+ TORCH_API void save_mobile_module_to_func(
87
+ const mobile::Module& module,
88
+ const std::function<size_t(const void*, size_t)>& writer_func);
89
+
90
+ // TODO(qihan): delete
91
+ TORCH_API bool register_flatbuffer_serializer();
92
+
93
+ } // namespace jit
94
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/flatbuffer_serializer_jit.h ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/serialization/flatbuffer_serializer.h>
4
+
5
+ namespace torch {
6
+ namespace jit {
7
+
8
+ TORCH_API bool register_flatbuffer_all();
9
+
10
+ } // namespace jit
11
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import.h ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/core/ivalue.h>
4
+ #include <caffe2/serialize/inline_container.h>
5
+ #include <torch/csrc/jit/api/module.h>
6
+ #include <torch/csrc/jit/ir/ir.h>
7
+
8
+ #include <istream>
9
+
10
+ namespace caffe2 {
11
+ namespace serialize {
12
+ class ReadAdapterInterface;
13
+ } // namespace serialize
14
+ } // namespace caffe2
15
+
16
+ namespace torch {
17
+ namespace jit {
18
+
19
+ class DeserializationStorageContext;
20
+
21
+ TORCH_API Module import_ir_module(
22
+ std::shared_ptr<CompilationUnit> cu,
23
+ const std::string& filename,
24
+ c10::optional<c10::Device> device = c10::nullopt,
25
+ bool load_debug_files = true);
26
+
27
+ TORCH_API Module import_ir_module(
28
+ std::shared_ptr<CompilationUnit> cu,
29
+ std::istream& in,
30
+ c10::optional<c10::Device> device = c10::nullopt,
31
+ bool load_debug_files = true);
32
+
33
+ TORCH_API Module import_ir_module(
34
+ std::shared_ptr<CompilationUnit> cu,
35
+ std::unique_ptr<caffe2::serialize::ReadAdapterInterface> rai,
36
+ c10::optional<c10::Device> device = c10::nullopt,
37
+ bool load_debug_files = true);
38
+
39
+ TORCH_API Module import_ir_module(
40
+ std::shared_ptr<CompilationUnit> cu,
41
+ const std::string& filename,
42
+ c10::optional<c10::Device> device,
43
+ ExtraFilesMap& extra_files,
44
+ bool load_debug_files = true,
45
+ bool restore_shapes = false);
46
+
47
+ // For reading unified serialization format from torch.Package
48
+ TORCH_API Module import_ir_module(
49
+ std::shared_ptr<CompilationUnit> cu,
50
+ std::shared_ptr<caffe2::serialize::PyTorchStreamReader> reader,
51
+ std::shared_ptr<torch::jit::DeserializationStorageContext> storage_context,
52
+ c10::optional<at::Device> device,
53
+ std::string ts_id /* torchscript identifier inside package */);
54
+
55
+ TORCH_API Module import_ir_module(
56
+ std::shared_ptr<CompilationUnit> cu,
57
+ std::istream& in,
58
+ c10::optional<c10::Device> device,
59
+ ExtraFilesMap& extra_files,
60
+ bool load_debug_files = true,
61
+ bool restore_shapes = false);
62
+
63
+ TORCH_API Module import_ir_module(
64
+ std::shared_ptr<CompilationUnit> cu,
65
+ std::unique_ptr<caffe2::serialize::ReadAdapterInterface> rai,
66
+ c10::optional<c10::Device> device,
67
+ ExtraFilesMap& extra_files,
68
+ bool load_debug_files = true);
69
+
70
+ TORCH_API Module import_ir_module(
71
+ std::shared_ptr<CompilationUnit> cu,
72
+ std::shared_ptr<caffe2::serialize::ReadAdapterInterface> rai,
73
+ c10::optional<c10::Device> device,
74
+ ExtraFilesMap& extra_files,
75
+ bool load_debug_files = true);
76
+
77
+ /// Loads a serialized `Module` from the given `istream`.
78
+ ///
79
+ /// The istream must contain a serialized `Module`, exported via
80
+ /// `torch::jit::ExportModule` in C++.
81
+ TORCH_API Module load(
82
+ std::istream& in,
83
+ c10::optional<c10::Device> device = c10::nullopt,
84
+ bool load_debug_files = true);
85
+
86
+ TORCH_API Module load(
87
+ std::istream& in,
88
+ c10::optional<c10::Device> device,
89
+ ExtraFilesMap& extra_files,
90
+ bool load_debug_files = true);
91
+
92
+ /// Loads a serialized `Module` from the given `filename`.
93
+ ///
94
+ /// The file stored at the location given in `filename` must contain a
95
+ /// serialized `Module`, exported either via `ScriptModule.save()` in
96
+ /// Python or `torch::jit::ExportModule` in C++.
97
+ TORCH_API Module load(
98
+ const std::string& filename,
99
+ c10::optional<c10::Device> device = c10::nullopt,
100
+ bool load_debug_files = true);
101
+
102
+ TORCH_API Module load(
103
+ const std::string& filename,
104
+ c10::optional<c10::Device> device,
105
+ ExtraFilesMap& extra_files,
106
+ bool load_debug_files = true);
107
+
108
+ /// Loads a serialized `Module` from the given shared_ptr `rai`.
109
+ ///
110
+ /// The reader adapter, which is for customized input stream, must contain a
111
+ /// serialized `Module`, exported either via `ScriptModule.save()` in
112
+ /// Python or `torch::jit::ExportModule` in C++.
113
+ TORCH_API Module load(
114
+ std::shared_ptr<caffe2::serialize::ReadAdapterInterface> rai,
115
+ c10::optional<c10::Device> device = c10::nullopt,
116
+ bool load_debug_files = true);
117
+
118
+ TORCH_API Module load(
119
+ std::shared_ptr<caffe2::serialize::ReadAdapterInterface> rai,
120
+ c10::optional<c10::Device> device,
121
+ ExtraFilesMap& extra_files,
122
+ bool load_debug_files = true);
123
+
124
+ TORCH_API Module jitModuleFromSourceAndConstants(
125
+ const IValue& ivalue,
126
+ const ExtraFilesMap& source,
127
+ const std::vector<IValue>& constants,
128
+ int32_t version);
129
+
130
+ TORCH_API Module parse_and_initialize_jit_module(
131
+ std::shared_ptr<char> data,
132
+ size_t size,
133
+ ExtraFilesMap& extra_files,
134
+ c10::optional<at::Device> device = c10::nullopt);
135
+
136
+ TORCH_API Module load_jit_module_from_file(
137
+ const std::string& filename,
138
+ ExtraFilesMap& extra_files,
139
+ c10::optional<at::Device> device = c10::nullopt);
140
+
141
+ TORCH_API Module load_jit_module_from_stream(
142
+ std::istream& in,
143
+ ExtraFilesMap& extra_files,
144
+ c10::optional<at::Device> device = c10::nullopt);
145
+
146
+ TORCH_API Module parse_and_initialize_jit_module(
147
+ std::shared_ptr<char> data,
148
+ size_t size,
149
+ ExtraFilesMap& extra_files,
150
+ c10::optional<at::Device> device);
151
+
152
+ TORCH_API c10::intrusive_ptr<c10::ivalue::Object> ObjLoaderFunc(
153
+ const at::StrongTypePtr& type,
154
+ IValue input);
155
+
156
+ } // namespace jit
157
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_export_constants.h ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #include <cstddef>
3
+
4
+ namespace torch {
5
+ namespace jit {
6
+ constexpr size_t BYTECODE_INDEX_INSTRUCTION = 0;
7
+ constexpr size_t BYTECODE_INDEX_OPERATOR = 1;
8
+ constexpr size_t BYTECODE_INDEX_CONSTANT = 2;
9
+ constexpr size_t BYTECODE_INDEX_TYPE = 3;
10
+ constexpr size_t BYTECODE_INDEX_REGISTER_SIZE = 4;
11
+
12
+ constexpr size_t BYTECODE_INDEX_SCHEMA_ARGUMENTS = 0;
13
+ constexpr size_t BYTECODE_INDEX_SCHEMA_RETURNS = 1;
14
+
15
+ constexpr size_t BYTECODE_INDEX_ARGUMENT_NAME = 0;
16
+ constexpr size_t BYTECODE_INDEX_ARGUMENT_TYPE = 1;
17
+ constexpr size_t BYTECODE_INDEX_ARGUMENT_DEFAULT_VALUE = 2;
18
+
19
+ constexpr size_t BYTECODE_INDEX_MODULE_DEBUG_HANDLES = 0;
20
+ } // namespace jit
21
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_export_functions.h ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #include <ATen/core/ivalue.h>
3
+
4
+ // Functions that are used in both import and export processes
5
+ namespace torch {
6
+ namespace jit {
7
+ using c10::IValue;
8
+ IValue expect_field(
9
+ c10::ivalue::TupleElements& elements,
10
+ const std::string& expected_name,
11
+ size_t entry);
12
+ std::string operator_str(
13
+ const std::string& name,
14
+ const std::string& overloadname);
15
+ } // namespace jit
16
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_export_helpers.h ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ namespace caffe2 {
7
+ namespace serialize {
8
+ class PyTorchStreamReader;
9
+ }
10
+ } // namespace caffe2
11
+
12
+ namespace torch {
13
+ namespace jit {
14
+
15
+ struct Source;
16
+
17
+ // Convert a class type's qualifier name to the corresponding path the source
18
+ // file it should be written to.
19
+ //
20
+ // Qualifier is like: foo.bar.baz
21
+ // Returns: libs/foo/bar/baz.py
22
+ std::string qualifierToArchivePath(
23
+ const std::string& qualifier,
24
+ const std::string& export_prefix);
25
+
26
+ std::shared_ptr<Source> findSourceInArchiveFromQualifier(
27
+ caffe2::serialize::PyTorchStreamReader& reader,
28
+ const std::string& export_prefix,
29
+ const std::string& qualifier);
30
+
31
+ } // namespace jit
32
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_legacy.h ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/api/module.h>
4
+
5
+ namespace caffe2 {
6
+ namespace serialize {
7
+ class PyTorchStreamReader;
8
+ } // namespace serialize
9
+ } // namespace caffe2
10
+
11
+ namespace torch {
12
+ namespace jit {
13
+
14
+ struct CompilationUnit;
15
+
16
+ // Deserializes a model in legacy format.
17
+ Module LEGACY_deserialize(
18
+ std::shared_ptr<CompilationUnit> cu,
19
+ std::shared_ptr<caffe2::serialize::PyTorchStreamReader> reader,
20
+ const c10::optional<c10::Device>& device);
21
+
22
+ } // namespace jit
23
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_read.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/serialization/unpickler.h>
4
+ #include <memory>
5
+
6
+ namespace caffe2 {
7
+ namespace serialize {
8
+ class PyTorchStreamReader;
9
+ } // namespace serialize
10
+ } // namespace caffe2
11
+
12
+ namespace torch {
13
+ namespace jit {
14
+
15
+ TORCH_API IValue readArchiveAndTensors(
16
+ const std::string& archive_name,
17
+ const std::string& pickle_prefix,
18
+ const std::string& tensor_prefix,
19
+ c10::optional<TypeResolver> type_resolver,
20
+ c10::optional<ObjLoader> obj_loader,
21
+ c10::optional<at::Device> device,
22
+ caffe2::serialize::PyTorchStreamReader& stream_reader,
23
+ c10::TypePtr (*type_parser)(const std::string&) =
24
+ Unpickler::defaultTypeParser,
25
+ std::shared_ptr<DeserializationStorageContext> storage_context = nullptr);
26
+
27
+ bool check_zip_file(
28
+ std::shared_ptr<caffe2::serialize::ReadAdapterInterface> rai);
29
+
30
+ } // namespace jit
31
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/import_source.h ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/core/ivalue_inl.h>
4
+ #include <ATen/core/qualified_name.h>
5
+ #include <c10/util/Optional.h>
6
+ #include <torch/csrc/jit/api/module.h>
7
+ #include <torch/csrc/jit/frontend/parser.h>
8
+ #include <torch/csrc/jit/frontend/resolver.h>
9
+ #include <torch/csrc/jit/frontend/script_type_parser.h>
10
+ #include <torch/csrc/jit/frontend/source_range.h>
11
+ #include <torch/csrc/jit/ir/ir.h>
12
+ #include <torch/csrc/jit/serialization/export.h>
13
+ #include <torch/custom_class.h>
14
+ #include <functional>
15
+ #include <memory>
16
+ #include <regex>
17
+ #include <string>
18
+ #include <vector>
19
+
20
+ namespace torch {
21
+ namespace jit {
22
+
23
+ using SourceLoader = std::function<std::shared_ptr<Source>(const std::string&)>;
24
+
25
+ struct SourceImporterImpl : public Resolver,
26
+ std::enable_shared_from_this<SourceImporterImpl> {
27
+ SourceImporterImpl(
28
+ std::shared_ptr<CompilationUnit> cu,
29
+ const std::vector<at::IValue>* constant_table,
30
+ SourceLoader source_loader,
31
+ size_t version);
32
+ TypePtr findNamedType(const QualifiedName& name);
33
+ Function* findFunction(const QualifiedName& name);
34
+ void parseSourceIfNeeded(const std::string& qualifier);
35
+ void LEGACY_import_methods(
36
+ const Module& mod,
37
+ const std::shared_ptr<Source>& src);
38
+
39
+ std::shared_ptr<SugaredValue> resolveValue(
40
+ const std::string& name,
41
+ GraphFunction& m,
42
+ const SourceRange& loc) override;
43
+ TypePtr resolveType(const std::string& name, const SourceRange& loc) override;
44
+
45
+ private:
46
+ void importFunction(const std::string& qualifier, const Def& def);
47
+ void importNamedType(const std::string& qualifier, const ClassDef& class_def);
48
+ c10::optional<Assign> attributeAssignmentSpecialHandlingHack(
49
+ const QualifiedName& qualified_classname,
50
+ const Assign& assign);
51
+ void importClass(
52
+ const QualifiedName& qualified_classname,
53
+ const ClassDef& class_def,
54
+ bool is_module);
55
+ void importEnum(
56
+ const QualifiedName& qualified_name,
57
+ const ClassDef& enum_def);
58
+ void importNamedTuple(
59
+ const QualifiedName& qualified_name,
60
+ const ClassDef& named_tuple_def);
61
+
62
+ void parsePossibleVersionNumber(Lexer& L);
63
+
64
+ void parseImports(Lexer& L);
65
+
66
+ std::shared_ptr<CompilationUnit> cu_;
67
+ std::unordered_map<std::string, std::shared_ptr<SugaredValue>> env_;
68
+ SourceLoader source_loader_;
69
+ c10::optional<size_t> version_ = c10::nullopt;
70
+ std::unordered_set<std::string> loaded_sources_;
71
+ // named types and functions loaded from a file but not yet defined because
72
+ // their type has not been requested yet.
73
+ std::unordered_map<QualifiedName, TreeRef> to_be_defined_;
74
+ };
75
+
76
+ // Given a directory of serialized TorchScript sources,
77
+ // This class allows the loading of individual named types in source.
78
+ // Resolves the dependencies between source files and parses
79
+ // the source files as necessary.
80
+
81
+ struct TORCH_API SourceImporter {
82
+ SourceImporter(
83
+ // The compilation unit that will own the imported source
84
+ std::shared_ptr<CompilationUnit> cu,
85
+ const std::vector<at::IValue>* constant_table,
86
+ SourceLoader loader,
87
+ size_t version);
88
+
89
+ TypePtr loadType(const QualifiedName& name) const;
90
+
91
+ // Add the methods defined in `src` to the module `mod`, using SourceImporter
92
+ // to resolve any classes via loadType
93
+ void LEGACY_import_methods(
94
+ const Module& mod,
95
+ const std::shared_ptr<Source>& src);
96
+ ~SourceImporter();
97
+
98
+ private:
99
+ std::shared_ptr<SourceImporterImpl> pImpl;
100
+ };
101
+
102
+ } // namespace jit
103
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/mobile_bytecode_generated.h ADDED
The diff for this file is too large to render. See raw diff
 
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/onnx.h ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <onnx/onnx_pb.h>
4
+ #include <torch/csrc/jit/ir/ir.h>
5
+
6
+ namespace torch {
7
+ namespace jit {
8
+
9
+ TORCH_API std::string prettyPrint(const ::ONNX_NAMESPACE::ModelProto& model);
10
+
11
+ } // namespace jit
12
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/pickle.h ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/core/ivalue.h>
4
+ #include <c10/util/ArrayRef.h>
5
+ #include <caffe2/serialize/inline_container.h>
6
+ #include <torch/csrc/Export.h>
7
+ #include <torch/csrc/jit/serialization/pickler.h>
8
+ #include <torch/csrc/jit/serialization/unpickler.h>
9
+
10
+ namespace torch {
11
+ namespace jit {
12
+
13
+ /// Pickle an IValue by calling a function to handle writing the data.
14
+ ///
15
+ /// `writer` is a function that takes in a pointer to a chunk of memory and its
16
+ /// size and consumes it.
17
+ ///
18
+ /// See `jit::pickle` for more details.
19
+ TORCH_API void pickle(
20
+ std::function<void(const char* data_start, size_t data_len)> writer,
21
+ const IValue& ivalue,
22
+ std::vector<at::Tensor>* tensor_table = nullptr);
23
+
24
+ /// Save a `torch::IValue` in a format compatible with Python's `pickle` module
25
+ ///
26
+ /// If present, `tensor_table` is a pointer to a table in which tensors that
27
+ /// are contained within `ivalue` are stored, and the bytes returned by the
28
+ /// pickler will only include references to these tensors in the table. This can
29
+ /// be used to keep the binary blob size small.
30
+ /// If not provided, tensors are stored in the same byte stream as the pickle
31
+ /// data, similar to `torch.save()` in eager Python.
32
+ ///
33
+ /// Pickled values can be loaded in Python and C++:
34
+ /// \rst
35
+ /// .. code-block:: cpp
36
+ ///
37
+ /// torch::IValue float_value(2.3);
38
+ ///
39
+ /// // TODO: when tensors are stored in the pickle, delete this
40
+ /// std::vector<at::Tensor> tensor_table;
41
+ /// auto data = torch::jit::pickle(float_value, &tensor_table);
42
+ ///
43
+ /// std::vector<torch::IValue> ivalues =
44
+ /// torch::jit::unpickle(data.data(), data.size());
45
+ ///
46
+ /// .. code-block:: python
47
+ ///
48
+ /// values = torch.load('data.pkl')
49
+ /// print(values)
50
+ ///
51
+ /// \endrst
52
+ TORCH_API std::vector<char> pickle(
53
+ const IValue& ivalue,
54
+ std::vector<at::Tensor>* tensor_table = nullptr);
55
+
56
+ /// Save a `torch::IValue` in a format that can be loaded by both
57
+ /// `torch::pickle_load` in C++ and `torch.load` in Python.
58
+ TORCH_API std::vector<char> pickle_save(const IValue& ivalue);
59
+
60
+ /// Deserialize a `torch::IValue` from bytes produced by either
61
+ /// `torch::pickle_save` in C++ or `torch.save` in Python
62
+ TORCH_API IValue pickle_load(const std::vector<char>& data);
63
+
64
+ /// `reader` is a function that takes in a size to read from some pickled
65
+ /// binary. `reader` should remember where it last read, and return
66
+ /// the number of bytes read.
67
+ /// See `torch::pickle` for details.
68
+ /// type_resolver is used to resolve any JIT type based on type str
69
+ TORCH_API IValue unpickle(
70
+ std::function<size_t(char*, size_t)> reader,
71
+ TypeResolver type_resolver,
72
+ c10::ArrayRef<at::Tensor> tensor_table,
73
+ c10::TypePtr (*type_parser)(const std::string&) =
74
+ Unpickler::defaultTypeParser,
75
+ ObjLoader obj_loader = nullptr);
76
+
77
+ /// Decode a chunk of memory containing pickled data into its `torch::IValue`s.
78
+ ///
79
+ /// If any `torch::IValue`s in the pickled data are `Object`s, then a
80
+ /// `class_resolver` function must be provided.
81
+ ///
82
+ /// See `torch::pickle` for details.
83
+ TORCH_API IValue unpickle(
84
+ const char* data,
85
+ size_t size,
86
+ TypeResolver type_resolver = nullptr,
87
+ c10::ArrayRef<at::Tensor> tensor_table = {},
88
+ c10::TypePtr (*type_parser)(const std::string&) =
89
+ Unpickler::defaultTypeParser);
90
+
91
+ /// Decode a chunk of memory containing pickled data into its `torch::IValue`s.
92
+ ///
93
+ /// If any `torch::IValue`s in the pickled data are `Object`s, then a
94
+ /// `class_resolver` function must be provided.
95
+ ///
96
+ /// See `torch::pickle` for details.
97
+ TORCH_API IValue unpickle(
98
+ const char* data,
99
+ size_t size,
100
+ ObjLoader obj_loader,
101
+ TypeResolver type_resolver = nullptr,
102
+ c10::ArrayRef<at::Tensor> tensor_table = {},
103
+ c10::TypePtr (*type_parser)(const std::string&) =
104
+ Unpickler::defaultTypeParser);
105
+
106
+ } // namespace jit
107
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/pickler.h ADDED
@@ -0,0 +1,429 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/core/qualified_name.h>
4
+ #include <string>
5
+ #include <utility>
6
+ #include <vector>
7
+
8
+ #include <ATen/Utils.h>
9
+ #include <ATen/core/ivalue.h>
10
+ #include <ATen/core/jit_type.h>
11
+ #include <c10/util/ArrayRef.h>
12
+ #include <c10/util/FbcodeMaps.h>
13
+ #include <c10/util/intrusive_ptr.h>
14
+ #include <c10/util/string_view.h>
15
+ #include <torch/csrc/Export.h>
16
+
17
+ namespace torch {
18
+ namespace jit {
19
+
20
+ // See Python's pickletools.py for a detailed description of each of these codes
21
+ enum class PickleOpCode : char {
22
+ MARK = '(',
23
+ STOP = '.',
24
+ POP = '0',
25
+ POP_MARK = '1',
26
+ DUP = '2',
27
+ FLOAT = 'F',
28
+ INT = 'I',
29
+ BININT = 'J',
30
+ BININT1 = 'K',
31
+ LONG = 'L',
32
+ BININT2 = 'M',
33
+ NONE = 'N',
34
+ PERSID = 'P',
35
+ BINPERSID = 'Q',
36
+ REDUCE = 'R',
37
+ STRING = 'S',
38
+ BINSTRING = 'T',
39
+ SHORT_BINSTRING = 'U',
40
+ // NB: Avoid using UNICODE as it is a macro in the Windows API
41
+ UNICODE_ = 'V',
42
+ BINUNICODE = 'X',
43
+ APPEND = 'a',
44
+ BUILD = 'b',
45
+ GLOBAL = 'c',
46
+ DICT = 'd',
47
+ EMPTY_DICT = '}',
48
+ APPENDS = 'e',
49
+ GET = 'g',
50
+ BINGET = 'h',
51
+ INST = 'i',
52
+ LONG_BINGET = 'j',
53
+ LIST = 'l',
54
+ EMPTY_LIST = ']',
55
+ OBJ = 'o',
56
+ PUT = 'p',
57
+ BINPUT = 'q',
58
+ LONG_BINPUT = 'r',
59
+ SETITEM = 's',
60
+ TUPLE = 't',
61
+ EMPTY_TUPLE = ')',
62
+ SETITEMS = 'u',
63
+ BINFLOAT = 'G',
64
+
65
+ // Protocol 2
66
+ PROTO = char('\x80'),
67
+ NEWOBJ = '\x81',
68
+ EXT1 = '\x82',
69
+ EXT2 = '\x83',
70
+ EXT4 = '\x84',
71
+ TUPLE1 = '\x85',
72
+ TUPLE2 = '\x86',
73
+ TUPLE3 = '\x87',
74
+ NEWTRUE = '\x88',
75
+ NEWFALSE = '\x89',
76
+ LONG1 = '\x8a',
77
+ LONG4 = '\x8b',
78
+
79
+ // Protocol 3 (Python 3.x)
80
+ BINBYTES = 'B',
81
+ SHORT_BINBYTES = 'C',
82
+
83
+ // Protocol 4
84
+ SHORT_BINUNICODE = char('\x8c'),
85
+ BINUNICODE8 = '\x8d',
86
+ BINBYTES8 = '\x8e',
87
+ EMPTY_SET = '\x8f',
88
+ ADDITEMS = '\x90',
89
+ FROZENSET = '\x91',
90
+ NEWOBJ_EX = '\x92',
91
+ STACK_GLOBAL = '\x93',
92
+ MEMOIZE = '\x94',
93
+ FRAME = '\x95'
94
+ };
95
+
96
+ using ::c10::IValue;
97
+
98
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
99
+ struct WriteableTensorData {
100
+ const char* data() const {
101
+ return static_cast<const char*>(tensor_.storage().data());
102
+ }
103
+ size_t sizeInBytes() const {
104
+ return size_;
105
+ }
106
+ size_t nbytes() const {
107
+ return tensor_.storage().nbytes();
108
+ }
109
+ bool storageHasDeleter() const {
110
+ return tensor_.storage().data_ptr().get_context() != nullptr;
111
+ }
112
+
113
+ private:
114
+ friend TORCH_API WriteableTensorData
115
+ getWriteableTensorData(const at::Tensor& tensor, bool to_cpu);
116
+ at::Tensor tensor_;
117
+ uint64_t size_;
118
+ };
119
+
120
+ void setTypeTags(bool state);
121
+ bool getTypeTags();
122
+
123
+ class TORCH_API Pickler {
124
+ AT_DISALLOW_COPY_AND_ASSIGN(Pickler);
125
+
126
+ public:
127
+ Pickler(std::function<void(const char*, size_t)> writer)
128
+ : Pickler(std::move(writer), nullptr, nullptr, nullptr) {}
129
+
130
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
131
+ Pickler(
132
+ std::function<void(const char*, size_t)> writer,
133
+ std::vector<at::Tensor>* tensor_table,
134
+ std::function<c10::QualifiedName(const c10::ClassTypePtr&)> type_renamer,
135
+ std::vector<c10::ClassTypePtr>* memoized_class_types,
136
+ std::function<std::string(const at::Tensor&)> get_tensor_id = nullptr,
137
+ bool tag_aggregates = true)
138
+ : writer_(std::move(writer)),
139
+ tensor_table_(tensor_table),
140
+ type_renamer_(std::move(type_renamer)),
141
+ memoized_class_types_(memoized_class_types),
142
+ get_tensor_id_(std::move(get_tensor_id)),
143
+ tag_aggregates_(tag_aggregates) {}
144
+ // NOLINTNEXTLINE(bugprone-exception-escape)
145
+ ~Pickler();
146
+
147
+ // Push protocol onto the stack
148
+ void protocol();
149
+
150
+ // Push STOP PickleOpCode onto the stack
151
+ void stop();
152
+
153
+ void pushIValue(const IValue& ivalue);
154
+
155
+ void startTuple();
156
+ void endTuple();
157
+
158
+ const std::vector<at::Tensor>& tensorData() {
159
+ return tensor_data_;
160
+ }
161
+
162
+ void pushEmptyDict();
163
+ void pushDict(const IValue& ivalue);
164
+ void pushInt(int64_t value);
165
+ void pushLong(const std::string& data);
166
+
167
+ private:
168
+ void pushIValueImpl(const IValue& ivalue);
169
+ void startTypeTag();
170
+ void endTypeTag(const IValue& value);
171
+ void pushBool(bool value);
172
+ void pushDouble(double value);
173
+ void pushComplexDouble(const IValue& value);
174
+ void pushGenericList(const IValue& ivalue);
175
+ void pushIntList(const IValue& ivalue);
176
+ void pushList(const IValue& ivalue);
177
+ void pushTensor(const IValue& ivalue);
178
+ void pushTensorReference(const IValue& ivalue);
179
+ void pushLiteralTensor(const IValue& ivalue);
180
+ void pushLiteralSparseTensor(const at::Tensor& tensor);
181
+ void pushTuple(const IValue& ivalue);
182
+ void pushString(const std::string& string);
183
+ void pushDevice(const IValue& ivalue);
184
+ #ifdef USE_DISTRIBUTED
185
+ void pushRRef(const IValue& ivalue);
186
+ #endif
187
+ // unmemoized version
188
+ void pushStringImpl(const std::string& string);
189
+ void pushStorageOfTensor(const at::Tensor& tensor);
190
+
191
+ void pushBinGet(uint32_t memo_id);
192
+ void pushSpecializedList(
193
+ const IValue& ivalue,
194
+ const char* list_name,
195
+ const std::function<void(const IValue&)>& item_pusher);
196
+ void pushGlobal(c10::string_view module_name, c10::string_view class_name);
197
+ // raw string data is appended directly to the byte stream
198
+ void pushBytes(const std::string& string);
199
+ void pushTensorData(const at::Tensor& tensor);
200
+
201
+ // Add a BINPUT op and return the memoization id used
202
+ size_t pushNextBinPut();
203
+
204
+ const void* getPointer(const IValue& ivalue);
205
+
206
+ // Caller checks that bufferPos_ > 0
207
+ void flushNonEmpty() {
208
+ writer_(buffer_.data(), bufferPos_);
209
+ bufferPos_ = 0;
210
+ }
211
+
212
+ void flush() {
213
+ if (bufferPos_ != 0) {
214
+ flushNonEmpty();
215
+ }
216
+ }
217
+
218
+ // These convert values to bytes and add them to the stack (NB: since T is to
219
+ // the left of a '::', its type cannot be deduced by the compiler so one must
220
+ // explicitly instantiate the template, i.e. push<int>(int) works, push(int)
221
+ // does not)
222
+ static CONSTEXPR_EXCEPT_WIN_CUDA size_t kBufferSize = 256;
223
+ template <typename T>
224
+ void push(typename std::common_type<T>::type value) {
225
+ const char* begin = reinterpret_cast<const char*>(&value);
226
+ if (bufferPos_ + sizeof(T) > buffer_.size()) {
227
+ flushNonEmpty();
228
+ }
229
+ static_assert(sizeof(T) <= kBufferSize, "Buffer size assumption");
230
+ memcpy(buffer_.data() + bufferPos_, begin, sizeof(T));
231
+ bufferPos_ += sizeof(T);
232
+ }
233
+
234
+ // Stream to write binary data to
235
+ // Code shouldn't call writer_ directly without first flush()ing.
236
+ std::function<void(const char*, size_t)> writer_;
237
+
238
+ // Buffer to avoid calling a writer_ on a per-byte basis.
239
+ std::array<char, kBufferSize> buffer_;
240
+ size_t bufferPos_{0};
241
+
242
+ // Stack of opcodes/data
243
+ std::vector<char> stack_;
244
+
245
+ // External table of tensors to serialize. If this is missing, then tensors
246
+ // are serialized directly into the pickle
247
+ std::vector<at::Tensor>* tensor_table_;
248
+
249
+ // TODO: only use this if necessary (add a pass to find all shared ivalues,
250
+ // and only memoize those)
251
+ uint32_t memo_id_ = 0;
252
+
253
+ // Memoization of IValues that have been written (index in table is used for
254
+ // BINPUT opcodes) to enable shared references
255
+ c10::FastMap<const void*, uint32_t> memoized_ivalue_map_;
256
+
257
+ // because we de-dup ivalues based on their raw pointer address in the above
258
+ // map we need to keep all the memoized values alive during the pickle.
259
+ // Otherwise, it is possible that a raw address gets reused for another
260
+ // object, and we will alias it to the old object at that address.
261
+ std::vector<IValue> memoized_ivalues_;
262
+
263
+ std::function<c10::QualifiedName(const c10::ClassTypePtr&)> type_renamer_;
264
+
265
+ // List of all the types that it wrote, inspect from the IValues it wrote.
266
+ std::vector<c10::ClassTypePtr>* memoized_class_types_;
267
+
268
+ // Function to grab next id_name for tensor storage, function is responsible
269
+ // for returning unique ids
270
+ std::function<std::string(const at::Tensor&)> get_tensor_id_;
271
+
272
+ // List of tensor storages to serialize in the same binary as the pickle data
273
+ // similar to ivalues, they are memoized using BINPUT
274
+ std::vector<at::Tensor> tensor_data_;
275
+ c10::FastMap<const void*, uint32_t> memoized_storage_map_;
276
+
277
+ c10::FastMap<std::string, uint32_t> memoized_globals_map_;
278
+ c10::FastMap<std::string, uint32_t> memoized_strings_map_;
279
+ c10::FastMap<std::string, uint32_t> memoized_devices_map_;
280
+ // when true, List and Dict objects will be wrapped in a
281
+ // torch.jit._pickle.restore_type_tag call to correctly set the dynamic
282
+ // TorchScript type for the object. When true the thing unpickling must have
283
+ // torch installed.
284
+ bool tag_aggregates_;
285
+ };
286
+
287
+ // returns a (tensor, record_size) for a tensor, converting it to a CPU tensor
288
+ // if it was CUDA and to_cpu is True.
289
+ TORCH_API WriteableTensorData
290
+ getWriteableTensorData(const at::Tensor& tensor, bool to_cpu = true);
291
+
292
+ // return the value of the tensor's storage pointer
293
+ uint64_t getStorageKey(const at::Tensor& tensor);
294
+
295
+ // if the cls has __getstate__/__setstate__
296
+ // assert they have the right schema and return true,
297
+ // otherwise return false
298
+ bool checkHasValidSetGetState(const std::shared_ptr<c10::ClassType>& cls);
299
+
300
+ // Declare BackendMeta serialization and deserialization function pointer types.
301
+ using BackendMetaPtr = std::function<
302
+ void(const at::Tensor&, std::unordered_map<std::string, bool>&)>;
303
+
304
+ // A allowlist of device type, currently available is PrivateUse1
305
+ inline std::unordered_set<c10::DeviceType>& GetBackendMetaAllowlist() {
306
+ static std::unordered_set<c10::DeviceType> DeviceTypeAllowlist{
307
+ c10::DeviceType::PrivateUse1};
308
+ return DeviceTypeAllowlist;
309
+ }
310
+
311
+ // Dynamically obtain serialization function pairs
312
+ // that require the corresponding backend.
313
+ inline std::array<
314
+ c10::optional<std::pair<BackendMetaPtr, BackendMetaPtr>>,
315
+ at::COMPILE_TIME_MAX_DEVICE_TYPES>&
316
+ GetBackendMetaSerialization() {
317
+ // The array to save function pointer for BackendMeta serialization.
318
+ // key is the DeviceType, value is std::pair obj.
319
+ // value.first represent get function and value.seconde represent set function
320
+ static std::array<
321
+ c10::optional<std::pair<BackendMetaPtr, BackendMetaPtr>>,
322
+ at::COMPILE_TIME_MAX_DEVICE_TYPES>
323
+ BackendMetaSerialization;
324
+ return BackendMetaSerialization;
325
+ }
326
+
327
+ // Register function pointer of Tensor BackendMetadata for serialization.
328
+ TORCH_API inline void TensorBackendMetaRegistry(
329
+ c10::DeviceType t,
330
+ const BackendMetaPtr& get_fptr,
331
+ const BackendMetaPtr& set_fptr) {
332
+ // allowlist verification
333
+ // Only if the devicetype is in the allowlist,
334
+ // we allow the serialization extension to be registered for backendmeta data.
335
+ const auto& DeviceTypeAllowlist = GetBackendMetaAllowlist();
336
+ TORCH_CHECK(
337
+ DeviceTypeAllowlist.find(t) != DeviceTypeAllowlist.end(),
338
+ "It is not allowed to register the serialization method ",
339
+ "of backendMeta data for PrivateUse1. ",
340
+ "If you have related serialization requirements, ",
341
+ "please expand the allowlist");
342
+ // Register function pointer
343
+ int device_type = static_cast<int>(t);
344
+ auto& BackendMetaSerialization = GetBackendMetaSerialization();
345
+ TORCH_CHECK(
346
+ !BackendMetaSerialization[device_type].has_value(),
347
+ "The tensor BackendMeta serialization function pointer for ",
348
+ t,
349
+ " has been registered.");
350
+ BackendMetaSerialization[device_type] =
351
+ c10::optional<std::pair<BackendMetaPtr, BackendMetaPtr>>(
352
+ std::make_pair(get_fptr, set_fptr));
353
+ }
354
+
355
+ // Return a map of Tensor Metadata which including BackendMetaData for
356
+ // serialization. For now, it only takes care of `conj` and `neg` bit.
357
+ inline std::unordered_map<std::string, bool> getTensorMetadata(
358
+ const at::Tensor& t) {
359
+ // We don't support serializing `ZeroTensor` as it is not public
360
+ // facing yet.
361
+ TORCH_CHECK(
362
+ !t._is_zerotensor(),
363
+ "ZeroTensor is not serializable,",
364
+ " please file an issue if required.");
365
+ std::unordered_map<std::string, bool> metadata{};
366
+
367
+ // Only add meta-data if the value is not default.
368
+ if (t.is_conj()) {
369
+ metadata["conj"] = true;
370
+ }
371
+ if (t.is_neg()) {
372
+ metadata["neg"] = true;
373
+ }
374
+ // Only add BackendMetaData for custom backend if the function pointer is
375
+ // registered.
376
+ int device_type = static_cast<int>(t.device().type());
377
+ const auto& BackendMetaSerialization = GetBackendMetaSerialization();
378
+ if (BackendMetaSerialization[device_type].has_value()) {
379
+ // Pass the tensor and metadata map references as parameters to the custom
380
+ // serialization function.
381
+ BackendMetaPtr fptr = BackendMetaSerialization[device_type].value().first;
382
+ fptr(t, metadata);
383
+ }
384
+ return metadata;
385
+ }
386
+
387
+ // set Tensor Metadata based on the map.
388
+ // Refer: getTensorMetadata
389
+ inline void setTensorMetadata(
390
+ const at::Tensor& t,
391
+ std::unordered_map<std::string, bool> metadata) {
392
+ auto iter_end = metadata.end();
393
+ auto iter_temp = metadata.find("conj");
394
+ if (iter_temp != iter_end) {
395
+ t._set_conj(true);
396
+ metadata.erase(iter_temp);
397
+ }
398
+ iter_temp = metadata.find("neg");
399
+ if (iter_temp != iter_end) {
400
+ t._set_neg(true);
401
+ metadata.erase(iter_temp);
402
+ }
403
+ // Only set BackendMetaData for custom backend if the function pointer is
404
+ // registered.
405
+ int device_type = static_cast<int>(t.device().type());
406
+ const auto& BackendMetaSerialization = GetBackendMetaSerialization();
407
+ if (BackendMetaSerialization[device_type].has_value()) {
408
+ // Pass the tensor and metadata map references as parameters to the custom
409
+ // deserialization function.
410
+ BackendMetaPtr fptr = BackendMetaSerialization[device_type].value().second;
411
+ fptr(t, metadata);
412
+ }
413
+ }
414
+
415
+ // set Tensor metadata based on the map.
416
+ // NOTE: This overload is required by unpickler.cpp
417
+ inline void setTensorMetadata(
418
+ const at::Tensor& t,
419
+ const c10::Dict<c10::IValue, c10::IValue>& metadata_idict) {
420
+ std::unordered_map<std::string, bool> metadata;
421
+ for (auto& pair : metadata_idict) {
422
+ auto key = *pair.key().toString();
423
+ metadata[key] = pair.value().toBool();
424
+ }
425
+ setTensorMetadata(t, std::move(metadata));
426
+ }
427
+
428
+ } // namespace jit
429
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/python_print.h ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #include <torch/csrc/Export.h>
3
+ #include <torch/csrc/jit/api/module.h>
4
+ #include <torch/csrc/jit/ir/ir.h>
5
+ #include <vector>
6
+
7
+ namespace torch {
8
+ namespace jit {
9
+
10
+ struct Method;
11
+ struct Module;
12
+ struct PythonPrintImpl;
13
+
14
+ struct PrintDepsTable {
15
+ void add(const c10::NamedTypePtr& type);
16
+
17
+ size_t size() const {
18
+ return table_.size();
19
+ }
20
+
21
+ const c10::NamedTypePtr& operator[](size_t index) const {
22
+ return table_[index];
23
+ }
24
+
25
+ private:
26
+ std::vector<c10::NamedTypePtr> table_;
27
+ std::unordered_set<c10::NamedTypePtr> non_unique_;
28
+ };
29
+
30
+ struct TORCH_API PythonPrint {
31
+ PythonPrint(
32
+ std::vector<IValue>& constant_table,
33
+ PrintDepsTable& deps_table,
34
+ c10::TypePrinter type_printer = nullptr,
35
+ bool enforce_importable = false);
36
+
37
+ void printNamedType(const c10::NamedTypePtr& classType);
38
+ void printFunction(const Function& callee);
39
+ void printMethod(const Function& callee);
40
+
41
+ std::string str() const;
42
+ const SourceRangeRecords& ranges() const;
43
+ uint64_t minVersion() const;
44
+
45
+ private:
46
+ std::shared_ptr<PythonPrintImpl> pImpl;
47
+ };
48
+
49
+ TORCH_API bool printerHasSpecialCaseFor(c10::Symbol sym);
50
+
51
+ TORCH_API void jitModuleToPythonCodeAndConstants(
52
+ const Module& module,
53
+ ExtraFilesMap* jit_sources, // output
54
+ std::vector<IValue>* constants // output
55
+ );
56
+
57
+ } // namespace jit
58
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/source_range_serialization.h ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <c10/core/Allocator.h>
4
+ #include <torch/csrc/jit/frontend/source_range.h>
5
+
6
+ #include <ATen/core/ivalue.h>
7
+
8
+ #include <unordered_map>
9
+ #include <vector>
10
+
11
+ namespace c10 {
12
+ struct IValue;
13
+ }
14
+
15
+ namespace torch {
16
+ namespace jit {
17
+
18
+ class Pickler;
19
+ class SourceRangeSerializer;
20
+ static constexpr size_t kByteOffsetIndex = 0;
21
+ static constexpr size_t kSourceRangeIndex = 1;
22
+ static constexpr size_t kSourceRangeTagIndex = 2;
23
+ constexpr c10::string_view kFormatWithStringTable = "FORMAT_WITH_STRING_TABLE";
24
+
25
+ class SourceRangePickler {
26
+ public:
27
+ SourceRangePickler();
28
+
29
+ std::vector<char> pickle(
30
+ const SourceRangeRecords& ranges,
31
+ const SourceRangeTagMap& source_range_tags);
32
+
33
+ private:
34
+ std::shared_ptr<SourceRangeSerializer> srs;
35
+ };
36
+
37
+ class SourceRangeDeserializer {
38
+ public:
39
+ SourceRangeDeserializer() = default;
40
+ explicit SourceRangeDeserializer(const c10::IValue& text_table) {
41
+ for (const auto& x : text_table.toTuple()->elements()) {
42
+ text_table_.emplace_back(std::make_shared<std::string>(x.toStringRef()));
43
+ }
44
+ }
45
+ SourceRange deserialize(const c10::IValue& iv);
46
+
47
+ private:
48
+ std::shared_ptr<Source> deserialize_source(const c10::IValue& iv);
49
+ std::unordered_map<
50
+ c10::intrusive_ptr<c10::ivalue::Tuple>,
51
+ std::shared_ptr<Source>>
52
+ cached_sources;
53
+ std::vector<std::shared_ptr<std::string>> text_table_;
54
+ };
55
+
56
+ class SourceRangeUnpickler {
57
+ public:
58
+ virtual c10::optional<SourceRange> findSourceRangeThatGenerated(
59
+ const SourceRange& range) = 0;
60
+
61
+ virtual ~SourceRangeUnpickler() = default;
62
+ };
63
+
64
+ TORCH_API void setShouldUseFormatWithStringTable(
65
+ bool should_use_format_with_string_table);
66
+
67
+ } // namespace jit
68
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/storage_context.h ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/core/ivalue.h>
4
+
5
+ namespace torch {
6
+ namespace jit {
7
+
8
+ // Used in torch.package and TorchScript serialization to coordinate
9
+ // sharing of storages between models. Also used to create deterministic
10
+ // naming for storages.
11
+ class TORCH_API SerializationStorageContext {
12
+ public:
13
+ explicit SerializationStorageContext() = default;
14
+ SerializationStorageContext operator=(const SerializationStorageContext&) =
15
+ delete;
16
+ SerializationStorageContext(const SerializationStorageContext&) = delete;
17
+
18
+ uint64_t getOrAddStorage(const c10::Storage& storage) {
19
+ if (!hasStorage(storage)) {
20
+ uint64_t size = storage_id_map_.size();
21
+ storage_id_map_[storage] = size;
22
+ }
23
+ return storage_id_map_[storage];
24
+ }
25
+
26
+ bool hasStorage(const c10::Storage& storage) {
27
+ return storage_id_map_.find(storage) != storage_id_map_.end();
28
+ }
29
+
30
+ ~SerializationStorageContext() = default;
31
+
32
+ private:
33
+ class StorageSerializationHash {
34
+ public:
35
+ size_t operator()(const c10::Storage& storage) const {
36
+ return std::hash<void*>()(
37
+ reinterpret_cast<void*>(storage.unsafeGetStorageImpl()));
38
+ }
39
+ };
40
+
41
+ class StorageSerializationEqual {
42
+ public:
43
+ bool operator()(const c10::Storage& lhs, const c10::Storage& rhs) const {
44
+ return lhs.unsafeGetStorageImpl() == rhs.unsafeGetStorageImpl();
45
+ }
46
+ };
47
+
48
+ std::unordered_map<
49
+ c10::Storage,
50
+ uint64_t,
51
+ StorageSerializationHash,
52
+ StorageSerializationEqual>
53
+ storage_id_map_;
54
+ };
55
+
56
+ // Used in torch.package and TorchScript deserialization to coordinate
57
+ // sharing of storages between models.
58
+ class TORCH_API DeserializationStorageContext {
59
+ public:
60
+ explicit DeserializationStorageContext() = default;
61
+ DeserializationStorageContext operator=(
62
+ const DeserializationStorageContext&) = delete;
63
+ DeserializationStorageContext(const DeserializationStorageContext&) = delete;
64
+
65
+ void addStorage(std::string name, c10::Storage storage) {
66
+ TORCH_INTERNAL_ASSERT(!hasStorage(name));
67
+ name_storage_map_.emplace(std::move(name), std::move(storage));
68
+ }
69
+
70
+ bool hasStorage(const std::string& name) {
71
+ return name_storage_map_.find(name) != name_storage_map_.end();
72
+ }
73
+
74
+ c10::Storage getStorage(const std::string& name) {
75
+ TORCH_INTERNAL_ASSERT(hasStorage(name));
76
+ return name_storage_map_.find(name)->second;
77
+ }
78
+ ~DeserializationStorageContext() = default;
79
+
80
+ private:
81
+ std::unordered_map<std::string, c10::Storage> name_storage_map_;
82
+ };
83
+
84
+ } // namespace jit
85
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/type_name_uniquer.h ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/jit/frontend/name_mangler.h>
4
+ #include <torch/csrc/jit/ir/type_hashing.h>
5
+
6
+ namespace torch {
7
+ namespace jit {
8
+
9
+ /**
10
+ * class TypeNameUniquer
11
+ *
12
+ * Generates a unique name for every type `t` passed in. Types that compare
13
+ * equal with EqualType will receive the same unique name.
14
+ *
15
+ * This is used during Module::save(), to resolve type name collisions during
16
+ * serialization.
17
+ */
18
+ class TORCH_API TypeNameUniquer {
19
+ public:
20
+ c10::QualifiedName getUniqueName(c10::ConstNamedTypePtr t);
21
+
22
+ private:
23
+ NameMangler mangler_;
24
+ std::unordered_set<c10::QualifiedName> used_names_;
25
+ std::unordered_map<
26
+ c10::ConstNamedTypePtr,
27
+ c10::QualifiedName,
28
+ HashType,
29
+ EqualType>
30
+ name_map_;
31
+ };
32
+ } // namespace jit
33
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/jit/serialization/unpickler.h ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/core/ivalue.h>
4
+ #include <c10/util/ArrayRef.h>
5
+ #include <caffe2/serialize/inline_container.h>
6
+ #include <torch/csrc/Export.h>
7
+ #include <torch/csrc/jit/frontend/script_type_parser.h>
8
+ #include <torch/csrc/jit/serialization/pickler.h>
9
+
10
+ namespace torch {
11
+ namespace jit {
12
+
13
+ using TypeResolver =
14
+ std::function<c10::StrongTypePtr(const c10::QualifiedName&)>;
15
+
16
+ using ObjLoader = std::function<
17
+ c10::intrusive_ptr<c10::ivalue::Object>(const at::StrongTypePtr&, IValue)>;
18
+
19
+ class DeserializationStorageContext;
20
+
21
+ // [unpickler refactor] there is some cruft around PickleOpCode::BUILD,
22
+ // PickleOpCode::NEWOBJ, and the last_opcode_ member below that should be
23
+ // deleted at some point, the Pickler doesn't produce it and it's only around to
24
+ // support models saved before 1.1
25
+ class TORCH_API Unpickler {
26
+ AT_DISALLOW_COPY_AND_ASSIGN(Unpickler);
27
+
28
+ using TypeParserT = c10::TypePtr (*)(const std::string&);
29
+
30
+ public:
31
+ // tensors inside the pickle are references to the tensor_table.
32
+ // class_resolver is to resolve strong class type, type_resolver_ is
33
+ // to resolve any JIT type. class_resolver and type_resolver are not merged
34
+ // here because some use cases need to get strong class type that
35
+ // type_resolver_ can not return.
36
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
37
+ Unpickler(
38
+ std::function<size_t(char*, size_t)> reader,
39
+ TypeResolver type_resolver,
40
+ c10::ArrayRef<at::Tensor> tensor_table,
41
+ TypeParserT type_parser = defaultTypeParser)
42
+ : reader_(std::move(reader)),
43
+ tensor_table_(tensor_table),
44
+ type_resolver_(std::move(type_resolver)),
45
+ use_storage_device_(false),
46
+ type_parser_(type_parser),
47
+ version_(caffe2::serialize::kProducedFileFormatVersion) {}
48
+
49
+ Unpickler(
50
+ std::function<size_t(char*, size_t)> reader,
51
+ TypeResolver type_resolver,
52
+ c10::ArrayRef<at::Tensor> tensor_table,
53
+ ObjLoader obj_loader,
54
+ TypeParserT type_parser = defaultTypeParser)
55
+ : reader_(std::move(reader)),
56
+ tensor_table_(tensor_table),
57
+ type_resolver_(std::move(type_resolver)),
58
+ obj_loader_(std::move(obj_loader)),
59
+ use_storage_device_(false),
60
+ type_parser_(type_parser),
61
+ version_(caffe2::serialize::kProducedFileFormatVersion) {}
62
+
63
+ // tensors inside the pickle contain meta-data, the raw tensor
64
+ // dead is retrieved by calling `read_record`.
65
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
66
+ Unpickler(
67
+ std::function<size_t(char*, size_t)> reader,
68
+ TypeResolver type_resolver,
69
+ ObjLoader obj_loader,
70
+ std::function<at::DataPtr(const std::string&)> read_record,
71
+ c10::optional<at::Device> device,
72
+ bool use_storage_device = false,
73
+ TypeParserT type_parser = defaultTypeParser,
74
+ std::shared_ptr<DeserializationStorageContext> storage_context = nullptr)
75
+ : reader_(std::move(reader)),
76
+ tensor_table_(),
77
+ type_resolver_(std::move(type_resolver)),
78
+ obj_loader_(std::move(obj_loader)),
79
+ read_record_(std::move(read_record)),
80
+ // NOLINTNEXTLINE(performance-move-const-arg)
81
+ device_(std::move(device)),
82
+ use_storage_device_(use_storage_device),
83
+ type_parser_(type_parser),
84
+ storage_context_(std::move(storage_context)),
85
+ version_(caffe2::serialize::kProducedFileFormatVersion) {}
86
+
87
+ // consume the pickle stream, producing an IValue from the contents.
88
+ // Type Tags: the pickler will restore the type tags on
89
+ // List and Dict objects when possible IValue is an Object.
90
+ // Otherwise, Dict and List objects will end up with Any as their tag.
91
+ // If you know the type of the ivalue, tags can be restored with
92
+ // restoreAccurateTypeTags
93
+ IValue parse_ivalue();
94
+
95
+ // [type tag serialization]
96
+ // This is used to determine whether to restore type tags be recursively
97
+ // descending into the returned stack object (if version_number <= 2), or
98
+ // if version_number >= 3, to use the type strings included in the pickle
99
+ // archive for container types. By default this is set to
100
+ // `kProducedFileFormatVersion` so unless you're loading a pickle file
101
+ // from alongside a corresponding `version` file, you don't need to set
102
+ // the version manually.
103
+ void set_version(uint64_t version_number) {
104
+ version_ = version_number;
105
+ }
106
+
107
+ static c10::TypePtr defaultTypeParser(const std::string& str) {
108
+ ScriptTypeParser parser;
109
+ return parser.parseType(str);
110
+ }
111
+
112
+ private:
113
+ // No arguments ensures that a template argument must be specified
114
+ // so that the number of bytes read / type read is explicit
115
+ template <typename T>
116
+ T read() {
117
+ T item;
118
+ if (sizeof(T) <= buffer_remaining_) {
119
+ // Fast path: entirely from buffer.
120
+ memcpy(&item, buffer_.data() + buffer_pos_, sizeof(T));
121
+ buffer_remaining_ -= sizeof(T);
122
+ buffer_pos_ += sizeof(T);
123
+ } else {
124
+ // Don't over-template the slow path, to avoid code size bloat.
125
+ readSlowWithBuffer(reinterpret_cast<char*>(&item), sizeof(T));
126
+ }
127
+ return item;
128
+ }
129
+ void readSlowWithBuffer(char* dest, size_t sz);
130
+ std::string readBytes(size_t num_bytes);
131
+
132
+ double readFloat();
133
+ void readGlobal(
134
+ const std::string& module_name,
135
+ const std::string& class_name);
136
+ void rebuildTensor(bool quantized);
137
+ void rebuildTensorFromTypeV2();
138
+ void rebuildSparseTensor();
139
+ #ifdef USE_DISTRIBUTED
140
+ void rebuildRRef();
141
+ #endif
142
+ PickleOpCode readInstruction();
143
+ PickleOpCode readOpCode() {
144
+ return static_cast<PickleOpCode>(read<uint8_t>());
145
+ }
146
+ std::string readString();
147
+ void readList(IValue list_ivalue);
148
+ void readListElements(IValue list_ivalue, size_t start);
149
+ void setInput(size_t memo_id);
150
+ void run();
151
+
152
+ // Returns the number of bytes read. This should statefully
153
+ // remember the position. Don't call reader_ directly.
154
+ std::function<size_t(char*, size_t)> reader_;
155
+ // Small buffer to avoid calling reader_ on a per-byte basis.
156
+ std::array<char, 256> buffer_;
157
+ size_t buffer_pos_{0};
158
+ size_t buffer_remaining_{0};
159
+
160
+ std::vector<IValue> stack_;
161
+
162
+ // globals are represented on the stack as IValue integer indices
163
+ // into this list
164
+ std::vector<std::function<void(void)>> globals_;
165
+ std::vector<IValue> memo_table_;
166
+ std::vector<size_t> marks_;
167
+ c10::ArrayRef<at::Tensor> tensor_table_;
168
+
169
+ // When deserializing types on lists and dicts, cache the type here
170
+ // so we don't have to parse the same type multiple times. Strings
171
+ // are already de-duplicated and replaced with BINGETs in the
172
+ // pickler, so we can just use the actual data pointer of each string.
173
+ std::unordered_map<std::string, c10::TypePtr> type_cache_;
174
+
175
+ // optionally nullptr, needs to be present for creating classes
176
+ TypeResolver type_resolver_;
177
+ ObjLoader obj_loader_;
178
+ IValue empty_tuple_;
179
+
180
+ std::function<at::DataPtr(const std::string&)> read_record_;
181
+ c10::optional<at::Device> device_;
182
+ // When set to true, Unpickler will ignore the pickled device and use the
183
+ // device of the DataPtr returned by the read_record_ function. The default
184
+ // value of this flag is false.
185
+ const bool use_storage_device_;
186
+
187
+ TypeParserT type_parser_{defaultTypeParser};
188
+
189
+ // Used for torch.package to enable sharing of storages across
190
+ // ScriptModules and eager modules
191
+ std::shared_ptr<DeserializationStorageContext> storage_context_;
192
+
193
+ // See [type tag serialization]
194
+ uint64_t version_;
195
+
196
+ // See [NOTE] skip_next_read_global
197
+ uint8_t skip_next_read_global = 0;
198
+ };
199
+
200
+ void restoreAccurateTypeTags(const IValue& root, const c10::TypePtr& type_tag);
201
+
202
+ } // namespace jit
203
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/utils/byte_order.h ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <c10/util/BFloat16.h>
4
+ #include <c10/util/Float8_e4m3fn.h>
5
+ #include <c10/util/Float8_e4m3fnuz.h>
6
+ #include <c10/util/Float8_e5m2.h>
7
+ #include <c10/util/Float8_e5m2fnuz.h>
8
+ #include <c10/util/Half.h>
9
+ #include <torch/csrc/Export.h>
10
+ #include <cstddef>
11
+ #include <cstdint>
12
+
13
+ #ifdef __FreeBSD__
14
+ #include <sys/endian.h>
15
+ #include <sys/types.h>
16
+ #define thp_bswap16(x) bswap16(x)
17
+ #define thp_bswap32(x) bswap32(x)
18
+ #define thp_bswap64(x) bswap64(x)
19
+ #elif defined(__APPLE__)
20
+ #include <libkern/OSByteOrder.h>
21
+ #define thp_bswap16(x) OSSwapInt16(x)
22
+ #define thp_bswap32(x) OSSwapInt32(x)
23
+ #define thp_bswap64(x) OSSwapInt64(x)
24
+ #elif defined(__GNUC__) && !defined(__MINGW32__)
25
+ #include <byteswap.h>
26
+ #define thp_bswap16(x) bswap_16(x)
27
+ #define thp_bswap32(x) bswap_32(x)
28
+ #define thp_bswap64(x) bswap_64(x)
29
+ #elif defined _WIN32 || defined _WIN64
30
+ #define thp_bswap16(x) _byteswap_ushort(x)
31
+ #define thp_bswap32(x) _byteswap_ulong(x)
32
+ #define thp_bswap64(x) _byteswap_uint64(x)
33
+ #endif
34
+
35
+ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
36
+ #define to_be16(x) thp_bswap16(x)
37
+ #define from_be16(x) thp_bswap16(x)
38
+ #define to_be32(x) thp_bswap32(x)
39
+ #define from_be32(x) thp_bswap32(x)
40
+ #define to_be64(x) thp_bswap64(x)
41
+ #define from_be64(x) thp_bswap64(x)
42
+ #define to_le16(x) (x)
43
+ #define from_le16(x) (x)
44
+ #define to_le32(x) (x)
45
+ #define from_le32(x) (x)
46
+ #define to_le64(x) (x)
47
+ #define from_le64(x) (x)
48
+ #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
49
+ #define to_be16(x) (x)
50
+ #define from_be16(x) (x)
51
+ #define to_be32(x) (x)
52
+ #define from_be32(x) (x)
53
+ #define to_be64(x) (x)
54
+ #define from_be64(x) (x)
55
+ #define to_le16(x) thp_bswap16(x)
56
+ #define from_le16(x) thp_bswap16(x)
57
+ #define to_le32(x) thp_bswap32(x)
58
+ #define from_le32(x) thp_bswap32(x)
59
+ #define to_le64(x) thp_bswap64(x)
60
+ #define from_le64(x) thp_bswap64(x)
61
+ #else
62
+ #error Unexpected or undefined __BYTE_ORDER__
63
+ #endif
64
+
65
+ namespace torch {
66
+ namespace utils {
67
+
68
+ enum THPByteOrder { THP_LITTLE_ENDIAN = 0, THP_BIG_ENDIAN = 1 };
69
+
70
+ TORCH_API THPByteOrder THP_nativeByteOrder();
71
+
72
+ TORCH_API void THP_decodeInt16Buffer(
73
+ int16_t* dst,
74
+ const uint8_t* src,
75
+ bool do_byte_swap,
76
+ size_t len);
77
+ TORCH_API void THP_decodeInt32Buffer(
78
+ int32_t* dst,
79
+ const uint8_t* src,
80
+ bool do_byte_swap,
81
+ size_t len);
82
+ TORCH_API void THP_decodeInt64Buffer(
83
+ int64_t* dst,
84
+ const uint8_t* src,
85
+ bool do_byte_swap,
86
+ size_t len);
87
+ TORCH_API void THP_decodeHalfBuffer(
88
+ c10::Half* dst,
89
+ const uint8_t* src,
90
+ bool do_byte_swap,
91
+ size_t len);
92
+ TORCH_API void THP_decodeFloatBuffer(
93
+ float* dst,
94
+ const uint8_t* src,
95
+ bool do_byte_swap,
96
+ size_t len);
97
+ TORCH_API void THP_decodeDoubleBuffer(
98
+ double* dst,
99
+ const uint8_t* src,
100
+ bool do_byte_swap,
101
+ size_t len);
102
+ TORCH_API void THP_decodeBoolBuffer(
103
+ bool* dst,
104
+ const uint8_t* src,
105
+ bool do_byte_swap,
106
+ size_t len);
107
+ TORCH_API void THP_decodeBFloat16Buffer(
108
+ at::BFloat16* dst,
109
+ const uint8_t* src,
110
+ bool do_byte_swap,
111
+ size_t len);
112
+ TORCH_API void THP_decodeComplexFloatBuffer(
113
+ c10::complex<float>* dst,
114
+ const uint8_t* src,
115
+ bool do_byte_swap,
116
+ size_t len);
117
+ TORCH_API void THP_decodeComplexDoubleBuffer(
118
+ c10::complex<double>* dst,
119
+ const uint8_t* src,
120
+ bool do_byte_swap,
121
+ size_t len);
122
+
123
+ TORCH_API void THP_decodeInt16Buffer(
124
+ int16_t* dst,
125
+ const uint8_t* src,
126
+ THPByteOrder order,
127
+ size_t len);
128
+ TORCH_API void THP_decodeInt32Buffer(
129
+ int32_t* dst,
130
+ const uint8_t* src,
131
+ THPByteOrder order,
132
+ size_t len);
133
+ TORCH_API void THP_decodeInt64Buffer(
134
+ int64_t* dst,
135
+ const uint8_t* src,
136
+ THPByteOrder order,
137
+ size_t len);
138
+ TORCH_API void THP_decodeHalfBuffer(
139
+ c10::Half* dst,
140
+ const uint8_t* src,
141
+ THPByteOrder order,
142
+ size_t len);
143
+ TORCH_API void THP_decodeFloatBuffer(
144
+ float* dst,
145
+ const uint8_t* src,
146
+ THPByteOrder order,
147
+ size_t len);
148
+ TORCH_API void THP_decodeDoubleBuffer(
149
+ double* dst,
150
+ const uint8_t* src,
151
+ THPByteOrder order,
152
+ size_t len);
153
+ TORCH_API void THP_decodeBoolBuffer(
154
+ bool* dst,
155
+ const uint8_t* src,
156
+ THPByteOrder order,
157
+ size_t len);
158
+ TORCH_API void THP_decodeBFloat16Buffer(
159
+ at::BFloat16* dst,
160
+ const uint8_t* src,
161
+ THPByteOrder order,
162
+ size_t len);
163
+ TORCH_API void THP_decodeFloat8_e5m2Buffer(
164
+ at::Float8_e5m2* dst,
165
+ const uint8_t* src,
166
+ size_t len);
167
+ TORCH_API void THP_decodeFloat8_e4m3fnBuffer(
168
+ at::Float8_e4m3fn* dst,
169
+ const uint8_t* src,
170
+ size_t len);
171
+ TORCH_API void THP_decodeFloat8_e5m2fnuzBuffer(
172
+ at::Float8_e5m2fnuz* dst,
173
+ const uint8_t* src,
174
+ size_t len);
175
+ TORCH_API void THP_decodeFloat8_e4m3fnuzBuffer(
176
+ at::Float8_e4m3fnuz* dst,
177
+ const uint8_t* src,
178
+ size_t len);
179
+ TORCH_API void THP_decodeComplexFloatBuffer(
180
+ c10::complex<float>* dst,
181
+ const uint8_t* src,
182
+ THPByteOrder order,
183
+ size_t len);
184
+ TORCH_API void THP_decodeComplexDoubleBuffer(
185
+ c10::complex<double>* dst,
186
+ const uint8_t* src,
187
+ THPByteOrder order,
188
+ size_t len);
189
+
190
+ TORCH_API void THP_encodeInt16Buffer(
191
+ uint8_t* dst,
192
+ const int16_t* src,
193
+ THPByteOrder order,
194
+ size_t len);
195
+ TORCH_API void THP_encodeInt32Buffer(
196
+ uint8_t* dst,
197
+ const int32_t* src,
198
+ THPByteOrder order,
199
+ size_t len);
200
+ TORCH_API void THP_encodeInt64Buffer(
201
+ uint8_t* dst,
202
+ const int64_t* src,
203
+ THPByteOrder order,
204
+ size_t len);
205
+ TORCH_API void THP_encodeFloatBuffer(
206
+ uint8_t* dst,
207
+ const float* src,
208
+ THPByteOrder order,
209
+ size_t len);
210
+ TORCH_API void THP_encodeDoubleBuffer(
211
+ uint8_t* dst,
212
+ const double* src,
213
+ THPByteOrder order,
214
+ size_t len);
215
+ TORCH_API void THP_encodeComplexFloatBuffer(
216
+ uint8_t* dst,
217
+ const c10::complex<float>* src,
218
+ THPByteOrder order,
219
+ size_t len);
220
+ TORCH_API void THP_encodeComplexDoubleBuffer(
221
+ uint8_t* dst,
222
+ const c10::complex<double>* src,
223
+ THPByteOrder order,
224
+ size_t len);
225
+
226
+ } // namespace utils
227
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/utils/disable_torch_function.h ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #include <c10/core/DispatchKey.h>
3
+ #include <c10/core/impl/LocalDispatchKeySet.h>
4
+ #include <torch/csrc/python_headers.h>
5
+
6
+ namespace torch {
7
+ // Sometimes we don't want infinite recursion for subclasses,
8
+ // Or a way to achieve the old behaviour.
9
+
10
+ // This is an internal utility, not exposed to users.
11
+ bool torch_function_enabled();
12
+ PyObject* disabled_torch_function_impl();
13
+ PyObject* disabled_torch_dispatch_impl();
14
+ void set_disabled_torch_function_impl(PyObject* value);
15
+ void set_disabled_torch_dispatch_impl(PyObject* value);
16
+ // Set ignore_mode to true if you're trying to collect overloaded arguments;
17
+ // using mode here will improperly cause you to add ALL objects to the
18
+ // overloaded list even if they don't actually have __torch_function__
19
+ bool check_has_torch_function(PyObject* obj, bool ignore_mode = false);
20
+
21
+ struct DisableTorchDispatch {
22
+ DisableTorchDispatch()
23
+ : guard_(c10::DispatchKey::Python),
24
+ guard_tls_snapshot_(c10::DispatchKey::PythonTLSSnapshot) {}
25
+ c10::impl::ExcludeDispatchKeyGuard guard_;
26
+ c10::impl::ExcludeDispatchKeyGuard guard_tls_snapshot_;
27
+ };
28
+
29
+ } // namespace torch
30
+
31
+ PyObject* THPModule_isEnabledTorchFunction(PyObject* self, PyObject* unused);
32
+ PyObject* THPModule_DisableTorchFunctionType();
33
+ PyObject* THPModule_DisableTorchFunctionSubclassType();
34
+ PyObject* THPModule_disable_torch_function(PyObject* self, PyObject* args);
35
+ PyObject* THPModule_disable_torch_dispatch(PyObject* self, PyObject* args);
36
+ PyObject* THPModule_has_torch_function(PyObject*, PyObject* arg);
37
+ PyObject* THPModule_has_torch_function_unary(PyObject*, PyObject* obj);
38
+ PyObject* THPModule_has_torch_function_variadic(
39
+ PyObject*,
40
+ PyObject* const* args,
41
+ Py_ssize_t nargs);
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/utils/pythoncapi_compat.h ADDED
@@ -0,0 +1,716 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Header file providing new C API functions to old Python versions.
2
+ //
3
+ // File distributed under the Zero Clause BSD (0BSD) license.
4
+ // Copyright Contributors to the pythoncapi_compat project.
5
+ //
6
+ // Homepage:
7
+ // https://github.com/python/pythoncapi_compat
8
+ //
9
+ // Latest version:
10
+ // https://raw.githubusercontent.com/python/pythoncapi_compat/master/pythoncapi_compat.h
11
+ //
12
+ // SPDX-License-Identifier: 0BSD
13
+
14
+ #ifndef PYTHONCAPI_COMPAT
15
+ #define PYTHONCAPI_COMPAT
16
+
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
21
+ #include <Python.h>
22
+ #include "frameobject.h" // PyFrameObject, PyFrame_GetBack()
23
+
24
+
25
+ // Compatibility with Visual Studio 2013 and older which don't support
26
+ // the inline keyword in C (only in C++): use __inline instead.
27
+ #if (defined(_MSC_VER) && _MSC_VER < 1900 \
28
+ && !defined(__cplusplus) && !defined(inline))
29
+ # define PYCAPI_COMPAT_STATIC_INLINE(TYPE) static __inline TYPE
30
+ #else
31
+ # define PYCAPI_COMPAT_STATIC_INLINE(TYPE) static inline TYPE
32
+ #endif
33
+
34
+
35
+ #ifndef _Py_CAST
36
+ # define _Py_CAST(type, expr) ((type)(expr))
37
+ #endif
38
+
39
+ // On C++11 and newer, _Py_NULL is defined as nullptr on C++11,
40
+ // otherwise it is defined as NULL.
41
+ #ifndef _Py_NULL
42
+ # if defined(__cplusplus) && __cplusplus >= 201103
43
+ # define _Py_NULL nullptr
44
+ # else
45
+ # define _Py_NULL NULL
46
+ # endif
47
+ #endif
48
+
49
+ // Cast argument to PyObject* type.
50
+ #ifndef _PyObject_CAST
51
+ # define _PyObject_CAST(op) _Py_CAST(PyObject*, op)
52
+ #endif
53
+
54
+
55
+ // bpo-42262 added Py_NewRef() to Python 3.10.0a3
56
+ #if PY_VERSION_HEX < 0x030A00A3 && !defined(Py_NewRef)
57
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
58
+ _Py_NewRef(PyObject *obj)
59
+ {
60
+ Py_INCREF(obj);
61
+ return obj;
62
+ }
63
+ #define Py_NewRef(obj) _Py_NewRef(_PyObject_CAST(obj))
64
+ #endif
65
+
66
+
67
+ // bpo-42262 added Py_XNewRef() to Python 3.10.0a3
68
+ #if PY_VERSION_HEX < 0x030A00A3 && !defined(Py_XNewRef)
69
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
70
+ _Py_XNewRef(PyObject *obj)
71
+ {
72
+ Py_XINCREF(obj);
73
+ return obj;
74
+ }
75
+ #define Py_XNewRef(obj) _Py_XNewRef(_PyObject_CAST(obj))
76
+ #endif
77
+
78
+
79
+ // bpo-39573 added Py_SET_REFCNT() to Python 3.9.0a4
80
+ #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_REFCNT)
81
+ PYCAPI_COMPAT_STATIC_INLINE(void)
82
+ _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt)
83
+ {
84
+ ob->ob_refcnt = refcnt;
85
+ }
86
+ #define Py_SET_REFCNT(ob, refcnt) _Py_SET_REFCNT(_PyObject_CAST(ob), refcnt)
87
+ #endif
88
+
89
+
90
+ // Py_SETREF() and Py_XSETREF() were added to Python 3.5.2.
91
+ // It is excluded from the limited C API.
92
+ #if (PY_VERSION_HEX < 0x03050200 && !defined(Py_SETREF)) && !defined(Py_LIMITED_API)
93
+ #define Py_SETREF(dst, src) \
94
+ do { \
95
+ PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
96
+ PyObject *_tmp_dst = (*_tmp_dst_ptr); \
97
+ *_tmp_dst_ptr = _PyObject_CAST(src); \
98
+ Py_DECREF(_tmp_dst); \
99
+ } while (0)
100
+
101
+ #define Py_XSETREF(dst, src) \
102
+ do { \
103
+ PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
104
+ PyObject *_tmp_dst = (*_tmp_dst_ptr); \
105
+ *_tmp_dst_ptr = _PyObject_CAST(src); \
106
+ Py_XDECREF(_tmp_dst); \
107
+ } while (0)
108
+ #endif
109
+
110
+
111
+ // bpo-43753 added Py_Is(), Py_IsNone(), Py_IsTrue() and Py_IsFalse()
112
+ // to Python 3.10.0b1.
113
+ #if PY_VERSION_HEX < 0x030A00B1 && !defined(Py_Is)
114
+ # define Py_Is(x, y) ((x) == (y))
115
+ #endif
116
+ #if PY_VERSION_HEX < 0x030A00B1 && !defined(Py_IsNone)
117
+ # define Py_IsNone(x) Py_Is(x, Py_None)
118
+ #endif
119
+ #if PY_VERSION_HEX < 0x030A00B1 && !defined(Py_IsTrue)
120
+ # define Py_IsTrue(x) Py_Is(x, Py_True)
121
+ #endif
122
+ #if PY_VERSION_HEX < 0x030A00B1 && !defined(Py_IsFalse)
123
+ # define Py_IsFalse(x) Py_Is(x, Py_False)
124
+ #endif
125
+
126
+
127
+ // bpo-39573 added Py_SET_TYPE() to Python 3.9.0a4
128
+ #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
129
+ PYCAPI_COMPAT_STATIC_INLINE(void)
130
+ _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
131
+ {
132
+ ob->ob_type = type;
133
+ }
134
+ #define Py_SET_TYPE(ob, type) _Py_SET_TYPE(_PyObject_CAST(ob), type)
135
+ #endif
136
+
137
+
138
+ // bpo-39573 added Py_SET_SIZE() to Python 3.9.0a4
139
+ #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE)
140
+ PYCAPI_COMPAT_STATIC_INLINE(void)
141
+ _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size)
142
+ {
143
+ ob->ob_size = size;
144
+ }
145
+ #define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size)
146
+ #endif
147
+
148
+
149
+ // bpo-40421 added PyFrame_GetCode() to Python 3.9.0b1
150
+ #if PY_VERSION_HEX < 0x030900B1 || defined(PYPY_VERSION)
151
+ PYCAPI_COMPAT_STATIC_INLINE(PyCodeObject*)
152
+ PyFrame_GetCode(PyFrameObject *frame)
153
+ {
154
+ assert(frame != _Py_NULL);
155
+ assert(frame->f_code != _Py_NULL);
156
+ return _Py_CAST(PyCodeObject*, Py_NewRef(frame->f_code));
157
+ }
158
+ #endif
159
+
160
+ PYCAPI_COMPAT_STATIC_INLINE(PyCodeObject*)
161
+ _PyFrame_GetCodeBorrow(PyFrameObject *frame)
162
+ {
163
+ PyCodeObject *code = PyFrame_GetCode(frame);
164
+ Py_DECREF(code);
165
+ return code;
166
+ }
167
+
168
+
169
+ // bpo-40421 added PyFrame_GetBack() to Python 3.9.0b1
170
+ #if PY_VERSION_HEX < 0x030900B1 && !defined(PYPY_VERSION)
171
+ PYCAPI_COMPAT_STATIC_INLINE(PyFrameObject*)
172
+ PyFrame_GetBack(PyFrameObject *frame)
173
+ {
174
+ assert(frame != _Py_NULL);
175
+ return _Py_CAST(PyFrameObject*, Py_XNewRef(frame->f_back));
176
+ }
177
+ #endif
178
+
179
+ #if !defined(PYPY_VERSION)
180
+ PYCAPI_COMPAT_STATIC_INLINE(PyFrameObject*)
181
+ _PyFrame_GetBackBorrow(PyFrameObject *frame)
182
+ {
183
+ PyFrameObject *back = PyFrame_GetBack(frame);
184
+ Py_XDECREF(back);
185
+ return back;
186
+ }
187
+ #endif
188
+
189
+
190
+ // bpo-40421 added PyFrame_GetLocals() to Python 3.11.0a7
191
+ #if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION)
192
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
193
+ PyFrame_GetLocals(PyFrameObject *frame)
194
+ {
195
+ #if PY_VERSION_HEX >= 0x030400B1
196
+ if (PyFrame_FastToLocalsWithError(frame) < 0) {
197
+ return NULL;
198
+ }
199
+ #else
200
+ PyFrame_FastToLocals(frame);
201
+ #endif
202
+ return Py_NewRef(frame->f_locals);
203
+ }
204
+ #endif
205
+
206
+
207
+ // bpo-40421 added PyFrame_GetGlobals() to Python 3.11.0a7
208
+ #if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION)
209
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
210
+ PyFrame_GetGlobals(PyFrameObject *frame)
211
+ {
212
+ return Py_NewRef(frame->f_globals);
213
+ }
214
+ #endif
215
+
216
+
217
+ // bpo-40421 added PyFrame_GetBuiltins() to Python 3.11.0a7
218
+ #if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION)
219
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
220
+ PyFrame_GetBuiltins(PyFrameObject *frame)
221
+ {
222
+ return Py_NewRef(frame->f_builtins);
223
+ }
224
+ #endif
225
+
226
+
227
+ // bpo-40421 added PyFrame_GetLasti() to Python 3.11.0b1
228
+ #if PY_VERSION_HEX < 0x030B00B1 && !defined(PYPY_VERSION)
229
+ PYCAPI_COMPAT_STATIC_INLINE(int)
230
+ PyFrame_GetLasti(PyFrameObject *frame)
231
+ {
232
+ #if PY_VERSION_HEX >= 0x030A00A7
233
+ // bpo-27129: Since Python 3.10.0a7, f_lasti is an instruction offset,
234
+ // not a bytes offset anymore. Python uses 16-bit "wordcode" (2 bytes)
235
+ // instructions.
236
+ if (frame->f_lasti < 0) {
237
+ return -1;
238
+ }
239
+ return frame->f_lasti * 2;
240
+ #else
241
+ return frame->f_lasti;
242
+ #endif
243
+ }
244
+ #endif
245
+
246
+
247
+ // gh-91248 added PyFrame_GetVar() to Python 3.12.0a2
248
+ #if PY_VERSION_HEX < 0x030C00A2 && !defined(PYPY_VERSION)
249
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
250
+ PyFrame_GetVar(PyFrameObject *frame, PyObject *name)
251
+ {
252
+ PyObject *locals, *value;
253
+
254
+ locals = PyFrame_GetLocals(frame);
255
+ if (locals == NULL) {
256
+ return NULL;
257
+ }
258
+ #if PY_VERSION_HEX >= 0x03000000
259
+ value = PyDict_GetItemWithError(locals, name);
260
+ #else
261
+ value = PyDict_GetItem(locals, name);
262
+ #endif
263
+ Py_DECREF(locals);
264
+
265
+ if (value == NULL) {
266
+ if (PyErr_Occurred()) {
267
+ return NULL;
268
+ }
269
+ #if PY_VERSION_HEX >= 0x03000000
270
+ PyErr_Format(PyExc_NameError, "variable %R does not exist", name);
271
+ #else
272
+ PyErr_SetString(PyExc_NameError, "variable does not exist");
273
+ #endif
274
+ return NULL;
275
+ }
276
+ return Py_NewRef(value);
277
+ }
278
+ #endif
279
+
280
+
281
+ // gh-91248 added PyFrame_GetVarString() to Python 3.12.0a2
282
+ #if PY_VERSION_HEX < 0x030C00A2 && !defined(PYPY_VERSION)
283
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
284
+ PyFrame_GetVarString(PyFrameObject *frame, const char *name)
285
+ {
286
+ PyObject *name_obj, *value;
287
+ name_obj = PyUnicode_FromString(name);
288
+ if (name_obj == NULL) {
289
+ return NULL;
290
+ }
291
+ value = PyFrame_GetVar(frame, name_obj);
292
+ Py_DECREF(name_obj);
293
+ return value;
294
+ }
295
+ #endif
296
+
297
+
298
+ // bpo-39947 added PyThreadState_GetInterpreter() to Python 3.9.0a5
299
+ #if PY_VERSION_HEX < 0x030900A5 || defined(PYPY_VERSION)
300
+ PYCAPI_COMPAT_STATIC_INLINE(PyInterpreterState *)
301
+ PyThreadState_GetInterpreter(PyThreadState *tstate)
302
+ {
303
+ assert(tstate != _Py_NULL);
304
+ return tstate->interp;
305
+ }
306
+ #endif
307
+
308
+
309
+ // bpo-40429 added PyThreadState_GetFrame() to Python 3.9.0b1
310
+ #if PY_VERSION_HEX < 0x030900B1 && !defined(PYPY_VERSION)
311
+ PYCAPI_COMPAT_STATIC_INLINE(PyFrameObject*)
312
+ PyThreadState_GetFrame(PyThreadState *tstate)
313
+ {
314
+ assert(tstate != _Py_NULL);
315
+ return _Py_CAST(PyFrameObject *, Py_XNewRef(tstate->frame));
316
+ }
317
+ #endif
318
+
319
+ #if !defined(PYPY_VERSION)
320
+ PYCAPI_COMPAT_STATIC_INLINE(PyFrameObject*)
321
+ _PyThreadState_GetFrameBorrow(PyThreadState *tstate)
322
+ {
323
+ PyFrameObject *frame = PyThreadState_GetFrame(tstate);
324
+ Py_XDECREF(frame);
325
+ return frame;
326
+ }
327
+ #endif
328
+
329
+
330
+ // bpo-39947 added PyInterpreterState_Get() to Python 3.9.0a5
331
+ #if PY_VERSION_HEX < 0x030900A5 || defined(PYPY_VERSION)
332
+ PYCAPI_COMPAT_STATIC_INLINE(PyInterpreterState*)
333
+ PyInterpreterState_Get(void)
334
+ {
335
+ PyThreadState *tstate;
336
+ PyInterpreterState *interp;
337
+
338
+ tstate = PyThreadState_GET();
339
+ if (tstate == _Py_NULL) {
340
+ Py_FatalError("GIL released (tstate is NULL)");
341
+ }
342
+ interp = tstate->interp;
343
+ if (interp == _Py_NULL) {
344
+ Py_FatalError("no current interpreter");
345
+ }
346
+ return interp;
347
+ }
348
+ #endif
349
+
350
+
351
+ // bpo-39947 added PyInterpreterState_Get() to Python 3.9.0a6
352
+ #if 0x030700A1 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x030900A6 && !defined(PYPY_VERSION)
353
+ PYCAPI_COMPAT_STATIC_INLINE(uint64_t)
354
+ PyThreadState_GetID(PyThreadState *tstate)
355
+ {
356
+ assert(tstate != _Py_NULL);
357
+ return tstate->id;
358
+ }
359
+ #endif
360
+
361
+ // bpo-43760 added PyThreadState_EnterTracing() to Python 3.11.0a2
362
+ #if PY_VERSION_HEX < 0x030B00A2 && !defined(PYPY_VERSION)
363
+ PYCAPI_COMPAT_STATIC_INLINE(void)
364
+ PyThreadState_EnterTracing(PyThreadState *tstate)
365
+ {
366
+ tstate->tracing++;
367
+ #if PY_VERSION_HEX >= 0x030A00A1
368
+ tstate->cframe->use_tracing = 0;
369
+ #else
370
+ tstate->use_tracing = 0;
371
+ #endif
372
+ }
373
+ #endif
374
+
375
+ // bpo-43760 added PyThreadState_LeaveTracing() to Python 3.11.0a2
376
+ #if PY_VERSION_HEX < 0x030B00A2 && !defined(PYPY_VERSION)
377
+ PYCAPI_COMPAT_STATIC_INLINE(void)
378
+ PyThreadState_LeaveTracing(PyThreadState *tstate)
379
+ {
380
+ int use_tracing = (tstate->c_tracefunc != _Py_NULL
381
+ || tstate->c_profilefunc != _Py_NULL);
382
+ tstate->tracing--;
383
+ #if PY_VERSION_HEX >= 0x030A00A1
384
+ tstate->cframe->use_tracing = use_tracing;
385
+ #else
386
+ tstate->use_tracing = use_tracing;
387
+ #endif
388
+ }
389
+ #endif
390
+
391
+
392
+ // bpo-37194 added PyObject_CallNoArgs() to Python 3.9.0a1
393
+ // PyObject_CallNoArgs() added to PyPy 3.9.16-v7.3.11
394
+ #if !defined(PyObject_CallNoArgs) && PY_VERSION_HEX < 0x030900A1
395
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
396
+ PyObject_CallNoArgs(PyObject *func)
397
+ {
398
+ return PyObject_CallFunctionObjArgs(func, NULL);
399
+ }
400
+
401
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
402
+ PyObject_CallMethodNoArgs(PyObject *obj, PyObject *name)
403
+ {
404
+ return PyObject_CallMethodObjArgs(obj, name, NULL);
405
+ }
406
+ #endif
407
+
408
+
409
+ // bpo-39245 made PyObject_CallOneArg() public (previously called
410
+ // _PyObject_CallOneArg) in Python 3.9.0a4
411
+ // PyObject_CallOneArg() added to PyPy 3.9.16-v7.3.11
412
+ #if !defined(PyObject_CallOneArg) && PY_VERSION_HEX < 0x030900A4
413
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
414
+ PyObject_CallOneArg(PyObject *func, PyObject *arg)
415
+ {
416
+ return PyObject_CallFunctionObjArgs(func, arg, NULL);
417
+ }
418
+
419
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
420
+ PyObject_CallMethodOneArg(PyObject *obj, PyObject *name, PyObject *arg)
421
+ {
422
+ return PyObject_CallMethodObjArgs(obj, name, arg, NULL);
423
+ }
424
+ #endif
425
+
426
+
427
+ // bpo-1635741 added PyModule_AddObjectRef() to Python 3.10.0a3
428
+ #if PY_VERSION_HEX < 0x030A00A3
429
+ PYCAPI_COMPAT_STATIC_INLINE(int)
430
+ PyModule_AddObjectRef(PyObject *module, const char *name, PyObject *value)
431
+ {
432
+ int res;
433
+ Py_XINCREF(value);
434
+ res = PyModule_AddObject(module, name, value);
435
+ if (res < 0) {
436
+ Py_XDECREF(value);
437
+ }
438
+ return res;
439
+ }
440
+ #endif
441
+
442
+
443
+ // bpo-40024 added PyModule_AddType() to Python 3.9.0a5
444
+ #if PY_VERSION_HEX < 0x030900A5
445
+ PYCAPI_COMPAT_STATIC_INLINE(int)
446
+ PyModule_AddType(PyObject *module, PyTypeObject *type)
447
+ {
448
+ const char *name, *dot;
449
+
450
+ if (PyType_Ready(type) < 0) {
451
+ return -1;
452
+ }
453
+
454
+ // inline _PyType_Name()
455
+ name = type->tp_name;
456
+ assert(name != _Py_NULL);
457
+ dot = strrchr(name, '.');
458
+ if (dot != _Py_NULL) {
459
+ name = dot + 1;
460
+ }
461
+
462
+ return PyModule_AddObjectRef(module, name, _PyObject_CAST(type));
463
+ }
464
+ #endif
465
+
466
+
467
+ // bpo-40241 added PyObject_GC_IsTracked() to Python 3.9.0a6.
468
+ // bpo-4688 added _PyObject_GC_IS_TRACKED() to Python 2.7.0a2.
469
+ #if PY_VERSION_HEX < 0x030900A6 && !defined(PYPY_VERSION)
470
+ PYCAPI_COMPAT_STATIC_INLINE(int)
471
+ PyObject_GC_IsTracked(PyObject* obj)
472
+ {
473
+ return (PyObject_IS_GC(obj) && _PyObject_GC_IS_TRACKED(obj));
474
+ }
475
+ #endif
476
+
477
+ // bpo-40241 added PyObject_GC_IsFinalized() to Python 3.9.0a6.
478
+ // bpo-18112 added _PyGCHead_FINALIZED() to Python 3.4.0 final.
479
+ #if PY_VERSION_HEX < 0x030900A6 && PY_VERSION_HEX >= 0x030400F0 && !defined(PYPY_VERSION)
480
+ PYCAPI_COMPAT_STATIC_INLINE(int)
481
+ PyObject_GC_IsFinalized(PyObject *obj)
482
+ {
483
+ PyGC_Head *gc = _Py_CAST(PyGC_Head*, obj) - 1;
484
+ return (PyObject_IS_GC(obj) && _PyGCHead_FINALIZED(gc));
485
+ }
486
+ #endif
487
+
488
+
489
+ // bpo-39573 added Py_IS_TYPE() to Python 3.9.0a4
490
+ #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_IS_TYPE)
491
+ PYCAPI_COMPAT_STATIC_INLINE(int)
492
+ _Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
493
+ return Py_TYPE(ob) == type;
494
+ }
495
+ #define Py_IS_TYPE(ob, type) _Py_IS_TYPE(_PyObject_CAST(ob), type)
496
+ #endif
497
+
498
+
499
+ // bpo-46906 added PyFloat_Pack2() and PyFloat_Unpack2() to Python 3.11a7.
500
+ // bpo-11734 added _PyFloat_Pack2() and _PyFloat_Unpack2() to Python 3.6.0b1.
501
+ // Python 3.11a2 moved _PyFloat_Pack2() and _PyFloat_Unpack2() to the internal
502
+ // C API: Python 3.11a2-3.11a6 versions are not supported.
503
+ #if 0x030600B1 <= PY_VERSION_HEX && PY_VERSION_HEX <= 0x030B00A1 && !defined(PYPY_VERSION)
504
+ PYCAPI_COMPAT_STATIC_INLINE(int)
505
+ PyFloat_Pack2(double x, char *p, int le)
506
+ { return _PyFloat_Pack2(x, (unsigned char*)p, le); }
507
+
508
+ PYCAPI_COMPAT_STATIC_INLINE(double)
509
+ PyFloat_Unpack2(const char *p, int le)
510
+ { return _PyFloat_Unpack2((const unsigned char *)p, le); }
511
+ #endif
512
+
513
+
514
+ // bpo-46906 added PyFloat_Pack4(), PyFloat_Pack8(), PyFloat_Unpack4() and
515
+ // PyFloat_Unpack8() to Python 3.11a7.
516
+ // Python 3.11a2 moved _PyFloat_Pack4(), _PyFloat_Pack8(), _PyFloat_Unpack4()
517
+ // and _PyFloat_Unpack8() to the internal C API: Python 3.11a2-3.11a6 versions
518
+ // are not supported.
519
+ #if PY_VERSION_HEX <= 0x030B00A1 && !defined(PYPY_VERSION)
520
+ PYCAPI_COMPAT_STATIC_INLINE(int)
521
+ PyFloat_Pack4(double x, char *p, int le)
522
+ { return _PyFloat_Pack4(x, (unsigned char*)p, le); }
523
+
524
+ PYCAPI_COMPAT_STATIC_INLINE(int)
525
+ PyFloat_Pack8(double x, char *p, int le)
526
+ { return _PyFloat_Pack8(x, (unsigned char*)p, le); }
527
+
528
+ PYCAPI_COMPAT_STATIC_INLINE(double)
529
+ PyFloat_Unpack4(const char *p, int le)
530
+ { return _PyFloat_Unpack4((const unsigned char *)p, le); }
531
+
532
+ PYCAPI_COMPAT_STATIC_INLINE(double)
533
+ PyFloat_Unpack8(const char *p, int le)
534
+ { return _PyFloat_Unpack8((const unsigned char *)p, le); }
535
+ #endif
536
+
537
+
538
+ // gh-92154 added PyCode_GetCode() to Python 3.11.0b1
539
+ #if PY_VERSION_HEX < 0x030B00B1 && !defined(PYPY_VERSION)
540
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
541
+ PyCode_GetCode(PyCodeObject *code)
542
+ {
543
+ return Py_NewRef(code->co_code);
544
+ }
545
+ #endif
546
+
547
+
548
+ // gh-95008 added PyCode_GetVarnames() to Python 3.11.0rc1
549
+ #if PY_VERSION_HEX < 0x030B00C1 && !defined(PYPY_VERSION)
550
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
551
+ PyCode_GetVarnames(PyCodeObject *code)
552
+ {
553
+ return Py_NewRef(code->co_varnames);
554
+ }
555
+ #endif
556
+
557
+ // gh-95008 added PyCode_GetFreevars() to Python 3.11.0rc1
558
+ #if PY_VERSION_HEX < 0x030B00C1 && !defined(PYPY_VERSION)
559
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
560
+ PyCode_GetFreevars(PyCodeObject *code)
561
+ {
562
+ return Py_NewRef(code->co_freevars);
563
+ }
564
+ #endif
565
+
566
+ // gh-95008 added PyCode_GetCellvars() to Python 3.11.0rc1
567
+ #if PY_VERSION_HEX < 0x030B00C1 && !defined(PYPY_VERSION)
568
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
569
+ PyCode_GetCellvars(PyCodeObject *code)
570
+ {
571
+ return Py_NewRef(code->co_cellvars);
572
+ }
573
+ #endif
574
+
575
+
576
+ // Py_UNUSED() was added to Python 3.4.0b2.
577
+ #if PY_VERSION_HEX < 0x030400B2 && !defined(Py_UNUSED)
578
+ # if defined(__GNUC__) || defined(__clang__)
579
+ # define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
580
+ # else
581
+ # define Py_UNUSED(name) _unused_ ## name
582
+ # endif
583
+ #endif
584
+
585
+
586
+ // gh-105922 added PyImport_AddModuleRef() to Python 3.13.0a1
587
+ #if PY_VERSION_HEX < 0x030D00A0
588
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
589
+ PyImport_AddModuleRef(const char *name)
590
+ {
591
+ return Py_XNewRef(PyImport_AddModule(name));
592
+ }
593
+ #endif
594
+
595
+
596
+ // gh-105927 added PyWeakref_GetRef() to Python 3.13.0a1
597
+ #if PY_VERSION_HEX < 0x030D0000
598
+ PYCAPI_COMPAT_STATIC_INLINE(int)
599
+ PyWeakref_GetRef(PyObject *ref, PyObject **pobj)
600
+ {
601
+ PyObject *obj;
602
+ if (ref != NULL && !PyWeakref_Check(ref)) {
603
+ *pobj = NULL;
604
+ PyErr_SetString(PyExc_TypeError, "expected a weakref");
605
+ return -1;
606
+ }
607
+ obj = PyWeakref_GetObject(ref);
608
+ if (obj == NULL) {
609
+ // SystemError if ref is NULL
610
+ *pobj = NULL;
611
+ return -1;
612
+ }
613
+ if (obj == Py_None) {
614
+ *pobj = NULL;
615
+ return 0;
616
+ }
617
+ *pobj = Py_NewRef(obj);
618
+ return (*pobj != NULL);
619
+ }
620
+ #endif
621
+
622
+
623
+ // bpo-36974 added PY_VECTORCALL_ARGUMENTS_OFFSET to Python 3.8b1
624
+ #ifndef PY_VECTORCALL_ARGUMENTS_OFFSET
625
+ # define PY_VECTORCALL_ARGUMENTS_OFFSET (_Py_CAST(size_t, 1) << (8 * sizeof(size_t) - 1))
626
+ #endif
627
+
628
+ // bpo-36974 added PyVectorcall_NARGS() to Python 3.8b1
629
+ #if PY_VERSION_HEX < 0x030800B1
630
+ static inline Py_ssize_t
631
+ PyVectorcall_NARGS(size_t n)
632
+ {
633
+ return n & ~PY_VECTORCALL_ARGUMENTS_OFFSET;
634
+ }
635
+ #endif
636
+
637
+
638
+ // gh-105922 added PyObject_Vectorcall() to Python 3.9.0a4
639
+ #if PY_VERSION_HEX < 0x030900A4
640
+ PYCAPI_COMPAT_STATIC_INLINE(PyObject*)
641
+ PyObject_Vectorcall(PyObject *callable, PyObject *const *args,
642
+ size_t nargsf, PyObject *kwnames)
643
+ {
644
+ #if PY_VERSION_HEX >= 0x030800B1 && !defined(PYPY_VERSION)
645
+ // bpo-36974 added _PyObject_Vectorcall() to Python 3.8.0b1
646
+ return _PyObject_Vectorcall(callable, args, nargsf, kwnames);
647
+ #else
648
+ PyObject *posargs = NULL, *kwargs = NULL;
649
+ PyObject *res;
650
+ Py_ssize_t nposargs, nkwargs, i;
651
+
652
+ if (nargsf != 0 && args == NULL) {
653
+ PyErr_BadInternalCall();
654
+ goto error;
655
+ }
656
+ if (kwnames != NULL && !PyTuple_Check(kwnames)) {
657
+ PyErr_BadInternalCall();
658
+ goto error;
659
+ }
660
+
661
+ nposargs = (Py_ssize_t)PyVectorcall_NARGS(nargsf);
662
+ if (kwnames) {
663
+ nkwargs = PyTuple_GET_SIZE(kwnames);
664
+ }
665
+ else {
666
+ nkwargs = 0;
667
+ }
668
+
669
+ posargs = PyTuple_New(nposargs);
670
+ if (posargs == NULL) {
671
+ goto error;
672
+ }
673
+ if (nposargs) {
674
+ for (i=0; i < nposargs; i++) {
675
+ PyTuple_SET_ITEM(posargs, i, Py_NewRef(*args));
676
+ args++;
677
+ }
678
+ }
679
+
680
+ if (nkwargs) {
681
+ kwargs = PyDict_New();
682
+ if (kwargs == NULL) {
683
+ goto error;
684
+ }
685
+
686
+ for (i = 0; i < nkwargs; i++) {
687
+ PyObject *key = PyTuple_GET_ITEM(kwnames, i);
688
+ PyObject *value = *args;
689
+ args++;
690
+ if (PyDict_SetItem(kwargs, key, value) < 0) {
691
+ goto error;
692
+ }
693
+ }
694
+ }
695
+ else {
696
+ kwargs = NULL;
697
+ }
698
+
699
+ res = PyObject_Call(callable, posargs, kwargs);
700
+ Py_DECREF(posargs);
701
+ Py_XDECREF(kwargs);
702
+ return res;
703
+
704
+ error:
705
+ Py_DECREF(posargs);
706
+ Py_XDECREF(kwargs);
707
+ return NULL;
708
+ #endif
709
+ }
710
+ #endif
711
+
712
+
713
+ #ifdef __cplusplus
714
+ }
715
+ #endif
716
+ #endif // PYTHONCAPI_COMPAT
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/utils/tensor_apply.h ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/core/Tensor.h>
4
+ #include <torch/csrc/python_headers.h>
5
+
6
+ namespace torch {
7
+ namespace utils {
8
+
9
+ const at::Tensor& apply_(const at::Tensor& self, PyObject* fn);
10
+ const at::Tensor& map_(
11
+ const at::Tensor& self,
12
+ const at::Tensor& other_,
13
+ PyObject* fn);
14
+ const at::Tensor& map2_(
15
+ const at::Tensor& self,
16
+ const at::Tensor& x_,
17
+ const at::Tensor& y_,
18
+ PyObject* fn);
19
+
20
+ } // namespace utils
21
+ } // namespace torch
videollama2/lib/python3.10/site-packages/torch/include/torch/csrc/utils/tensor_qschemes.h ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #include <torch/csrc/QScheme.h>
3
+
4
+ namespace torch {
5
+ namespace utils {
6
+
7
+ PyObject* getTHPQScheme(at::QScheme qscheme);
8
+ void initializeQSchemes();
9
+
10
+ } // namespace utils
11
+ } // namespace torch
vllm/lib/python3.10/site-packages/dns/__init__.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
2
+
3
+ # Copyright (C) 2003-2007, 2009, 2011 Nominum, Inc.
4
+ #
5
+ # Permission to use, copy, modify, and distribute this software and its
6
+ # documentation for any purpose with or without fee is hereby granted,
7
+ # provided that the above copyright notice and this permission notice
8
+ # appear in all copies.
9
+ #
10
+ # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
11
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
13
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
16
+ # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+
18
+ """dnspython DNS toolkit"""
19
+
20
+ __all__ = [
21
+ "asyncbackend",
22
+ "asyncquery",
23
+ "asyncresolver",
24
+ "dnssec",
25
+ "dnssecalgs",
26
+ "dnssectypes",
27
+ "e164",
28
+ "edns",
29
+ "entropy",
30
+ "exception",
31
+ "flags",
32
+ "immutable",
33
+ "inet",
34
+ "ipv4",
35
+ "ipv6",
36
+ "message",
37
+ "name",
38
+ "namedict",
39
+ "node",
40
+ "opcode",
41
+ "query",
42
+ "quic",
43
+ "rcode",
44
+ "rdata",
45
+ "rdataclass",
46
+ "rdataset",
47
+ "rdatatype",
48
+ "renderer",
49
+ "resolver",
50
+ "reversename",
51
+ "rrset",
52
+ "serial",
53
+ "set",
54
+ "tokenizer",
55
+ "transaction",
56
+ "tsig",
57
+ "tsigkeyring",
58
+ "ttl",
59
+ "rdtypes",
60
+ "update",
61
+ "version",
62
+ "versioned",
63
+ "wire",
64
+ "xfr",
65
+ "zone",
66
+ "zonetypes",
67
+ "zonefile",
68
+ ]
69
+
70
+ from dns.version import version as __version__ # noqa