jasonfan commited on
Commit
e20bd03
·
verified ·
1 Parent(s): 5dd5a7b

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. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/accumulate_grad.h +307 -0
  2. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/basic_ops.h +117 -0
  3. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/comm.h +50 -0
  4. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/pybind.h +19 -0
  5. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/tensor.h +190 -0
  6. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/utils.h +120 -0
  7. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/Functions.h +0 -0
  8. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/VariableType.h +60 -0
  9. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/ViewFuncs.h +960 -0
  10. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/python_functions.h +30 -0
  11. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/python_return_types.h +103 -0
  12. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/variable_factories.h +784 -0
  13. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/python_variable_indexing.h +104 -0
  14. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/record_function_ops.h +32 -0
  15. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/saved_variable.h +145 -0
  16. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/saved_variable_hooks.h +24 -0
  17. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/symbolic.h +21 -0
  18. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/error_messages.h +23 -0
  19. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/grad_layout_contract.h +83 -0
  20. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/lambda_post_hook.h +47 -0
  21. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/python_arg_parsing.h +54 -0
  22. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/warnings.h +29 -0
  23. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/wrap_outputs.h +158 -0
  24. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/variable.h +1016 -0
  25. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/variable_info.h +28 -0
  26. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cpu/Module.h +13 -0
  27. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/CUDAPluggableAllocator.h +175 -0
  28. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Event.h +24 -0
  29. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/GdsFile.h +14 -0
  30. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Module.h +17 -0
  31. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Stream.h +25 -0
  32. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/THCP.h +13 -0
  33. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/comm.h +57 -0
  34. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/device_set.h +16 -0
  35. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/memory_snapshot.h +38 -0
  36. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/nccl.h +224 -0
  37. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_comm.h +13 -0
  38. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_nccl.h +18 -0
  39. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/utils.h +14 -0
  40. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/Placement.h +120 -0
  41. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/autograd.h +41 -0
  42. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/context/container.h +167 -0
  43. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/context/context.h +176 -0
  44. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/engine/dist_engine.h +177 -0
  45. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/functions/recvrpc_backward.h +50 -0
  46. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/functions/sendrpc_backward.h +38 -0
  47. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/python_autograd.h +14 -0
  48. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h +26 -0
  49. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_req.h +30 -0
  50. miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_resp.h +24 -0
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/accumulate_grad.h ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <ATen/CachedTensorUtils.h>
5
+ #include <ATen/LegacyBatchedTensorImpl.h>
6
+ #include <ATen/TensorOperators.h>
7
+ #include <torch/csrc/Export.h>
8
+ #include <torch/csrc/autograd/function.h>
9
+ #include <torch/csrc/autograd/utils/grad_layout_contract.h>
10
+ #include <torch/csrc/autograd/variable.h>
11
+
12
+ #ifndef AT_PER_OPERATOR_HEADERS
13
+ #include <ATen/Functions.h>
14
+ #else
15
+ #include <ATen/ops/_sparse_coo_tensor_unsafe.h>
16
+ #endif
17
+
18
+ #include <mutex>
19
+
20
+ namespace torch::autograd {
21
+
22
+ #define CHECK_RESULT(RESULT, VAR) \
23
+ if (!(RESULT.is_sparse() || VAR.is_sparse() || RESULT.is_sparse_csr() || \
24
+ VAR.is_sparse_csr())) { \
25
+ if (!utils::obeys_layout_contract(RESULT, VAR)) { \
26
+ TORCH_WARN_ONCE( \
27
+ "grad and param do not obey the gradient layout contract. " \
28
+ "This is not an error, but may impair performance.\n" \
29
+ "grad.sizes() = ", \
30
+ RESULT.sizes(), \
31
+ ", strides() = ", \
32
+ RESULT.strides(), \
33
+ "\n", \
34
+ "param.sizes() = ", \
35
+ VAR.sizes(), \
36
+ ", strides() = ", \
37
+ VAR.strides()); \
38
+ } \
39
+ }
40
+
41
+ struct TORCH_API AccumulateGrad : public Node {
42
+ explicit AccumulateGrad(Variable variable_);
43
+
44
+ variable_list apply(variable_list&& grads) override;
45
+
46
+ std::vector<std::unique_ptr<FunctionPreHook>>& tensor_pre_hooks() noexcept
47
+ override {
48
+ // NB: Since the AccumulateGrad Node is only a weak ref from the Tensor,
49
+ // it can be destroyed even though the Tensor is still alive (contrary
50
+ // to all other Nodes). So we must lazily read the Tensor hooks here.
51
+ return impl::hooks(variable);
52
+ }
53
+
54
+ std::unique_ptr<PostAccumulateGradHook>& tensor_post_acc_grad_hooks()
55
+ const noexcept override {
56
+ // NB: Since the AccumulateGrad Node is only a weak ref from the Tensor,
57
+ // it can be destroyed even though the Tensor is still alive (contrary
58
+ // to all other Nodes). So we must lazily read the Tensor hooks here.
59
+ return impl::post_acc_grad_hooks(variable);
60
+ }
61
+
62
+ // Note: Gradient Layout Contract
63
+ //
64
+ // AccumulateGrad tries to stash strided (non-sparse) grads with memory layout
65
+ // (strides) such that variables and grads interact efficiently in later
66
+ // optimizer kernels, and grads interact efficiently with c10d::Reducer.cpp.
67
+ //
68
+ // Specifically, AccumulateGrad tries to ensure the following
69
+ // (cf torch/csrc/autograd/utils/grad_layout_contract.h):
70
+ // (1) if variable.is_non_overlapping_and_dense(), the stashed grad's
71
+ // strides match variable.
72
+ // (2) else, stashed grad is rowmajor contiguous.
73
+ // If variable's grad does not exist (!variable_grad.defined())
74
+ // AccumulateGrad steals new_grad if it's stealable and obeys the contract
75
+ // already, otherwise it deep copies new_grad into an obedient clone.
76
+ //
77
+ // If variable's grad already exists (variable_grad.defined()), new_grad must
78
+ // be added to variable_grad. If we aren't setting up for double backward
79
+ // (!GradMode::is_enabled()), AccumulateGrad performs "variable_grad +=
80
+ // new_grad" in-place, which keeps variable_grad's layout. We assume (hope)
81
+ // variable_grad was created obeying (1) or (2) at some point in the past.
82
+ //
83
+ // If we are setting up for double backward, AccumulateGrad updates the grad
84
+ // out-of-place via "variable_grad + new_grad." TensorIterator operator+
85
+ // decides result's layout. Typically TensorIterator matches strides of the
86
+ // first arg, so we once again assume (hope) variable_grad was originally
87
+ // created obeying (1) or (2).
88
+ //
89
+ // AccumulateGrad does not enforce the contract with 100% certainty. Examples:
90
+ // - If a user manually permutes a param or its grad, then runs a fwd+bwd,
91
+ // variable_grad += new_grad keeps variable_grad's layout without
92
+ // rechecking the contract.
93
+ // - If TensorIterator changes its corner cases about operator+'s result
94
+ // (for example, giving more or less priority to channels_last inputs, see
95
+ // https://github.com/pytorch/pytorch/pull/37968) the result may not obey.
96
+ //
97
+ // Fortunately, if a given grad doesn't satisfy (1) or (2), the penalty is
98
+ // degraded performance in Reducer.cpp or optimizer kernels, not death by
99
+ // assert or silently bad numerics.
100
+
101
+ // Gradient Accumulation
102
+ // Given a variable with its current grad as variable_grad, accumulates
103
+ // new_grad into variable_grad if in place accumulation is possible.
104
+ // Otherwise, uses 'update_grad' to update the grad for the variable.
105
+ //
106
+ // Branch breakdown:
107
+ // - Case 1: Param has no existing grad
108
+ // - Case 1.1: Stealable dense new_grad
109
+ // . We aren't setting up for double-backward.
110
+ // . No other user-visible tensor references new_grad.
111
+ // . new_grad obeys the "Gradient Layout Contract", there has a special
112
+ // case, For MKLDNN tensor, which is a opaque tensor, assuming it obeys
113
+ // layout_contract.
114
+ // - Case 1.2: Stealable sparse new_grad
115
+ // . Can't detach sparse tensor (since metadata changes are not allowed
116
+ // after detach), so just create a new one for the grad which is a
117
+ // shallow copy. We need a shallow copy so that modifying the original
118
+ // grad tensor doesn't modify the grad we accumulate.
119
+ // . We only skip clone if indices and values themselves are contiguous
120
+ // for backward compatibility reasons. Since without this optimization,
121
+ // earlier we would clone the entire SparseTensor which cloned indices
122
+ // and values. For details see
123
+ // https://github.com/pytorch/pytorch/issues/34375.
124
+ // - Case 1.3: Cloning sparse/nested new_grad
125
+ // - Case 1.4: Cloning MKLDNN new_grad
126
+ // - Case 1.5: Deep copies new_grad according to the Gradient Layout
127
+ // Contract.
128
+ // - Case 2: Param has existing grad and grad mode is not enabled
129
+ // - This case is not strictly necessary, but it makes the first-order only
130
+ // case slightly more efficient.
131
+ // - Case 2.1: Sparse variable_grad + Dense new_grad
132
+ // . If `variable_grad` is sparse and `new_grad` is not sparse, their
133
+ // sum is not sparse, and we must change the TensorImpl type of
134
+ // `variable_grad` for it to store the result. However, changing the
135
+ // TensorImpl type of a tensor requires changing the tensor itself, and
136
+ // thus in this case we have to change the grad tensor.
137
+ // - Case 2.2: Vmap-incompatible
138
+ // . Ideally we'd perform an in-place operation to avoid changing
139
+ // the grad tensor. However, if that's impossible because the grads
140
+ // are vmap-incompatible (See NOTE: [vmap-incompatible in-place
141
+ // operations]), then we just add them out-of-place.
142
+ // - Case 2.3: In-place addition
143
+ // . In this case we can avoid changing the grad tensor. There are three
144
+ // scenarios when we'll hit this case:
145
+ // . `variable_grad` is sparse, and `new_grad` is sparse.
146
+ // . `variable_grad` is dense, and `new_grad` is sparse.
147
+ // . `variable_grad` is dense, and `new_grad` is dense.
148
+ // . `variable_grad` is mkldnn, and `new_grad` is mkldnn.
149
+ //
150
+ // In all of these four cases, `variable_grad += new_grad` is a
151
+ // valid operation which adds `new_grad` to `variable_grad` in
152
+ // place. `variable_grad` is thus still referring to the same tensor
153
+ // after the operation.
154
+ // . DistributedDataParallel(DDP) package relies on grad being
155
+ // mutated in place for saving peak memory usage. DDP will still
156
+ // work correctly if it is mutated out of place here, but DDP will
157
+ // maintain one extra copy of grad tensors in buffer and thus
158
+ // increase peak memory usage.
159
+ // - Case 3: Param has existing grad and grad mode is enabled
160
+ // - Case 3.1: Sparse variable_grad + Dense new_grad
161
+ // - Case 3.2: Not Sparse variable_grad + Dense new_grad
162
+ //
163
+ // variable: the variable whose grad we're accumulating.
164
+ // variable_grad: the current grad for the variable.
165
+ // new_grad: new grad we want to accumulate for the variable.
166
+ // num_expected_refs: the number of refs we expect to hold internally
167
+ // such that it is safe to avoid cloning the grad
168
+ // if use_count() of the grad is less than or equal
169
+ // to this value (in addition to post_hooks).
170
+ // update_grad: Function that is used to update grad for the variable.
171
+ // The argument to the function is a Tensor which
172
+ // is used to set a new value for the grad.
173
+ template <typename T>
174
+ static void accumulateGrad(
175
+ const Variable& variable,
176
+ at::Tensor& variable_grad,
177
+ const at::Tensor& new_grad,
178
+ size_t num_expected_refs,
179
+ const T& update_grad) {
180
+ if (!variable_grad.defined()) {
181
+ if (!GradMode::is_enabled() && !new_grad.is_sparse() &&
182
+ !new_grad.is_sparse_csr() &&
183
+ !(variable.is_sparse_csr() && new_grad.layout() == at::kStrided) &&
184
+ impl::is_tensor_stealable(
185
+ new_grad,
186
+ num_expected_refs + at::caching::is_cached_tensor(new_grad)) &&
187
+ (new_grad.is_mkldnn() ||
188
+ utils::obeys_layout_contract(new_grad, variable))) {
189
+ // See Case 1.1: Stealable dense new_grad
190
+ update_grad(new_grad.detach());
191
+ } else if (
192
+ !GradMode::is_enabled() && new_grad.is_sparse() &&
193
+ new_grad._indices().is_contiguous() &&
194
+ new_grad._values().is_contiguous() &&
195
+ // Use count for indices and values should always be <=1 since the
196
+ // SparseTensor should be the only one holding a reference to these.
197
+ new_grad._indices().use_count() <= 1 &&
198
+ new_grad._values().use_count() <= 1 &&
199
+ impl::is_tensor_stealable(new_grad, num_expected_refs)) {
200
+ // Case 1.2: Stealable sparse new_grad
201
+ // No scenario where we expect this to be true currently
202
+ TORCH_INTERNAL_ASSERT_DEBUG_ONLY(
203
+ !at::caching::is_cached_tensor(new_grad._indices()) &&
204
+ !at::caching::is_cached_tensor(new_grad._values()) &&
205
+ !at::caching::is_cached_tensor(new_grad));
206
+
207
+ update_grad(at::_sparse_coo_tensor_unsafe(
208
+ new_grad._indices(),
209
+ new_grad._values(),
210
+ new_grad.sizes(),
211
+ new_grad.options()));
212
+ } else {
213
+ if (new_grad.is_sparse() || new_grad.is_sparse_csr() ||
214
+ new_grad.is_nested()) {
215
+ // Case 1.3: Cloning sparse/nested new_grad
216
+ update_grad(new_grad.clone());
217
+ } else {
218
+ if (new_grad.is_mkldnn()) {
219
+ // Case 1.4: Cloning MKLDNN new_grad
220
+ update_grad(new_grad.clone());
221
+ } else {
222
+ // Case 1.5: Deep copies new_grad according to the "Gradient
223
+ // Layout Contract."
224
+ update_grad(utils::clone_obey_contract(new_grad, variable));
225
+ }
226
+ }
227
+ }
228
+ } else if (!GradMode::is_enabled()) {
229
+ // Case 2: Param has existing grad and grad mode is not enabled
230
+ if (variable_grad.is_sparse() && !new_grad.is_sparse()) {
231
+ // Case 2.1: Sparse variable_grad + Dense new_grad
232
+ auto result = new_grad + variable_grad;
233
+ CHECK_RESULT(result, variable);
234
+ update_grad(std::move(result));
235
+ } else if (!at::inplaceIsVmapCompatible(variable_grad, new_grad)) {
236
+ // Case 2.2: Vmap-incompatible
237
+ auto result = variable_grad + new_grad;
238
+ CHECK_RESULT(result, variable);
239
+ update_grad(std::move(result));
240
+ } else {
241
+ // Case 2.3: In-place addition
242
+ variable_grad += new_grad;
243
+ CHECK_RESULT(variable_grad, variable);
244
+ // ^ We could enforce the contract more aggressively here by writing:
245
+ // if (variable_grad.is_sparse() || new_grad.is_sparse()) {
246
+ // variable_grad += new_grad;
247
+ // } else if (obeys_layout_contract(variable_grad, variable)) {
248
+ // variable_grad += new_grad;
249
+ // } else {
250
+ // result = at::empty_strided(variable.sizes(), variable.strides(),
251
+ // variable.options().memory_format(std::nullopt));
252
+ // update_grad(at::native::add_out(result, variable_grad,
253
+ // new_grad, 1.0);
254
+ // }
255
+ // However, that accumulation is sometimes in place and sometimes not,
256
+ // which may break user code.
257
+ }
258
+ } else {
259
+ // Case 3: Param has existing grad and grad mode is enabled
260
+ at::Tensor result;
261
+ if (variable_grad.is_sparse() && !new_grad.is_sparse()) {
262
+ // Case 3.1: Sparse variable_grad + Dense new_grad
263
+ // CPU backend throws an error on sparse + dense, so
264
+ // prefer dense + sparse here.
265
+ result = new_grad + variable_grad;
266
+ } else {
267
+ // Case 3.2: Not Sparse variable_grad + Dense new_grad
268
+ // Assumes operator+ result typically matches strides of first arg,
269
+ // and hopes variable_grad was originally created obeying layout
270
+ // contract.
271
+ result = variable_grad + new_grad;
272
+ }
273
+ CHECK_RESULT(result, variable);
274
+ update_grad(std::move(result));
275
+ // ^ We could enforce the contract more aggressively here by saying
276
+ // if (obeys_layout_contract(new_grad, variable)) {
277
+ // update_grad(new_grad + variable_grad);
278
+ // } else {
279
+ // update_grad(variable_grad + new_grad);
280
+ // }
281
+ // such that the stashed grad is likely to have the right strides if
282
+ // either variable_grad or new_grad already has the right strides.
283
+ // We could enforce the contract with certainty by saying
284
+ // auto result = variable_grad + new_grad (or vice versa), checking
285
+ // result's layout, and copying to an obedient clone if necessary before
286
+ // update_grad. The copy would require another gmem pass. We can't create
287
+ // empty result with the right layout then add_out into it with a single
288
+ // kernel, because GradMode is enabled in this branch, and add_out isn't
289
+ // differentiable. Maybe more trouble than it's worth.
290
+ }
291
+ }
292
+
293
+ void compiled_args(CompiledNodeArgs& args) const override;
294
+ variable_list apply_with_saved(
295
+ const variable_list& inputs,
296
+ SwapSavedVariables& saved) override;
297
+
298
+ Variable variable;
299
+ };
300
+
301
+ #undef CHECK_RESULT
302
+
303
+ } // namespace torch::autograd
304
+
305
+ #else
306
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
307
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/basic_ops.h ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <c10/util/irange.h>
5
+ #include <torch/csrc/Export.h>
6
+ #include <torch/csrc/autograd/function.h>
7
+ #include <torch/csrc/autograd/variable.h>
8
+
9
+ #include <memory>
10
+ #include <string>
11
+ #include <vector>
12
+
13
+ namespace torch::autograd {
14
+
15
+ struct TORCH_API Error : public Node {
16
+ Error(std::string msg, edge_list&& next_edges)
17
+ : Node(std::move(next_edges)), msg(std::move(msg)) {}
18
+
19
+ Error(std::string msg) : msg(std::move(msg)) {}
20
+
21
+ variable_list apply(variable_list&& inputs) override;
22
+ variable_list apply(variable_list&& inputs) const;
23
+
24
+ void compiled_args(CompiledNodeArgs& args) const override;
25
+ variable_list apply_with_saved(
26
+ const variable_list& inputs,
27
+ SwapSavedVariables& saved) override;
28
+
29
+ std::string msg;
30
+ };
31
+
32
+ // We print grad_fn names in tensor printing. For functions with backward
33
+ // NYI, grad_fn=<Error> will be printed if we use Error, which is confusing. So
34
+ // special case with a new NotImplemented function here.
35
+ struct TORCH_API NotImplemented : public Error {
36
+ NotImplemented(const std::string& forward_fn, edge_list&& next_edges)
37
+ : Error(
38
+ "derivative for " + forward_fn + " is not implemented",
39
+ std::move(next_edges)) {}
40
+
41
+ NotImplemented(const std::string& forward_fn)
42
+ : Error("derivative for " + forward_fn + " is not implemented") {}
43
+ };
44
+
45
+ // Identity in forward, Error in backward. Used to implement
46
+ // @once_differentiable
47
+ struct TORCH_API DelayedError : public Node {
48
+ DelayedError(std::string msg, int64_t num_inputs) : msg(std::move(msg)) {
49
+ for ([[maybe_unused]] const auto _ [[maybe_unused]] :
50
+ c10::irange(num_inputs)) {
51
+ add_input_metadata(Node::undefined_input());
52
+ }
53
+ }
54
+
55
+ variable_list apply(variable_list&& inputs) override;
56
+ variable_list apply(variable_list&& inputs) const;
57
+
58
+ std::string msg;
59
+ };
60
+
61
+ struct TORCH_API UndefinedGrad : public Node {
62
+ UndefinedGrad() {
63
+ add_input_metadata(Node::undefined_input());
64
+ }
65
+
66
+ variable_list apply(variable_list&& inputs) override;
67
+ variable_list apply(variable_list&& inputs) const;
68
+ };
69
+
70
+ struct TORCH_API UndefinedGradBackward : public Node {
71
+ UndefinedGradBackward(edge_list&& next_edges) : Node(std::move(next_edges)) {}
72
+
73
+ UndefinedGradBackward() = default;
74
+
75
+ variable_list apply(variable_list&& inputs) override;
76
+ variable_list apply(variable_list&& inputs) const;
77
+
78
+ void compiled_args(CompiledNodeArgs& args) const override {}
79
+ variable_list apply_with_saved(
80
+ const variable_list& inputs,
81
+ SwapSavedVariables& saved) override {
82
+ return apply(variable_list(inputs));
83
+ }
84
+ };
85
+
86
+ struct TORCH_API GraphRoot : public Node {
87
+ GraphRoot(edge_list functions, variable_list inputs)
88
+ : Node(std::move(functions)), outputs(std::move(inputs)) {
89
+ // Ensures calls to stream() on a GraphRoot instance reflect current
90
+ // stream(s) on devices of root grad tensors at the time the instance is
91
+ // constructed.
92
+ for (const auto& t : outputs) {
93
+ add_input_metadata(t);
94
+ }
95
+ }
96
+
97
+ variable_list apply(variable_list&& inputs) override {
98
+ return outputs;
99
+ }
100
+
101
+ void compiled_args(CompiledNodeArgs& args) const override;
102
+ variable_list apply_with_saved(
103
+ const variable_list& inputs,
104
+ SwapSavedVariables& saved) override;
105
+
106
+ variable_list outputs;
107
+ };
108
+
109
+ struct TORCH_API Identity : public Node {
110
+ variable_list apply(variable_list&& inputs) override;
111
+ };
112
+
113
+ } // namespace torch::autograd
114
+
115
+ #else
116
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
117
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/comm.h ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/Export.h>
5
+ #include <torch/csrc/autograd/function.h>
6
+ #include <torch/csrc/autograd/variable.h>
7
+
8
+ #include <ATen/ATen.h>
9
+ #include <c10/cuda/CUDAStream.h>
10
+ #include <optional>
11
+
12
+ #include <cstddef>
13
+ #include <vector>
14
+
15
+ namespace torch::autograd {
16
+
17
+ struct TORCH_CUDA_CU_API Scatter : public Node {
18
+ explicit Scatter(
19
+ std::vector<at::Device> devices,
20
+ std::optional<std::vector<int64_t>> chunk_sizes = std::nullopt,
21
+ int64_t dim = 0,
22
+ std::optional<std::vector<std::optional<at::cuda::CUDAStream>>> streams =
23
+ std::nullopt,
24
+ bool unsqueeze_scalars = false);
25
+ ~Scatter() override;
26
+
27
+ variable_list apply(variable_list&& inputs) override;
28
+
29
+ std::vector<at::Device> devices_;
30
+ std::optional<std::vector<int64_t>> chunk_sizes_;
31
+ int64_t dim_;
32
+ std::optional<std::vector<std::optional<at::cuda::CUDAStream>>> streams_;
33
+ bool unsqueeze_scalars_;
34
+ };
35
+
36
+ struct TORCH_CUDA_CU_API Gather : public Node {
37
+ explicit Gather(const at::Device& destination_device, int64_t dim = 0);
38
+ ~Gather() override;
39
+
40
+ variable_list apply(variable_list&& inputs) override;
41
+
42
+ at::Device destination_device_;
43
+ int64_t dim_;
44
+ };
45
+
46
+ } // namespace torch::autograd
47
+
48
+ #else
49
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
50
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/pybind.h ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <pybind11/pybind11.h>
5
+ #include <pybind11/stl.h>
6
+ #include <torch/csrc/python_headers.h>
7
+ #include <torch/csrc/utils/pybind.h>
8
+
9
+ #include <torch/csrc/autograd/python_cpp_function.h>
10
+ #include <torch/csrc/autograd/python_function.h>
11
+
12
+ // NOLINTNEXTLINE(misc-unused-alias-decls)
13
+ namespace py = pybind11;
14
+
15
+ namespace pybind11::detail {} // namespace pybind11::detail
16
+
17
+ #else
18
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
19
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/tensor.h ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/Export.h>
5
+ #include <torch/csrc/autograd/function.h>
6
+ #include <torch/csrc/autograd/variable.h>
7
+
8
+ #include <ATen/TensorGeometry.h>
9
+ #include <ATen/core/DeprecatedTypeProperties.h>
10
+ #include <optional>
11
+
12
+ #include <cstdint>
13
+ #include <memory>
14
+
15
+ namespace torch::autograd {
16
+
17
+ struct TORCH_API CopyBackwards : public Node {
18
+ variable_list apply(variable_list&& grads) override;
19
+ void compiled_args(CompiledNodeArgs& args) const override;
20
+ variable_list apply_with_saved(
21
+ const variable_list& inputs,
22
+ SwapSavedVariables& saved) override;
23
+
24
+ at::TensorOptions src_options;
25
+ };
26
+
27
+ // Note [View + Inplace update for base tensor]
28
+ //
29
+ // This note covers a few important topics related to view + inplace handling.
30
+ // - It explains what is the CopySlices Node and why we need it.
31
+ // - It explains the considerations on what is saved for backward in
32
+ // CopySlices.
33
+ // - It explains why we need to sometimes change the exec_info of the current
34
+ // backward
35
+ //
36
+ // What is CopySlices?
37
+ // ~~~~~~~~~~~~~~~~~~~
38
+ //
39
+ // We support autograd with inplace mutation; e.g., if you write x.mul_(2)
40
+ // the autograd will work as if you now had multiple Tensors under the hood and
41
+ // you did
42
+ // x = t.clone()
43
+ // x0 = x
44
+ // x1 = x0 * 2
45
+ // x = x1
46
+ // As you can see here, after this operation, x.grad_fn now points to x1.grad_fn
47
+ // (the MulBackward node) and this node points to x's original grad_fn (which is
48
+ // also x0.grad_fn). It is important to keep in mind that after the inplace,
49
+ // there is no Tensor object that represents the x0 state anymore. But the graph
50
+ // for it is still around in autograd (in case x was used before being modified
51
+ // inplace). See Example 1 in
52
+ // https://docs.google.com/drawings/d/1-T5DyYfChMX1ONQkY-zU-hj_ayQ2zmA5CBOKDWqvEhE
53
+ // We call this rebasing the history of the Tensor.
54
+ //
55
+ // Now, a difficult situation is what happens if x is a differentiable view
56
+ // of a base b.
57
+ // b = t.clone()
58
+ // x = b.select(0, 0)
59
+ // x *= 2
60
+ // With the same approach as above, this will become
61
+ // b = t.clone()
62
+ // x = b.select(0, 0)
63
+ // b0 = b
64
+ // x0 = x
65
+ // x1 = x0 * 2
66
+ // b1 = b0.select_scatter(x1, 0, 0)
67
+ // x2 = b1.select(0, 0)
68
+ // x = x2
69
+ // b = b1
70
+ // As you can see here, not only we need to modify x's grad_fn, we also need to
71
+ // modify the one from b. We also need to ensure that the new grad_fn on x is
72
+ // linked to b's new grad_fn. The chain the select_scatter, multiplication and
73
+ // select is what CopySlices does, all wrapped into a single Node.
74
+ //
75
+ // See Example 1 in
76
+ // https://docs.google.com/drawings/d/1-T5DyYfChMX1ONQkY-zU-hj_ayQ2zmA5CBOKDWqvEhE
77
+ //
78
+ // What do we need to save in CopySlices to run backward?
79
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80
+ //
81
+ // We need to perform grad_view = fn(grad_view), but out-of-place.
82
+ // view_fn_ is an optional function saved in DifferentiableViewMeta
83
+ // from forward pass, so that we can recover we when as_strided is not
84
+ // supported. It preserves the invariants:
85
+ // view = view_fn_(base)
86
+ // grad_view = view_fn_(grad_base)
87
+ //
88
+ // When as_strided is supported (e.g. strided CPU/CUDA Tensors), view_fn_
89
+ // is empty and we save TensorGeometry(view) instead.
90
+ // With the TensorGeometry information we can use `as_strided` call which
91
+ // is more efficient to recover views in backward.
92
+ //
93
+ // For example:
94
+ // view_1 = view_op_1(base)
95
+ // view_2 = view_op_2(view_1)
96
+ // ...
97
+ // view_n = view_op_n(view_n-1)
98
+ // view_n = inplace_op(view_n)
99
+ //
100
+ // In CPU/CUDA case where we support efficient as_strided implementation,
101
+ // grad_view_n can be calculated through 1 step.
102
+ //
103
+ // grad_view_n = grad_base.as_strided(view_sizes, view_strides, view_offset);
104
+ //
105
+ // But in XLA backend where we don't have full support of as_strided,
106
+ // it has to save a chained lambda function view_fn_, to exactly
107
+ // replay how the view was done in forward.
108
+ //
109
+ // view_fn_ = view_op_n(...(view_op_2(view_op_1())))
110
+ // grad_view_n = view_fn_(grad_base)
111
+ //
112
+ // This chain view_fn_ works as long as forward view ops are implemented,
113
+ // e.g XLA simulates view without a real Storage behind Tensor, but it's less
114
+ // efficient than the as_strided one so we should be careful to only use it when
115
+ // necessary.
116
+ //
117
+ // - For CPU/CUDA we save TensorGeometry of both base and view tensors,
118
+ // That's all we need to pass into as_strided.
119
+ // E.g. int[] sizes, int[] strides, and int storage_offset.
120
+ // - For XLA we use view_fn_, which captures all forward view op arguments
121
+ // by **value**.
122
+ // E.g for at::narrow, int dim, int start, in length are saved.
123
+ //
124
+ // Theoretically we could also save Tensor `view` in CopySlices Node, but
125
+ // it's far more expensive than what we currently save.
126
+ // 1. We cannot afford keeping large tensors alive to recover views only.
127
+ // 2. There are inplace checks when Tensors are loaded back to make sure
128
+ // they haven't been changed (including size metadata).
129
+ // So saving metadata like TensorGeometry/view arguments is much better
130
+ // because it is minimal information needed to recover views, as well as it
131
+ // allows the user to modify the original Tensor without preventing the
132
+ // backward pass from running.
133
+ //
134
+ // Why do we manually change exec_info in the apply?
135
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136
+ //
137
+ // Using the same example as before,
138
+ // b = t.clone()
139
+ // x = b.select(0, 0)
140
+ // x *= y
141
+ //
142
+ // You can see the visualization at
143
+ // https://docs.google.com/drawings/d/1Bx-Hcz-zlIv7PabQqnPhUIVIs9F8WWi48svqMsAUMFs
144
+ // which contains the wrapped MulBackward Node and show what it links to.
145
+ // Since a backward can happen between any subset of the inputs (t and y) and
146
+ // outputs (o, x, b). It is possible to get into a state where CopySlices's 0th
147
+ // next function (CloneBackward) needs gradient but MulBackward's 0th next
148
+ // function (SelectBackward) is not. This happens if you do autograd.grad
149
+ // between x and t for example.
150
+ // In such a case, we do need to mark SelectBackward as requiring gradient such
151
+ // that, during the execution of MulBackward, we will actually compute gradient
152
+ // for the 0th input.
153
+ //
154
+ // All the other next functions are always shared (this is asserted in the apply
155
+ // code) and so nothing needs to be done for them.
156
+
157
+ // See Note [View + Inplace update for view tensor] for what we do to view
158
+ // tensor when an in-place operation happens.
159
+ struct TORCH_API CopySlices : public Node {
160
+ CopySlices(
161
+ const Variable& base_var,
162
+ at::TensorGeometry view_,
163
+ std::unique_ptr<ViewFunc> view_fn_,
164
+ std::shared_ptr<Node> fn_);
165
+
166
+ // common code between apply/apply_with_saved
167
+ template <typename T>
168
+ variable_list apply_impl(variable_list&& inputs, const T& call_fn);
169
+
170
+ variable_list apply(variable_list&& inputs) override;
171
+ void release_variables() override;
172
+ void compiled_args(CompiledNodeArgs& args) const override;
173
+ variable_list apply_with_saved(
174
+ const variable_list& inputs,
175
+ SwapSavedVariables& saved) override;
176
+ void update_exec_info();
177
+
178
+ at::TensorGeometry base;
179
+ // view and view_fn are redundant and view_fn will be used if available.
180
+ // See Note [View + Inplace update for base tensor] for details.
181
+ at::TensorGeometry view;
182
+ std::unique_ptr<ViewFunc> view_fn;
183
+ std::shared_ptr<Node> fn;
184
+ };
185
+
186
+ } // namespace torch::autograd
187
+
188
+ #else
189
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
190
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/functions/utils.h ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/Export.h>
5
+ #include <torch/csrc/autograd/InferenceMode.h>
6
+ #include <torch/csrc/autograd/autograd.h>
7
+ #include <torch/csrc/autograd/function.h>
8
+ #include <torch/csrc/autograd/variable.h>
9
+ #include <torch/csrc/utils/variadic.h>
10
+
11
+ #include <ATen/core/Tensor.h>
12
+
13
+ #include <functional>
14
+ #include <memory>
15
+ #include <vector>
16
+
17
+ namespace torch::autograd {
18
+
19
+ using function_constructor = std::function<std::shared_ptr<Node>(edge_list&&)>;
20
+
21
+ /**
22
+ * Wraps the tensor outputs in variables and creates the grad_fn and sets the
23
+ * grad_fn if necessary.
24
+ */
25
+ TORCH_API variable_list wrap_outputs(
26
+ const variable_list& inputs,
27
+ tensor_list&& outputs,
28
+ const function_constructor& ctr);
29
+
30
+ /// Checks that inputs contains exactly `args` items and that the first
31
+ /// `required_args`
32
+ /// items are not nullptr. If not specified, `required_args` defaults to `args`.
33
+ TORCH_API void check_input_variables(
34
+ const char* name,
35
+ const variable_list& inputs,
36
+ int args,
37
+ int required_args = -1,
38
+ bool allow_undefined = false);
39
+
40
+ struct ComputeRequiresGrad : IterArgs<ComputeRequiresGrad> {
41
+ bool out = false;
42
+ using IterArgs<ComputeRequiresGrad>::operator();
43
+ void operator()(const at::Tensor& tensor) {
44
+ const auto& var = static_cast<const Variable&>(tensor);
45
+ if (var.defined() && var.requires_grad()) {
46
+ out = true;
47
+ }
48
+ }
49
+ void operator()(const std::optional<at::Tensor>& tensor) {
50
+ if (tensor.has_value()) {
51
+ (*this)(*tensor);
52
+ }
53
+ }
54
+ bool short_circuit() {
55
+ return out;
56
+ }
57
+ };
58
+
59
+ template <typename... Args>
60
+ inline bool compute_requires_grad(Args&&... args) {
61
+ if (!GradMode::is_enabled()) {
62
+ return false;
63
+ }
64
+ return ComputeRequiresGrad().apply(std::forward<Args>(args)...).out;
65
+ }
66
+
67
+ inline void set_history(
68
+ const at::Tensor& variable,
69
+ const std::shared_ptr<Node>& grad_fn) {
70
+ TORCH_CHECK(grad_fn != nullptr);
71
+ if (variable.defined()) {
72
+ // If the codegen triggers this, you most likely want to add your newly
73
+ // added function to the DONT_REQUIRE_DERIVATIVE list in
74
+ // tools/autograd/gen_variable_type.py
75
+ TORCH_CHECK(
76
+ isDifferentiableType(variable.scalar_type()),
77
+ "Autograd not support dtype: ",
78
+ variable.scalar_type());
79
+ auto output_nr = grad_fn->add_input_metadata(variable);
80
+ impl::set_gradient_edge(variable, {grad_fn, output_nr});
81
+ } else {
82
+ grad_fn->add_input_metadata(Node::undefined_input());
83
+ }
84
+ }
85
+
86
+ inline void set_history(
87
+ const std::vector<Variable>& variables,
88
+ const std::shared_ptr<Node>& grad_fn) {
89
+ for (auto& variable : variables) {
90
+ set_history(variable, grad_fn);
91
+ }
92
+ }
93
+
94
+ inline bool isFwGradDefined(const std::optional<at::Tensor>& t) {
95
+ return t.has_value() && t->defined() && t->_fw_grad(/*level */ 0).defined();
96
+ }
97
+
98
+ inline bool isFwGradDefinedTensorList(const at::ITensorListRef& variables) {
99
+ bool ret = false;
100
+ for (auto& variable : variables) {
101
+ ret |= isFwGradDefined(variable);
102
+ }
103
+ return ret;
104
+ }
105
+
106
+ inline bool isFwGradDefinedTensorList(
107
+ const c10::List<std::optional<at::Tensor>>& li) {
108
+ bool ret = false;
109
+ for (auto i : c10::irange(li.size())) {
110
+ auto t = li.get(i);
111
+ ret |= isFwGradDefined(t);
112
+ }
113
+ return ret;
114
+ }
115
+
116
+ } // namespace torch::autograd
117
+
118
+ #else
119
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
120
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/Functions.h ADDED
The diff for this file is too large to render. See raw diff
 
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/VariableType.h ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated from ../tools/autograd/templates/VariableType.h
5
+
6
+ #include <ATen/core/Tensor.h>
7
+ #include <ATen/Context.h>
8
+
9
+ #include <c10/util/intrusive_ptr.h>
10
+
11
+ #include <torch/csrc/Export.h>
12
+ #include <torch/csrc/autograd/autograd_not_implemented_fallback.h>
13
+
14
+ #include <cstdint> // for size_t
15
+ #include <functional> // for function
16
+ #include <memory> // for unique_ptr
17
+ #include <string>
18
+ #include <vector>
19
+
20
+ namespace at {
21
+ struct Quantizer;
22
+ }
23
+
24
+ namespace torch { namespace autograd {
25
+
26
+ using Variable = at::Tensor;
27
+ using at::Context;
28
+ using at::Device;
29
+ using at::Dimname;
30
+ using at::DimnameList;
31
+ using at::Generator;
32
+ using at::IntArrayRef;
33
+ using at::MemoryFormat;
34
+ using at::QScheme;
35
+ using at::Scalar;
36
+ using at::ScalarType;
37
+ using at::Storage;
38
+ using at::Tensor;
39
+ using at::TensorList;
40
+ using at::TensorOptions;
41
+ using at::Quantizer;
42
+ using std::optional;
43
+
44
+ namespace VariableType {
45
+ TORCH_API std::vector<at::DeprecatedTypeProperties*> allCUDATypes();
46
+ TORCH_API std::vector<at::DeprecatedTypeProperties*> allXPUTypes();
47
+ TORCH_API std::vector<at::DeprecatedTypeProperties*> allCPUTypes();
48
+ TORCH_API std::vector<at::DeprecatedTypeProperties*> allPrivateUser1Types();
49
+
50
+ at::Tensor & unpack(Tensor & t, const char * name, int pos);
51
+ const at::Tensor & unpack(const Tensor & t, const char * name, int pos);
52
+ at::Tensor unpack_opt(const Tensor & t, const char * name, int pos);
53
+ std::vector<at::Tensor> unpack(const at::ITensorListRef& tl, const char *name, int pos);
54
+ }
55
+
56
+ }} // namespace torch::autograd
57
+
58
+ #else
59
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
60
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/ViewFuncs.h ADDED
@@ -0,0 +1,960 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated from ../tools/autograd/templates/ViewFuncs.h
5
+
6
+ #include <torch/library.h>
7
+ #include <torch/csrc/autograd/variable.h>
8
+ #include <c10/core/SymIntArrayRef.h>
9
+
10
+ #ifndef AT_PER_OPERATOR_HEADERS
11
+ #include <ATen/Operators.h>
12
+ #else
13
+ #include <ATen/ops/_conj_ops.h>
14
+ #include <ATen/ops/_indices_ops.h>
15
+ #include <ATen/ops/_neg_view_ops.h>
16
+ #include <ATen/ops/_nested_get_values_ops.h>
17
+ #include <ATen/ops/_nested_view_from_buffer_ops.h>
18
+ #include <ATen/ops/_nested_view_from_jagged_ops.h>
19
+ #include <ATen/ops/_reshape_alias_ops.h>
20
+ #include <ATen/ops/_test_autograd_multiple_dispatch_view_ops.h>
21
+ #include <ATen/ops/_values_ops.h>
22
+ #include <ATen/ops/alias_ops.h>
23
+ #include <ATen/ops/as_strided_ops.h>
24
+ #include <ATen/ops/ccol_indices_ops.h>
25
+ #include <ATen/ops/chunk_ops.h>
26
+ #include <ATen/ops/col_indices_ops.h>
27
+ #include <ATen/ops/crow_indices_ops.h>
28
+ #include <ATen/ops/diagonal_ops.h>
29
+ #include <ATen/ops/expand_ops.h>
30
+ #include <ATen/ops/indices_ops.h>
31
+ #include <ATen/ops/narrow_ops.h>
32
+ #include <ATen/ops/permute_ops.h>
33
+ #include <ATen/ops/row_indices_ops.h>
34
+ #include <ATen/ops/select_ops.h>
35
+ #include <ATen/ops/slice_ops.h>
36
+ #include <ATen/ops/slice_inverse_ops.h>
37
+ #include <ATen/ops/split_ops.h>
38
+ #include <ATen/ops/split_with_sizes_ops.h>
39
+ #include <ATen/ops/squeeze_ops.h>
40
+ #include <ATen/ops/squeeze_ops.h>
41
+ #include <ATen/ops/squeeze_ops.h>
42
+ #include <ATen/ops/t_ops.h>
43
+ #include <ATen/ops/transpose_ops.h>
44
+ #include <ATen/ops/unbind_ops.h>
45
+ #include <ATen/ops/unfold_ops.h>
46
+ #include <ATen/ops/unsqueeze_ops.h>
47
+ #include <ATen/ops/values_ops.h>
48
+ #include <ATen/ops/view_ops.h>
49
+ #include <ATen/ops/view_ops.h>
50
+ #include <ATen/ops/view_as_complex_ops.h>
51
+ #include <ATen/ops/view_as_real_ops.h>
52
+ #endif
53
+
54
+ namespace torch::autograd::generated {
55
+
56
+ using at::Scalar;
57
+ using at::Tensor;
58
+ using at::IntArrayRef;
59
+ using at::ArrayRef;
60
+ using at::Type;
61
+ using at::ScalarType;
62
+ using std::optional;
63
+ using c10::fmap;
64
+
65
+ #define _CONJ_VIEW_FUNC_AVAILABLE
66
+ struct _ConjViewFunc : public torch::autograd::ViewFunc {
67
+ _ConjViewFunc()
68
+ {}
69
+ virtual ~_ConjViewFunc() override = default;
70
+ virtual std::vector<c10::SymInt> get_symints() const override;
71
+ virtual size_t num_symints() const override;
72
+ virtual std::vector<at::Tensor> get_tensors() const override;
73
+ virtual size_t num_tensors() const override;
74
+ virtual at::Tensor operator()(const at::Tensor&) const override;
75
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
76
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
77
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
78
+
79
+ protected:
80
+ virtual void set_symints(std::vector<c10::SymInt>) override;
81
+ virtual void set_tensors(std::vector<at::Tensor>) override;
82
+
83
+ private:
84
+
85
+ };
86
+
87
+ #define _INDICES_VIEW_FUNC_AVAILABLE
88
+ struct _IndicesViewFunc : public torch::autograd::ViewFunc {
89
+ _IndicesViewFunc()
90
+ {}
91
+ virtual ~_IndicesViewFunc() override = default;
92
+ virtual std::vector<c10::SymInt> get_symints() const override;
93
+ virtual size_t num_symints() const override;
94
+ virtual std::vector<at::Tensor> get_tensors() const override;
95
+ virtual size_t num_tensors() const override;
96
+ virtual at::Tensor operator()(const at::Tensor&) const override;
97
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
98
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
99
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
100
+
101
+ protected:
102
+ virtual void set_symints(std::vector<c10::SymInt>) override;
103
+ virtual void set_tensors(std::vector<at::Tensor>) override;
104
+
105
+ private:
106
+
107
+ };
108
+
109
+ #define _NEG_VIEW_VIEW_FUNC_AVAILABLE
110
+ struct _NegViewViewFunc : public torch::autograd::ViewFunc {
111
+ _NegViewViewFunc()
112
+ {}
113
+ virtual ~_NegViewViewFunc() override = default;
114
+ virtual std::vector<c10::SymInt> get_symints() const override;
115
+ virtual size_t num_symints() const override;
116
+ virtual std::vector<at::Tensor> get_tensors() const override;
117
+ virtual size_t num_tensors() const override;
118
+ virtual at::Tensor operator()(const at::Tensor&) const override;
119
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
120
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
121
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
122
+
123
+ protected:
124
+ virtual void set_symints(std::vector<c10::SymInt>) override;
125
+ virtual void set_tensors(std::vector<at::Tensor>) override;
126
+
127
+ private:
128
+
129
+ };
130
+
131
+ #define _NESTED_GET_VALUES_VIEW_FUNC_AVAILABLE
132
+ struct _NestedGetValuesViewFunc : public torch::autograd::ViewFunc {
133
+ _NestedGetValuesViewFunc()
134
+ {}
135
+ virtual ~_NestedGetValuesViewFunc() override = default;
136
+ virtual std::vector<c10::SymInt> get_symints() const override;
137
+ virtual size_t num_symints() const override;
138
+ virtual std::vector<at::Tensor> get_tensors() const override;
139
+ virtual size_t num_tensors() const override;
140
+ virtual at::Tensor operator()(const at::Tensor&) const override;
141
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
142
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
143
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
144
+
145
+ protected:
146
+ virtual void set_symints(std::vector<c10::SymInt>) override;
147
+ virtual void set_tensors(std::vector<at::Tensor>) override;
148
+
149
+ private:
150
+
151
+ };
152
+
153
+ #define _NESTED_VIEW_FROM_BUFFER_VIEW_FUNC_AVAILABLE
154
+ struct _NestedViewFromBufferViewFunc : public torch::autograd::ViewFunc {
155
+ _NestedViewFromBufferViewFunc(const at::Tensor & nested_size, const at::Tensor & nested_strides, const at::Tensor & offsets) : nested_size(nested_size), nested_strides(nested_strides), offsets(offsets)
156
+ {}
157
+ virtual ~_NestedViewFromBufferViewFunc() override = default;
158
+ virtual std::vector<c10::SymInt> get_symints() const override;
159
+ virtual size_t num_symints() const override;
160
+ virtual std::vector<at::Tensor> get_tensors() const override;
161
+ virtual size_t num_tensors() const override;
162
+ virtual at::Tensor operator()(const at::Tensor&) const override;
163
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
164
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
165
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
166
+
167
+ protected:
168
+ virtual void set_symints(std::vector<c10::SymInt>) override;
169
+ virtual void set_tensors(std::vector<at::Tensor>) override;
170
+
171
+ private:
172
+ at::Tensor nested_size;
173
+ at::Tensor nested_strides;
174
+ at::Tensor offsets;
175
+ };
176
+
177
+ #define _NESTED_VIEW_FROM_JAGGED_VIEW_FUNC_AVAILABLE
178
+ struct _NestedViewFromJaggedViewFunc : public torch::autograd::ViewFunc {
179
+ _NestedViewFromJaggedViewFunc(const at::Tensor & offsets, const at::Tensor & dummy, const ::std::optional<at::Tensor> & lengths, int64_t ragged_idx, const ::std::optional<at::Tensor> & min_seqlen, const ::std::optional<at::Tensor> & max_seqlen) : offsets(offsets), dummy(dummy), lengths(lengths), ragged_idx(ragged_idx), min_seqlen(min_seqlen), max_seqlen(max_seqlen)
180
+ {}
181
+ virtual ~_NestedViewFromJaggedViewFunc() override = default;
182
+ virtual std::vector<c10::SymInt> get_symints() const override;
183
+ virtual size_t num_symints() const override;
184
+ virtual std::vector<at::Tensor> get_tensors() const override;
185
+ virtual size_t num_tensors() const override;
186
+ virtual at::Tensor operator()(const at::Tensor&) const override;
187
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
188
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
189
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
190
+
191
+ protected:
192
+ virtual void set_symints(std::vector<c10::SymInt>) override;
193
+ virtual void set_tensors(std::vector<at::Tensor>) override;
194
+
195
+ private:
196
+ at::Tensor offsets;
197
+ at::Tensor dummy;
198
+ ::std::optional<at::Tensor> lengths;
199
+ int64_t ragged_idx;
200
+ ::std::optional<at::Tensor> min_seqlen;
201
+ ::std::optional<at::Tensor> max_seqlen;
202
+ };
203
+
204
+ #define _RESHAPE_ALIAS_VIEW_FUNC_AVAILABLE
205
+ struct _ReshapeAliasViewFunc : public torch::autograd::ViewFunc {
206
+ _ReshapeAliasViewFunc(c10::SymIntArrayRef size, c10::SymIntArrayRef stride) : size(size.vec()), stride(stride.vec())
207
+ {}
208
+ virtual ~_ReshapeAliasViewFunc() override = default;
209
+ virtual std::vector<c10::SymInt> get_symints() const override;
210
+ virtual size_t num_symints() const override;
211
+ virtual std::vector<at::Tensor> get_tensors() const override;
212
+ virtual size_t num_tensors() const override;
213
+ virtual at::Tensor operator()(const at::Tensor&) const override;
214
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
215
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
216
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
217
+
218
+ protected:
219
+ virtual void set_symints(std::vector<c10::SymInt>) override;
220
+ virtual void set_tensors(std::vector<at::Tensor>) override;
221
+
222
+ private:
223
+ ::std::vector<c10::SymInt> size;
224
+ ::std::vector<c10::SymInt> stride;
225
+ };
226
+
227
+ #define _TEST_AUTOGRAD_MULTIPLE_DISPATCH_VIEW_VIEW_FUNC_AVAILABLE
228
+ struct _TestAutogradMultipleDispatchViewViewFunc : public torch::autograd::ViewFunc {
229
+ _TestAutogradMultipleDispatchViewViewFunc()
230
+ {}
231
+ virtual ~_TestAutogradMultipleDispatchViewViewFunc() override = default;
232
+ virtual std::vector<c10::SymInt> get_symints() const override;
233
+ virtual size_t num_symints() const override;
234
+ virtual std::vector<at::Tensor> get_tensors() const override;
235
+ virtual size_t num_tensors() const override;
236
+ virtual at::Tensor operator()(const at::Tensor&) const override;
237
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
238
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
239
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
240
+
241
+ protected:
242
+ virtual void set_symints(std::vector<c10::SymInt>) override;
243
+ virtual void set_tensors(std::vector<at::Tensor>) override;
244
+
245
+ private:
246
+
247
+ };
248
+
249
+ #define _VALUES_VIEW_FUNC_AVAILABLE
250
+ struct _ValuesViewFunc : public torch::autograd::ViewFunc {
251
+ _ValuesViewFunc()
252
+ {}
253
+ virtual ~_ValuesViewFunc() override = default;
254
+ virtual std::vector<c10::SymInt> get_symints() const override;
255
+ virtual size_t num_symints() const override;
256
+ virtual std::vector<at::Tensor> get_tensors() const override;
257
+ virtual size_t num_tensors() const override;
258
+ virtual at::Tensor operator()(const at::Tensor&) const override;
259
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
260
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
261
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
262
+
263
+ protected:
264
+ virtual void set_symints(std::vector<c10::SymInt>) override;
265
+ virtual void set_tensors(std::vector<at::Tensor>) override;
266
+
267
+ private:
268
+
269
+ };
270
+
271
+ #define ALIAS_VIEW_FUNC_AVAILABLE
272
+ struct AliasViewFunc : public torch::autograd::ViewFunc {
273
+ AliasViewFunc()
274
+ {}
275
+ virtual ~AliasViewFunc() override = default;
276
+ virtual std::vector<c10::SymInt> get_symints() const override;
277
+ virtual size_t num_symints() const override;
278
+ virtual std::vector<at::Tensor> get_tensors() const override;
279
+ virtual size_t num_tensors() const override;
280
+ virtual at::Tensor operator()(const at::Tensor&) const override;
281
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
282
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
283
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
284
+
285
+ protected:
286
+ virtual void set_symints(std::vector<c10::SymInt>) override;
287
+ virtual void set_tensors(std::vector<at::Tensor>) override;
288
+
289
+ private:
290
+
291
+ };
292
+
293
+ #define AS_STRIDED_VIEW_FUNC_AVAILABLE
294
+ struct AsStridedViewFunc : public torch::autograd::ViewFunc {
295
+ AsStridedViewFunc(c10::SymIntArrayRef size, c10::SymIntArrayRef stride, ::std::optional<c10::SymInt> storage_offset) : size(size.vec()), stride(stride.vec()), storage_offset(storage_offset)
296
+ {}
297
+ virtual ~AsStridedViewFunc() override = default;
298
+ virtual std::vector<c10::SymInt> get_symints() const override;
299
+ virtual size_t num_symints() const override;
300
+ virtual std::vector<at::Tensor> get_tensors() const override;
301
+ virtual size_t num_tensors() const override;
302
+ virtual at::Tensor operator()(const at::Tensor&) const override;
303
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
304
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
305
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
306
+
307
+ protected:
308
+ virtual void set_symints(std::vector<c10::SymInt>) override;
309
+ virtual void set_tensors(std::vector<at::Tensor>) override;
310
+
311
+ private:
312
+ ::std::vector<c10::SymInt> size;
313
+ ::std::vector<c10::SymInt> stride;
314
+ ::std::optional<c10::SymInt> storage_offset;
315
+ };
316
+
317
+ #define CCOL_INDICES_VIEW_FUNC_AVAILABLE
318
+ struct CcolIndicesViewFunc : public torch::autograd::ViewFunc {
319
+ CcolIndicesViewFunc()
320
+ {}
321
+ virtual ~CcolIndicesViewFunc() override = default;
322
+ virtual std::vector<c10::SymInt> get_symints() const override;
323
+ virtual size_t num_symints() const override;
324
+ virtual std::vector<at::Tensor> get_tensors() const override;
325
+ virtual size_t num_tensors() const override;
326
+ virtual at::Tensor operator()(const at::Tensor&) const override;
327
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
328
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
329
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
330
+
331
+ protected:
332
+ virtual void set_symints(std::vector<c10::SymInt>) override;
333
+ virtual void set_tensors(std::vector<at::Tensor>) override;
334
+
335
+ private:
336
+
337
+ };
338
+
339
+ #define CHUNK_VIEW_FUNC_AVAILABLE
340
+ struct ChunkViewFunc : public torch::autograd::ViewFunc {
341
+ ChunkViewFunc(int64_t chunks, int64_t dim, int64_t view_idx) : chunks(chunks), dim(dim), view_idx(view_idx)
342
+ {}
343
+ virtual ~ChunkViewFunc() override = default;
344
+ virtual std::vector<c10::SymInt> get_symints() const override;
345
+ virtual size_t num_symints() const override;
346
+ virtual std::vector<at::Tensor> get_tensors() const override;
347
+ virtual size_t num_tensors() const override;
348
+ virtual at::Tensor operator()(const at::Tensor&) const override;
349
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
350
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
351
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
352
+
353
+ protected:
354
+ virtual void set_symints(std::vector<c10::SymInt>) override;
355
+ virtual void set_tensors(std::vector<at::Tensor>) override;
356
+
357
+ private:
358
+ int64_t chunks;
359
+ int64_t dim;
360
+ int64_t view_idx;
361
+ };
362
+
363
+ #define COL_INDICES_VIEW_FUNC_AVAILABLE
364
+ struct ColIndicesViewFunc : public torch::autograd::ViewFunc {
365
+ ColIndicesViewFunc()
366
+ {}
367
+ virtual ~ColIndicesViewFunc() override = default;
368
+ virtual std::vector<c10::SymInt> get_symints() const override;
369
+ virtual size_t num_symints() const override;
370
+ virtual std::vector<at::Tensor> get_tensors() const override;
371
+ virtual size_t num_tensors() const override;
372
+ virtual at::Tensor operator()(const at::Tensor&) const override;
373
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
374
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
375
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
376
+
377
+ protected:
378
+ virtual void set_symints(std::vector<c10::SymInt>) override;
379
+ virtual void set_tensors(std::vector<at::Tensor>) override;
380
+
381
+ private:
382
+
383
+ };
384
+
385
+ #define CROW_INDICES_VIEW_FUNC_AVAILABLE
386
+ struct CrowIndicesViewFunc : public torch::autograd::ViewFunc {
387
+ CrowIndicesViewFunc()
388
+ {}
389
+ virtual ~CrowIndicesViewFunc() override = default;
390
+ virtual std::vector<c10::SymInt> get_symints() const override;
391
+ virtual size_t num_symints() const override;
392
+ virtual std::vector<at::Tensor> get_tensors() const override;
393
+ virtual size_t num_tensors() const override;
394
+ virtual at::Tensor operator()(const at::Tensor&) const override;
395
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
396
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
397
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
398
+
399
+ protected:
400
+ virtual void set_symints(std::vector<c10::SymInt>) override;
401
+ virtual void set_tensors(std::vector<at::Tensor>) override;
402
+
403
+ private:
404
+
405
+ };
406
+
407
+ #define DIAGONAL_VIEW_FUNC_AVAILABLE
408
+ struct DiagonalViewFunc : public torch::autograd::ViewFunc {
409
+ DiagonalViewFunc(int64_t offset, int64_t dim1, int64_t dim2) : offset(offset), dim1(dim1), dim2(dim2)
410
+ {}
411
+ virtual ~DiagonalViewFunc() override = default;
412
+ virtual std::vector<c10::SymInt> get_symints() const override;
413
+ virtual size_t num_symints() const override;
414
+ virtual std::vector<at::Tensor> get_tensors() const override;
415
+ virtual size_t num_tensors() const override;
416
+ virtual at::Tensor operator()(const at::Tensor&) const override;
417
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
418
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
419
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
420
+
421
+ protected:
422
+ virtual void set_symints(std::vector<c10::SymInt>) override;
423
+ virtual void set_tensors(std::vector<at::Tensor>) override;
424
+
425
+ private:
426
+ int64_t offset;
427
+ int64_t dim1;
428
+ int64_t dim2;
429
+ };
430
+
431
+ #define EXPAND_VIEW_FUNC_AVAILABLE
432
+ struct ExpandViewFunc : public torch::autograd::ViewFunc {
433
+ ExpandViewFunc(c10::SymIntArrayRef size, bool implicit) : size(size.vec()), implicit(implicit)
434
+ {}
435
+ virtual ~ExpandViewFunc() override = default;
436
+ virtual std::vector<c10::SymInt> get_symints() const override;
437
+ virtual size_t num_symints() const override;
438
+ virtual std::vector<at::Tensor> get_tensors() const override;
439
+ virtual size_t num_tensors() const override;
440
+ virtual at::Tensor operator()(const at::Tensor&) const override;
441
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
442
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
443
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
444
+
445
+ protected:
446
+ virtual void set_symints(std::vector<c10::SymInt>) override;
447
+ virtual void set_tensors(std::vector<at::Tensor>) override;
448
+
449
+ private:
450
+ ::std::vector<c10::SymInt> size;
451
+ bool implicit;
452
+ };
453
+
454
+ #define INDICES_VIEW_FUNC_AVAILABLE
455
+ struct IndicesViewFunc : public torch::autograd::ViewFunc {
456
+ IndicesViewFunc()
457
+ {}
458
+ virtual ~IndicesViewFunc() override = default;
459
+ virtual std::vector<c10::SymInt> get_symints() const override;
460
+ virtual size_t num_symints() const override;
461
+ virtual std::vector<at::Tensor> get_tensors() const override;
462
+ virtual size_t num_tensors() const override;
463
+ virtual at::Tensor operator()(const at::Tensor&) const override;
464
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
465
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
466
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
467
+
468
+ protected:
469
+ virtual void set_symints(std::vector<c10::SymInt>) override;
470
+ virtual void set_tensors(std::vector<at::Tensor>) override;
471
+
472
+ private:
473
+
474
+ };
475
+
476
+ #define NARROW_VIEW_FUNC_AVAILABLE
477
+ struct NarrowViewFunc : public torch::autograd::ViewFunc {
478
+ NarrowViewFunc(int64_t dim, c10::SymInt start, c10::SymInt length) : dim(dim), start(start), length(length)
479
+ {}
480
+ virtual ~NarrowViewFunc() override = default;
481
+ virtual std::vector<c10::SymInt> get_symints() const override;
482
+ virtual size_t num_symints() const override;
483
+ virtual std::vector<at::Tensor> get_tensors() const override;
484
+ virtual size_t num_tensors() const override;
485
+ virtual at::Tensor operator()(const at::Tensor&) const override;
486
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
487
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
488
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
489
+
490
+ protected:
491
+ virtual void set_symints(std::vector<c10::SymInt>) override;
492
+ virtual void set_tensors(std::vector<at::Tensor>) override;
493
+
494
+ private:
495
+ int64_t dim;
496
+ c10::SymInt start;
497
+ c10::SymInt length;
498
+ };
499
+
500
+ #define PERMUTE_VIEW_FUNC_AVAILABLE
501
+ struct PermuteViewFunc : public torch::autograd::ViewFunc {
502
+ PermuteViewFunc(at::IntArrayRef dims) : dims(dims.vec())
503
+ {}
504
+ virtual ~PermuteViewFunc() override = default;
505
+ virtual std::vector<c10::SymInt> get_symints() const override;
506
+ virtual size_t num_symints() const override;
507
+ virtual std::vector<at::Tensor> get_tensors() const override;
508
+ virtual size_t num_tensors() const override;
509
+ virtual at::Tensor operator()(const at::Tensor&) const override;
510
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
511
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
512
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
513
+
514
+ protected:
515
+ virtual void set_symints(std::vector<c10::SymInt>) override;
516
+ virtual void set_tensors(std::vector<at::Tensor>) override;
517
+
518
+ private:
519
+ ::std::vector<int64_t> dims;
520
+ };
521
+
522
+ #define ROW_INDICES_VIEW_FUNC_AVAILABLE
523
+ struct RowIndicesViewFunc : public torch::autograd::ViewFunc {
524
+ RowIndicesViewFunc()
525
+ {}
526
+ virtual ~RowIndicesViewFunc() override = default;
527
+ virtual std::vector<c10::SymInt> get_symints() const override;
528
+ virtual size_t num_symints() const override;
529
+ virtual std::vector<at::Tensor> get_tensors() const override;
530
+ virtual size_t num_tensors() const override;
531
+ virtual at::Tensor operator()(const at::Tensor&) const override;
532
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
533
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
534
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
535
+
536
+ protected:
537
+ virtual void set_symints(std::vector<c10::SymInt>) override;
538
+ virtual void set_tensors(std::vector<at::Tensor>) override;
539
+
540
+ private:
541
+
542
+ };
543
+
544
+ #define SELECT_INT_VIEW_FUNC_AVAILABLE
545
+ struct SelectIntViewFunc : public torch::autograd::ViewFunc {
546
+ SelectIntViewFunc(int64_t dim, c10::SymInt index) : dim(dim), index(index)
547
+ {}
548
+ virtual ~SelectIntViewFunc() override = default;
549
+ virtual std::vector<c10::SymInt> get_symints() const override;
550
+ virtual size_t num_symints() const override;
551
+ virtual std::vector<at::Tensor> get_tensors() const override;
552
+ virtual size_t num_tensors() const override;
553
+ virtual at::Tensor operator()(const at::Tensor&) const override;
554
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
555
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
556
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
557
+
558
+ protected:
559
+ virtual void set_symints(std::vector<c10::SymInt>) override;
560
+ virtual void set_tensors(std::vector<at::Tensor>) override;
561
+
562
+ private:
563
+ int64_t dim;
564
+ c10::SymInt index;
565
+ };
566
+
567
+ #define SLICE_TENSOR_VIEW_FUNC_AVAILABLE
568
+ struct SliceTensorViewFunc : public torch::autograd::ViewFunc {
569
+ SliceTensorViewFunc(int64_t dim, ::std::optional<c10::SymInt> start, ::std::optional<c10::SymInt> end, c10::SymInt step) : dim(dim), start(start), end(end), step(step)
570
+ {}
571
+ virtual ~SliceTensorViewFunc() override = default;
572
+ virtual std::vector<c10::SymInt> get_symints() const override;
573
+ virtual size_t num_symints() const override;
574
+ virtual std::vector<at::Tensor> get_tensors() const override;
575
+ virtual size_t num_tensors() const override;
576
+ virtual at::Tensor operator()(const at::Tensor&) const override;
577
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
578
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
579
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
580
+
581
+ protected:
582
+ virtual void set_symints(std::vector<c10::SymInt>) override;
583
+ virtual void set_tensors(std::vector<at::Tensor>) override;
584
+
585
+ private:
586
+ int64_t dim;
587
+ ::std::optional<c10::SymInt> start;
588
+ ::std::optional<c10::SymInt> end;
589
+ c10::SymInt step;
590
+ };
591
+
592
+ #define SLICE_INVERSE_VIEW_FUNC_AVAILABLE
593
+ struct SliceInverseViewFunc : public torch::autograd::ViewFunc {
594
+ SliceInverseViewFunc(const at::Tensor & src, int64_t dim, ::std::optional<c10::SymInt> start, ::std::optional<c10::SymInt> end, c10::SymInt step) : src(src), dim(dim), start(start), end(end), step(step)
595
+ {}
596
+ virtual ~SliceInverseViewFunc() override = default;
597
+ virtual std::vector<c10::SymInt> get_symints() const override;
598
+ virtual size_t num_symints() const override;
599
+ virtual std::vector<at::Tensor> get_tensors() const override;
600
+ virtual size_t num_tensors() const override;
601
+ virtual at::Tensor operator()(const at::Tensor&) const override;
602
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
603
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
604
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
605
+
606
+ protected:
607
+ virtual void set_symints(std::vector<c10::SymInt>) override;
608
+ virtual void set_tensors(std::vector<at::Tensor>) override;
609
+
610
+ private:
611
+ at::Tensor src;
612
+ int64_t dim;
613
+ ::std::optional<c10::SymInt> start;
614
+ ::std::optional<c10::SymInt> end;
615
+ c10::SymInt step;
616
+ };
617
+
618
+ #define SPLIT_TENSOR_VIEW_FUNC_AVAILABLE
619
+ struct SplitTensorViewFunc : public torch::autograd::ViewFunc {
620
+ SplitTensorViewFunc(c10::SymInt split_size, int64_t dim, int64_t view_idx) : split_size(split_size), dim(dim), view_idx(view_idx)
621
+ {}
622
+ virtual ~SplitTensorViewFunc() override = default;
623
+ virtual std::vector<c10::SymInt> get_symints() const override;
624
+ virtual size_t num_symints() const override;
625
+ virtual std::vector<at::Tensor> get_tensors() const override;
626
+ virtual size_t num_tensors() const override;
627
+ virtual at::Tensor operator()(const at::Tensor&) const override;
628
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
629
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
630
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
631
+
632
+ protected:
633
+ virtual void set_symints(std::vector<c10::SymInt>) override;
634
+ virtual void set_tensors(std::vector<at::Tensor>) override;
635
+
636
+ private:
637
+ c10::SymInt split_size;
638
+ int64_t dim;
639
+ int64_t view_idx;
640
+ };
641
+
642
+ #define SPLIT_WITH_SIZES_VIEW_FUNC_AVAILABLE
643
+ struct SplitWithSizesViewFunc : public torch::autograd::ViewFunc {
644
+ SplitWithSizesViewFunc(c10::SymIntArrayRef split_sizes, int64_t dim, int64_t view_idx) : split_sizes(split_sizes.vec()), dim(dim), view_idx(view_idx)
645
+ {}
646
+ virtual ~SplitWithSizesViewFunc() override = default;
647
+ virtual std::vector<c10::SymInt> get_symints() const override;
648
+ virtual size_t num_symints() const override;
649
+ virtual std::vector<at::Tensor> get_tensors() const override;
650
+ virtual size_t num_tensors() const override;
651
+ virtual at::Tensor operator()(const at::Tensor&) const override;
652
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
653
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
654
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
655
+
656
+ protected:
657
+ virtual void set_symints(std::vector<c10::SymInt>) override;
658
+ virtual void set_tensors(std::vector<at::Tensor>) override;
659
+
660
+ private:
661
+ ::std::vector<c10::SymInt> split_sizes;
662
+ int64_t dim;
663
+ int64_t view_idx;
664
+ };
665
+
666
+ #define SQUEEZE_VIEW_FUNC_AVAILABLE
667
+ struct SqueezeViewFunc : public torch::autograd::ViewFunc {
668
+ SqueezeViewFunc()
669
+ {}
670
+ virtual ~SqueezeViewFunc() override = default;
671
+ virtual std::vector<c10::SymInt> get_symints() const override;
672
+ virtual size_t num_symints() const override;
673
+ virtual std::vector<at::Tensor> get_tensors() const override;
674
+ virtual size_t num_tensors() const override;
675
+ virtual at::Tensor operator()(const at::Tensor&) const override;
676
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
677
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
678
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
679
+
680
+ protected:
681
+ virtual void set_symints(std::vector<c10::SymInt>) override;
682
+ virtual void set_tensors(std::vector<at::Tensor>) override;
683
+
684
+ private:
685
+
686
+ };
687
+
688
+ #define SQUEEZE_DIM_VIEW_FUNC_AVAILABLE
689
+ struct SqueezeDimViewFunc : public torch::autograd::ViewFunc {
690
+ SqueezeDimViewFunc(int64_t dim) : dim(dim)
691
+ {}
692
+ virtual ~SqueezeDimViewFunc() override = default;
693
+ virtual std::vector<c10::SymInt> get_symints() const override;
694
+ virtual size_t num_symints() const override;
695
+ virtual std::vector<at::Tensor> get_tensors() const override;
696
+ virtual size_t num_tensors() const override;
697
+ virtual at::Tensor operator()(const at::Tensor&) const override;
698
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
699
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
700
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
701
+
702
+ protected:
703
+ virtual void set_symints(std::vector<c10::SymInt>) override;
704
+ virtual void set_tensors(std::vector<at::Tensor>) override;
705
+
706
+ private:
707
+ int64_t dim;
708
+ };
709
+
710
+ #define SQUEEZE_DIMS_VIEW_FUNC_AVAILABLE
711
+ struct SqueezeDimsViewFunc : public torch::autograd::ViewFunc {
712
+ SqueezeDimsViewFunc(at::IntArrayRef dim) : dim(dim.vec())
713
+ {}
714
+ virtual ~SqueezeDimsViewFunc() override = default;
715
+ virtual std::vector<c10::SymInt> get_symints() const override;
716
+ virtual size_t num_symints() const override;
717
+ virtual std::vector<at::Tensor> get_tensors() const override;
718
+ virtual size_t num_tensors() const override;
719
+ virtual at::Tensor operator()(const at::Tensor&) const override;
720
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
721
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
722
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
723
+
724
+ protected:
725
+ virtual void set_symints(std::vector<c10::SymInt>) override;
726
+ virtual void set_tensors(std::vector<at::Tensor>) override;
727
+
728
+ private:
729
+ ::std::vector<int64_t> dim;
730
+ };
731
+
732
+ #define T_VIEW_FUNC_AVAILABLE
733
+ struct TViewFunc : public torch::autograd::ViewFunc {
734
+ TViewFunc()
735
+ {}
736
+ virtual ~TViewFunc() override = default;
737
+ virtual std::vector<c10::SymInt> get_symints() const override;
738
+ virtual size_t num_symints() const override;
739
+ virtual std::vector<at::Tensor> get_tensors() const override;
740
+ virtual size_t num_tensors() const override;
741
+ virtual at::Tensor operator()(const at::Tensor&) const override;
742
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
743
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
744
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
745
+
746
+ protected:
747
+ virtual void set_symints(std::vector<c10::SymInt>) override;
748
+ virtual void set_tensors(std::vector<at::Tensor>) override;
749
+
750
+ private:
751
+
752
+ };
753
+
754
+ #define TRANSPOSE_INT_VIEW_FUNC_AVAILABLE
755
+ struct TransposeIntViewFunc : public torch::autograd::ViewFunc {
756
+ TransposeIntViewFunc(int64_t dim0, int64_t dim1) : dim0(dim0), dim1(dim1)
757
+ {}
758
+ virtual ~TransposeIntViewFunc() override = default;
759
+ virtual std::vector<c10::SymInt> get_symints() const override;
760
+ virtual size_t num_symints() const override;
761
+ virtual std::vector<at::Tensor> get_tensors() const override;
762
+ virtual size_t num_tensors() const override;
763
+ virtual at::Tensor operator()(const at::Tensor&) const override;
764
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
765
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
766
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
767
+
768
+ protected:
769
+ virtual void set_symints(std::vector<c10::SymInt>) override;
770
+ virtual void set_tensors(std::vector<at::Tensor>) override;
771
+
772
+ private:
773
+ int64_t dim0;
774
+ int64_t dim1;
775
+ };
776
+
777
+ #define UNBIND_INT_VIEW_FUNC_AVAILABLE
778
+ struct UnbindIntViewFunc : public torch::autograd::ViewFunc {
779
+ UnbindIntViewFunc(int64_t dim, int64_t view_idx) : dim(dim), view_idx(view_idx)
780
+ {}
781
+ virtual ~UnbindIntViewFunc() override = default;
782
+ virtual std::vector<c10::SymInt> get_symints() const override;
783
+ virtual size_t num_symints() const override;
784
+ virtual std::vector<at::Tensor> get_tensors() const override;
785
+ virtual size_t num_tensors() const override;
786
+ virtual at::Tensor operator()(const at::Tensor&) const override;
787
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
788
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
789
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
790
+
791
+ protected:
792
+ virtual void set_symints(std::vector<c10::SymInt>) override;
793
+ virtual void set_tensors(std::vector<at::Tensor>) override;
794
+
795
+ private:
796
+ int64_t dim;
797
+ int64_t view_idx;
798
+ };
799
+
800
+ #define UNFOLD_VIEW_FUNC_AVAILABLE
801
+ struct UnfoldViewFunc : public torch::autograd::ViewFunc {
802
+ UnfoldViewFunc(int64_t dimension, int64_t size, int64_t step) : dimension(dimension), size(size), step(step)
803
+ {}
804
+ virtual ~UnfoldViewFunc() override = default;
805
+ virtual std::vector<c10::SymInt> get_symints() const override;
806
+ virtual size_t num_symints() const override;
807
+ virtual std::vector<at::Tensor> get_tensors() const override;
808
+ virtual size_t num_tensors() const override;
809
+ virtual at::Tensor operator()(const at::Tensor&) const override;
810
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
811
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
812
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
813
+
814
+ protected:
815
+ virtual void set_symints(std::vector<c10::SymInt>) override;
816
+ virtual void set_tensors(std::vector<at::Tensor>) override;
817
+
818
+ private:
819
+ int64_t dimension;
820
+ int64_t size;
821
+ int64_t step;
822
+ };
823
+
824
+ #define UNSQUEEZE_VIEW_FUNC_AVAILABLE
825
+ struct UnsqueezeViewFunc : public torch::autograd::ViewFunc {
826
+ UnsqueezeViewFunc(int64_t dim) : dim(dim)
827
+ {}
828
+ virtual ~UnsqueezeViewFunc() override = default;
829
+ virtual std::vector<c10::SymInt> get_symints() const override;
830
+ virtual size_t num_symints() const override;
831
+ virtual std::vector<at::Tensor> get_tensors() const override;
832
+ virtual size_t num_tensors() const override;
833
+ virtual at::Tensor operator()(const at::Tensor&) const override;
834
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
835
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
836
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
837
+
838
+ protected:
839
+ virtual void set_symints(std::vector<c10::SymInt>) override;
840
+ virtual void set_tensors(std::vector<at::Tensor>) override;
841
+
842
+ private:
843
+ int64_t dim;
844
+ };
845
+
846
+ #define VALUES_VIEW_FUNC_AVAILABLE
847
+ struct ValuesViewFunc : public torch::autograd::ViewFunc {
848
+ ValuesViewFunc()
849
+ {}
850
+ virtual ~ValuesViewFunc() override = default;
851
+ virtual std::vector<c10::SymInt> get_symints() const override;
852
+ virtual size_t num_symints() const override;
853
+ virtual std::vector<at::Tensor> get_tensors() const override;
854
+ virtual size_t num_tensors() const override;
855
+ virtual at::Tensor operator()(const at::Tensor&) const override;
856
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
857
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
858
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
859
+
860
+ protected:
861
+ virtual void set_symints(std::vector<c10::SymInt>) override;
862
+ virtual void set_tensors(std::vector<at::Tensor>) override;
863
+
864
+ private:
865
+
866
+ };
867
+
868
+ #define VIEW_VIEW_FUNC_AVAILABLE
869
+ struct ViewViewFunc : public torch::autograd::ViewFunc {
870
+ ViewViewFunc(c10::SymIntArrayRef size) : size(size.vec())
871
+ {}
872
+ virtual ~ViewViewFunc() override = default;
873
+ virtual std::vector<c10::SymInt> get_symints() const override;
874
+ virtual size_t num_symints() const override;
875
+ virtual std::vector<at::Tensor> get_tensors() const override;
876
+ virtual size_t num_tensors() const override;
877
+ virtual at::Tensor operator()(const at::Tensor&) const override;
878
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
879
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
880
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
881
+
882
+ protected:
883
+ virtual void set_symints(std::vector<c10::SymInt>) override;
884
+ virtual void set_tensors(std::vector<at::Tensor>) override;
885
+
886
+ private:
887
+ ::std::vector<c10::SymInt> size;
888
+ };
889
+
890
+ #define VIEW_DTYPE_VIEW_FUNC_AVAILABLE
891
+ struct ViewDtypeViewFunc : public torch::autograd::ViewFunc {
892
+ ViewDtypeViewFunc(at::ScalarType dtype) : dtype(dtype)
893
+ {}
894
+ virtual ~ViewDtypeViewFunc() override = default;
895
+ virtual std::vector<c10::SymInt> get_symints() const override;
896
+ virtual size_t num_symints() const override;
897
+ virtual std::vector<at::Tensor> get_tensors() const override;
898
+ virtual size_t num_tensors() const override;
899
+ virtual at::Tensor operator()(const at::Tensor&) const override;
900
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
901
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
902
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
903
+
904
+ protected:
905
+ virtual void set_symints(std::vector<c10::SymInt>) override;
906
+ virtual void set_tensors(std::vector<at::Tensor>) override;
907
+
908
+ private:
909
+ at::ScalarType dtype;
910
+ };
911
+
912
+ #define VIEW_AS_COMPLEX_VIEW_FUNC_AVAILABLE
913
+ struct ViewAsComplexViewFunc : public torch::autograd::ViewFunc {
914
+ ViewAsComplexViewFunc()
915
+ {}
916
+ virtual ~ViewAsComplexViewFunc() override = default;
917
+ virtual std::vector<c10::SymInt> get_symints() const override;
918
+ virtual size_t num_symints() const override;
919
+ virtual std::vector<at::Tensor> get_tensors() const override;
920
+ virtual size_t num_tensors() const override;
921
+ virtual at::Tensor operator()(const at::Tensor&) const override;
922
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
923
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
924
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
925
+
926
+ protected:
927
+ virtual void set_symints(std::vector<c10::SymInt>) override;
928
+ virtual void set_tensors(std::vector<at::Tensor>) override;
929
+
930
+ private:
931
+
932
+ };
933
+
934
+ #define VIEW_AS_REAL_VIEW_FUNC_AVAILABLE
935
+ struct ViewAsRealViewFunc : public torch::autograd::ViewFunc {
936
+ ViewAsRealViewFunc()
937
+ {}
938
+ virtual ~ViewAsRealViewFunc() override = default;
939
+ virtual std::vector<c10::SymInt> get_symints() const override;
940
+ virtual size_t num_symints() const override;
941
+ virtual std::vector<at::Tensor> get_tensors() const override;
942
+ virtual size_t num_tensors() const override;
943
+ virtual at::Tensor operator()(const at::Tensor&) const override;
944
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
945
+ std::optional<std::vector<c10::SymInt>> = ::std::nullopt,
946
+ std::optional<std::vector<at::Tensor>> = ::std::nullopt) const override;
947
+
948
+ protected:
949
+ virtual void set_symints(std::vector<c10::SymInt>) override;
950
+ virtual void set_tensors(std::vector<at::Tensor>) override;
951
+
952
+ private:
953
+
954
+ };
955
+
956
+ } // namespace torch::autograd::generated
957
+
958
+ #else
959
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
960
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/python_functions.h ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <Python.h>
5
+
6
+ // @generated from ../tools/autograd/templates/python_functions.h
7
+
8
+ // Python bindings for automatically generated autograd functions
9
+
10
+ namespace torch { namespace autograd { namespace generated {
11
+
12
+ void initialize_autogenerated_functions_0(PyObject* module);
13
+ void initialize_autogenerated_functions_1(PyObject* module);
14
+ void initialize_autogenerated_functions_2(PyObject* module);
15
+ void initialize_autogenerated_functions_3(PyObject* module);
16
+ void initialize_autogenerated_functions_4(PyObject* module);
17
+
18
+ inline void initialize_autogenerated_functions(PyObject* module) {
19
+ initialize_autogenerated_functions_0(module);
20
+ initialize_autogenerated_functions_1(module);
21
+ initialize_autogenerated_functions_2(module);
22
+ initialize_autogenerated_functions_3(module);
23
+ initialize_autogenerated_functions_4(module);
24
+ }
25
+
26
+ }}} // namespace torch::autograd::generated
27
+
28
+ #else
29
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
30
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/python_return_types.h ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ namespace torch {
5
+ namespace autograd {
6
+ namespace generated {
7
+
8
+ PyTypeObject* get__fake_quantize_per_tensor_affine_cachemask_tensor_qparams_structseq();
9
+ PyTypeObject* get__fused_moving_avg_obs_fq_helper_structseq();
10
+ PyTypeObject* get__linalg_det_structseq();
11
+ PyTypeObject* get__linalg_det_out_structseq();
12
+ PyTypeObject* get__linalg_eigh_structseq();
13
+ PyTypeObject* get__linalg_eigh_out_structseq();
14
+ PyTypeObject* get__linalg_slogdet_structseq();
15
+ PyTypeObject* get__linalg_slogdet_out_structseq();
16
+ PyTypeObject* get__linalg_solve_ex_structseq();
17
+ PyTypeObject* get__linalg_solve_ex_out_structseq();
18
+ PyTypeObject* get__linalg_svd_structseq();
19
+ PyTypeObject* get__linalg_svd_out_structseq();
20
+ PyTypeObject* get__lu_with_info_structseq();
21
+ PyTypeObject* get__scaled_dot_product_cudnn_attention_structseq();
22
+ PyTypeObject* get__scaled_dot_product_efficient_attention_structseq();
23
+ PyTypeObject* get__scaled_dot_product_flash_attention_structseq();
24
+ PyTypeObject* get__scaled_dot_product_flash_attention_for_cpu_structseq();
25
+ PyTypeObject* get__unpack_dual_structseq();
26
+ PyTypeObject* get_aminmax_structseq();
27
+ PyTypeObject* get_aminmax_out_structseq();
28
+ PyTypeObject* get_cummax_structseq();
29
+ PyTypeObject* get_cummax_out_structseq();
30
+ PyTypeObject* get_cummin_structseq();
31
+ PyTypeObject* get_cummin_out_structseq();
32
+ PyTypeObject* get_frexp_structseq();
33
+ PyTypeObject* get_frexp_out_structseq();
34
+ PyTypeObject* get_geqrf_out_structseq();
35
+ PyTypeObject* get_geqrf_structseq();
36
+ PyTypeObject* get_histogram_out_structseq();
37
+ PyTypeObject* get_histogram_structseq();
38
+ PyTypeObject* get_histogramdd_structseq();
39
+ PyTypeObject* get_kthvalue_structseq();
40
+ PyTypeObject* get_kthvalue_out_structseq();
41
+ PyTypeObject* get_linalg_cholesky_ex_structseq();
42
+ PyTypeObject* get_linalg_cholesky_ex_out_structseq();
43
+ PyTypeObject* get_linalg_eig_structseq();
44
+ PyTypeObject* get_linalg_eig_out_structseq();
45
+ PyTypeObject* get_linalg_eigh_structseq();
46
+ PyTypeObject* get_linalg_eigh_out_structseq();
47
+ PyTypeObject* get_linalg_inv_ex_structseq();
48
+ PyTypeObject* get_linalg_inv_ex_out_structseq();
49
+ PyTypeObject* get_linalg_ldl_factor_structseq();
50
+ PyTypeObject* get_linalg_ldl_factor_out_structseq();
51
+ PyTypeObject* get_linalg_ldl_factor_ex_structseq();
52
+ PyTypeObject* get_linalg_ldl_factor_ex_out_structseq();
53
+ PyTypeObject* get_linalg_lstsq_structseq();
54
+ PyTypeObject* get_linalg_lstsq_out_structseq();
55
+ PyTypeObject* get_linalg_lu_structseq();
56
+ PyTypeObject* get_linalg_lu_out_structseq();
57
+ PyTypeObject* get_linalg_lu_factor_structseq();
58
+ PyTypeObject* get_linalg_lu_factor_out_structseq();
59
+ PyTypeObject* get_linalg_lu_factor_ex_structseq();
60
+ PyTypeObject* get_linalg_lu_factor_ex_out_structseq();
61
+ PyTypeObject* get_linalg_qr_structseq();
62
+ PyTypeObject* get_linalg_qr_out_structseq();
63
+ PyTypeObject* get_linalg_slogdet_structseq();
64
+ PyTypeObject* get_linalg_slogdet_out_structseq();
65
+ PyTypeObject* get_linalg_solve_ex_structseq();
66
+ PyTypeObject* get_linalg_solve_ex_out_structseq();
67
+ PyTypeObject* get_linalg_svd_structseq();
68
+ PyTypeObject* get_linalg_svd_out_structseq();
69
+ PyTypeObject* get_lu_unpack_structseq();
70
+ PyTypeObject* get_lu_unpack_out_structseq();
71
+ PyTypeObject* get_max_structseq();
72
+ PyTypeObject* get_max_out_structseq();
73
+ PyTypeObject* get_median_structseq();
74
+ PyTypeObject* get_median_out_structseq();
75
+ PyTypeObject* get_min_structseq();
76
+ PyTypeObject* get_min_out_structseq();
77
+ PyTypeObject* get_mode_structseq();
78
+ PyTypeObject* get_mode_out_structseq();
79
+ PyTypeObject* get_nanmedian_structseq();
80
+ PyTypeObject* get_nanmedian_out_structseq();
81
+ PyTypeObject* get_qr_out_structseq();
82
+ PyTypeObject* get_qr_structseq();
83
+ PyTypeObject* get_slogdet_structseq();
84
+ PyTypeObject* get_slogdet_out_structseq();
85
+ PyTypeObject* get_sort_out_structseq();
86
+ PyTypeObject* get_sort_structseq();
87
+ PyTypeObject* get_svd_out_structseq();
88
+ PyTypeObject* get_svd_structseq();
89
+ PyTypeObject* get_topk_out_structseq();
90
+ PyTypeObject* get_topk_structseq();
91
+ PyTypeObject* get_triangular_solve_out_structseq();
92
+ PyTypeObject* get_triangular_solve_structseq();
93
+
94
+ }
95
+
96
+ void initReturnTypes(PyObject* module);
97
+
98
+ } // namespace autograd
99
+ } // namespace torch
100
+
101
+ #else
102
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
103
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/variable_factories.h ADDED
@@ -0,0 +1,784 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // @generated from ../tools/autograd/templates/variable_factories.h
5
+
6
+ #include <ATen/core/Tensor.h>
7
+ #include <ATen/TracerMode.h>
8
+ #include <ATen/core/grad_mode.h>
9
+ #include <c10/util/ArrayRef.h>
10
+ #include <c10/core/MemoryFormat.h>
11
+ #include <torch/csrc/api/include/torch/detail/TensorDataContainer.h>
12
+ #include <torch/csrc/autograd/variable.h>
13
+
14
+ #ifndef AT_PER_OPERATOR_HEADERS
15
+ #include <ATen/Functions.h>
16
+ #else
17
+ #include <ATen/ops/from_blob.h>
18
+ #include <ATen/ops/_make_dep_token.h>
19
+ #include <ATen/ops/_cudnn_init_dropout_state.h>
20
+ #include <ATen/ops/arange.h>
21
+ #include <ATen/ops/arange.h>
22
+ #include <ATen/ops/arange.h>
23
+ #include <ATen/ops/bartlett_window.h>
24
+ #include <ATen/ops/bartlett_window.h>
25
+ #include <ATen/ops/blackman_window.h>
26
+ #include <ATen/ops/blackman_window.h>
27
+ #include <ATen/ops/empty.h>
28
+ #include <ATen/ops/empty.h>
29
+ #include <ATen/ops/empty_permuted.h>
30
+ #include <ATen/ops/_empty_affine_quantized.h>
31
+ #include <ATen/ops/_empty_per_channel_affine_quantized.h>
32
+ #include <ATen/ops/empty_quantized.h>
33
+ #include <ATen/ops/empty_like.h>
34
+ #include <ATen/ops/empty_strided.h>
35
+ #include <ATen/ops/eye.h>
36
+ #include <ATen/ops/eye.h>
37
+ #include <ATen/ops/full.h>
38
+ #include <ATen/ops/full.h>
39
+ #include <ATen/ops/full_like.h>
40
+ #include <ATen/ops/from_file.h>
41
+ #include <ATen/ops/hann_window.h>
42
+ #include <ATen/ops/hann_window.h>
43
+ #include <ATen/ops/hamming_window.h>
44
+ #include <ATen/ops/hamming_window.h>
45
+ #include <ATen/ops/hamming_window.h>
46
+ #include <ATen/ops/hamming_window.h>
47
+ #include <ATen/ops/kaiser_window.h>
48
+ #include <ATen/ops/kaiser_window.h>
49
+ #include <ATen/ops/kaiser_window.h>
50
+ #include <ATen/ops/linspace.h>
51
+ #include <ATen/ops/linspace.h>
52
+ #include <ATen/ops/linspace.h>
53
+ #include <ATen/ops/linspace.h>
54
+ #include <ATen/ops/logspace.h>
55
+ #include <ATen/ops/logspace.h>
56
+ #include <ATen/ops/logspace.h>
57
+ #include <ATen/ops/logspace.h>
58
+ #include <ATen/ops/ones.h>
59
+ #include <ATen/ops/ones.h>
60
+ #include <ATen/ops/ones_like.h>
61
+ #include <ATen/ops/scalar_tensor.h>
62
+ #include <ATen/ops/rand.h>
63
+ #include <ATen/ops/rand.h>
64
+ #include <ATen/ops/rand.h>
65
+ #include <ATen/ops/rand.h>
66
+ #include <ATen/ops/rand_like.h>
67
+ #include <ATen/ops/rand_like.h>
68
+ #include <ATen/ops/randint.h>
69
+ #include <ATen/ops/randint.h>
70
+ #include <ATen/ops/randint.h>
71
+ #include <ATen/ops/randint.h>
72
+ #include <ATen/ops/randint_like.h>
73
+ #include <ATen/ops/randint_like.h>
74
+ #include <ATen/ops/randint_like.h>
75
+ #include <ATen/ops/randint_like.h>
76
+ #include <ATen/ops/randint_like.h>
77
+ #include <ATen/ops/randint_like.h>
78
+ #include <ATen/ops/randn.h>
79
+ #include <ATen/ops/randn.h>
80
+ #include <ATen/ops/randn.h>
81
+ #include <ATen/ops/randn.h>
82
+ #include <ATen/ops/randn_like.h>
83
+ #include <ATen/ops/randn_like.h>
84
+ #include <ATen/ops/randperm.h>
85
+ #include <ATen/ops/randperm.h>
86
+ #include <ATen/ops/range.h>
87
+ #include <ATen/ops/range.h>
88
+ #include <ATen/ops/zeros.h>
89
+ #include <ATen/ops/_efficientzerotensor.h>
90
+ #include <ATen/ops/zeros.h>
91
+ #include <ATen/ops/zeros_like.h>
92
+ #include <ATen/ops/_sparse_compressed_tensor_with_dims.h>
93
+ #include <ATen/ops/sparse_compressed_tensor.h>
94
+ #include <ATen/ops/sparse_csr_tensor.h>
95
+ #include <ATen/ops/sparse_csc_tensor.h>
96
+ #include <ATen/ops/sparse_bsr_tensor.h>
97
+ #include <ATen/ops/sparse_bsc_tensor.h>
98
+ #include <ATen/ops/sparse_compressed_tensor.h>
99
+ #include <ATen/ops/sparse_csr_tensor.h>
100
+ #include <ATen/ops/sparse_csc_tensor.h>
101
+ #include <ATen/ops/sparse_bsr_tensor.h>
102
+ #include <ATen/ops/sparse_bsc_tensor.h>
103
+ #include <ATen/ops/_sparse_compressed_tensor_unsafe.h>
104
+ #include <ATen/ops/_sparse_csr_tensor_unsafe.h>
105
+ #include <ATen/ops/_sparse_csc_tensor_unsafe.h>
106
+ #include <ATen/ops/_sparse_bsr_tensor_unsafe.h>
107
+ #include <ATen/ops/_sparse_bsc_tensor_unsafe.h>
108
+ #include <ATen/ops/sparse_coo_tensor.h>
109
+ #include <ATen/ops/sparse_coo_tensor.h>
110
+ #include <ATen/ops/sparse_coo_tensor.h>
111
+ #include <ATen/ops/_sparse_coo_tensor_unsafe.h>
112
+ #include <ATen/ops/_sparse_coo_tensor_with_dims.h>
113
+ #include <ATen/ops/_sparse_coo_tensor_with_dims_and_tensors.h>
114
+ #include <ATen/ops/_to_copy.h>
115
+ #include <ATen/ops/tril_indices.h>
116
+ #include <ATen/ops/triu_indices.h>
117
+ #include <ATen/ops/normal.h>
118
+ #include <ATen/ops/fft_fftfreq.h>
119
+ #include <ATen/ops/fft_rfftfreq.h>
120
+ #endif
121
+
122
+ #include <functional>
123
+ #include <initializer_list>
124
+ #include <utility>
125
+
126
+ namespace torch {
127
+
128
+ /// NOTE: Currently `torch::tensor(...)` doesn't support mixed data types
129
+ /// (i.e. `torch::tensor({{bool, 2.0}})` doesn't work). We might be able to
130
+ /// support it in the future by iterating over all sub-lists to find
131
+ /// the largest data type that can represent all of the elements, or by using
132
+ /// variadic templates.
133
+ ///
134
+ /// NOTE: C++ `torch::tensor` with a floating-point type or an `at::ArrayRef` / `std::vector` /
135
+ /// (nested) braced-init-list of floating-point types always produces a tensor of dtype
136
+ /// `torch::get_default_dtype()`, matching Python `torch.tensor` behavior.
137
+ ///
138
+ /// NOTE: C++ `torch::tensor` with an integer type or an `at::ArrayRef` / `std::vector` /
139
+ /// (nested) braced-init-list of integer types always produces a tensor of dtype `at::kLong`
140
+ /// (aka. int64_t), matching Python `torch.tensor` behavior.
141
+ ///
142
+ /// NOTE: The following dtypes are not supported by `torch::tensor` currently:
143
+ /// - `unsigned int`
144
+ /// - `unsigned long int`
145
+ /// - `unsigned long long int`
146
+ /// - `long long int`
147
+ inline at::Tensor tensor(detail::TensorDataContainer tensor_data_container, const at::TensorOptions& options = {}) {
148
+ return autograd::make_variable(
149
+ // note: we remove the requires_grad setting from the TensorOptions because
150
+ // it is ignored anyways (and we actually have an assertion that it isn't set
151
+ // which would fail otherwise). We handle requires_grad explicitly here
152
+ // instead of passing it through to the kernel.
153
+ tensor_data_container.convert_to_tensor(options.requires_grad(::std::nullopt)),
154
+ options.requires_grad());
155
+ }
156
+
157
+ /// A generic deleter function.
158
+ using Deleter = std::function<void(void*)>;
159
+ using at::MemoryFormat;
160
+
161
+ /// Exposes the given `data` as a `Tensor` without taking ownership of the
162
+ /// original data. `sizes` should specify the shape of the tensor, `strides` the
163
+ /// stride in each dimension. The `deleter` function (a
164
+ /// `std::function<void(void*)>`) will be called on the `data` when the Tensor
165
+ /// data would normally be deallocated. The `TensorOptions` specify additional
166
+ /// configuration options for the returned tensor, such as what type to
167
+ /// interpret the `data` as.
168
+ inline at::Tensor from_blob(
169
+ void* data,
170
+ at::IntArrayRef sizes,
171
+ at::IntArrayRef strides,
172
+ const Deleter& deleter,
173
+ const at::TensorOptions& options = at::TensorOptions()) {
174
+ at::Tensor tensor = ([&]() {
175
+ at::AutoDispatchBelowAutograd guard; // TODO: remove
176
+ at::tracer::impl::NoTracerDispatchMode tracer_guard;
177
+ return at::from_blob(data, sizes, strides, deleter, options.requires_grad(::std::nullopt));
178
+ })();
179
+ return autograd::make_variable(tensor, options.requires_grad());
180
+ }
181
+
182
+ /// Exposes the given `data` as a `Tensor` without taking ownership of the
183
+ /// original data. `sizes` should specify the shape of the tensor, `strides` the
184
+ /// stride in each dimension. The `TensorOptions`
185
+ /// specify additional configuration options for the returned tensor, such as
186
+ /// what type to interpret the `data` as.
187
+ inline at::Tensor from_blob(
188
+ void* data,
189
+ at::IntArrayRef sizes,
190
+ at::IntArrayRef strides,
191
+ const at::TensorOptions& options = at::TensorOptions()) {
192
+ at::Tensor tensor = ([&]() {
193
+ at::AutoDispatchBelowAutograd guard; // TODO: remove
194
+ at::tracer::impl::NoTracerDispatchMode tracer_guard;
195
+ return at::from_blob(data, sizes, strides, options.requires_grad(::std::nullopt));
196
+ })();
197
+ return autograd::make_variable(tensor, options.requires_grad());
198
+ }
199
+
200
+ /// Exposes the given `data` as a `Tensor` without taking ownership of the
201
+ /// original data. `sizes` should specify the shape of the tensor. The `deleter`
202
+ /// (a `std::function<void(void*)>`) function will be called on the `data` when
203
+ /// the Tensor data would normally be deallocated. The `TensorOptions` specify
204
+ /// additional configuration options for the returned tensor, such as what type
205
+ /// to interpret the `data` as.
206
+ inline at::Tensor from_blob(
207
+ void* data,
208
+ at::IntArrayRef sizes,
209
+ const Deleter& deleter,
210
+ const at::TensorOptions& options = at::TensorOptions()) {
211
+ at::Tensor tensor = ([&]() {
212
+ at::AutoDispatchBelowAutograd guard; // TODO: remove
213
+ at::tracer::impl::NoTracerDispatchMode tracer_guard;
214
+ return at::from_blob(data, sizes, deleter, options.requires_grad(::std::nullopt));
215
+ })();
216
+ return autograd::make_variable(tensor, options.requires_grad());
217
+ }
218
+
219
+ /// Exposes the given `data` as a `Tensor` without taking ownership of the
220
+ /// original data. `sizes` should specify the shape of the tensor. The
221
+ /// `TensorOptions` specify additional configuration options for the returned
222
+ /// tensor, such as what type to interpret the `data` as.
223
+ inline at::Tensor from_blob(
224
+ void* data,
225
+ at::IntArrayRef sizes,
226
+ const at::TensorOptions& options = at::TensorOptions()) {
227
+ at::Tensor tensor = ([&]() {
228
+ at::AutoDispatchBelowAutograd guard; // TODO: remove
229
+ at::tracer::impl::NoTracerDispatchMode tracer_guard;
230
+ return at::from_blob(data, sizes, options.requires_grad(::std::nullopt));
231
+ })();
232
+ return autograd::make_variable(tensor, options.requires_grad());
233
+ }
234
+
235
+ inline at::Tensor _make_dep_token(at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
236
+ at::AutoDispatchBelowADInplaceOrView guard;
237
+ return autograd::make_variable(at::_make_dep_token(at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
238
+ }
239
+ inline at::Tensor _cudnn_init_dropout_state(double dropout, bool train, int64_t dropout_seed, at::TensorOptions options) {
240
+ at::AutoDispatchBelowADInplaceOrView guard;
241
+ return autograd::make_variable(at::_cudnn_init_dropout_state(dropout, train, dropout_seed, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
242
+ }
243
+ inline at::Tensor arange(const at::Scalar & end, at::TensorOptions options = {}) {
244
+ at::AutoDispatchBelowADInplaceOrView guard;
245
+ return autograd::make_variable(at::arange(end, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
246
+ }
247
+ inline at::Tensor arange(const at::Scalar & start, const at::Scalar & end, at::TensorOptions options = {}) {
248
+ at::AutoDispatchBelowADInplaceOrView guard;
249
+ return autograd::make_variable(at::arange(start, end, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
250
+ }
251
+ inline at::Tensor arange(const at::Scalar & start, const at::Scalar & end, const at::Scalar & step, at::TensorOptions options = {}) {
252
+ at::AutoDispatchBelowADInplaceOrView guard;
253
+ return autograd::make_variable(at::arange(start, end, step, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
254
+ }
255
+ inline at::Tensor bartlett_window(int64_t window_length, at::TensorOptions options = {}) {
256
+ at::AutoDispatchBelowADInplaceOrView guard;
257
+ return autograd::make_variable(at::bartlett_window(window_length, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
258
+ }
259
+ inline at::Tensor bartlett_window(int64_t window_length, bool periodic, at::TensorOptions options = {}) {
260
+ at::AutoDispatchBelowADInplaceOrView guard;
261
+ return autograd::make_variable(at::bartlett_window(window_length, periodic, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
262
+ }
263
+ inline at::Tensor blackman_window(int64_t window_length, at::TensorOptions options = {}) {
264
+ at::AutoDispatchBelowADInplaceOrView guard;
265
+ return autograd::make_variable(at::blackman_window(window_length, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
266
+ }
267
+ inline at::Tensor blackman_window(int64_t window_length, bool periodic, at::TensorOptions options = {}) {
268
+ at::AutoDispatchBelowADInplaceOrView guard;
269
+ return autograd::make_variable(at::blackman_window(window_length, periodic, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
270
+ }
271
+ inline at::Tensor empty(at::IntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
272
+ at::AutoDispatchBelowADInplaceOrView guard;
273
+ return autograd::make_variable(at::empty(size, names, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
274
+ }
275
+ inline at::Tensor empty(at::IntArrayRef size, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
276
+ at::AutoDispatchBelowADInplaceOrView guard;
277
+ return autograd::make_variable(at::empty(size, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
278
+ }
279
+ inline at::Tensor empty_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
280
+ at::AutoDispatchBelowADInplaceOrView guard;
281
+ return autograd::make_variable(at::empty_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
282
+ }
283
+ inline at::Tensor empty_permuted(at::IntArrayRef size, at::IntArrayRef physical_layout, at::TensorOptions options = {}) {
284
+ at::AutoDispatchBelowADInplaceOrView guard;
285
+ return autograd::make_variable(at::empty_permuted(size, physical_layout, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
286
+ }
287
+ inline at::Tensor empty_permuted_symint(c10::SymIntArrayRef size, at::IntArrayRef physical_layout, at::TensorOptions options = {}) {
288
+ at::AutoDispatchBelowADInplaceOrView guard;
289
+ return autograd::make_variable(at::empty_permuted_symint(size, physical_layout, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
290
+ }
291
+ inline at::Tensor _empty_affine_quantized(at::IntArrayRef size, at::TensorOptions options = {}, double scale = 1, int64_t zero_point = 0, ::std::optional<at::MemoryFormat> memory_format = c10::MemoryFormat::Contiguous) {
292
+ at::AutoDispatchBelowADInplaceOrView guard;
293
+ return autograd::make_variable(at::_empty_affine_quantized(size, at::TensorOptions(options).requires_grad(::std::nullopt), scale, zero_point, memory_format), /*requires_grad=*/options.requires_grad());
294
+ }
295
+ inline at::Tensor _empty_affine_quantized_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}, double scale = 1, int64_t zero_point = 0, ::std::optional<at::MemoryFormat> memory_format = c10::MemoryFormat::Contiguous) {
296
+ at::AutoDispatchBelowADInplaceOrView guard;
297
+ return autograd::make_variable(at::_empty_affine_quantized_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt), scale, zero_point, memory_format), /*requires_grad=*/options.requires_grad());
298
+ }
299
+ inline at::Tensor _empty_per_channel_affine_quantized(at::IntArrayRef size, const at::Tensor & scales, const at::Tensor & zero_points, int64_t axis, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = c10::MemoryFormat::Contiguous) {
300
+ at::AutoDispatchBelowADInplaceOrView guard;
301
+ return autograd::make_variable(at::_empty_per_channel_affine_quantized(size, scales, zero_points, axis, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
302
+ }
303
+ inline at::Tensor _empty_per_channel_affine_quantized_symint(c10::SymIntArrayRef size, const at::Tensor & scales, const at::Tensor & zero_points, int64_t axis, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = c10::MemoryFormat::Contiguous) {
304
+ at::AutoDispatchBelowADInplaceOrView guard;
305
+ return autograd::make_variable(at::_empty_per_channel_affine_quantized_symint(size, scales, zero_points, axis, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
306
+ }
307
+ inline at::Tensor empty_quantized(at::IntArrayRef size, const at::Tensor & qtensor, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
308
+ at::AutoDispatchBelowADInplaceOrView guard;
309
+ return autograd::make_variable(at::empty_quantized(size, qtensor, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
310
+ }
311
+ inline at::Tensor empty_like(const at::Tensor & self, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
312
+ at::AutoDispatchBelowADInplaceOrView guard;
313
+ return autograd::make_variable(at::empty_like(self, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
314
+ }
315
+ inline at::Tensor empty_strided(at::IntArrayRef size, at::IntArrayRef stride, at::TensorOptions options = {}) {
316
+ at::AutoDispatchBelowADInplaceOrView guard;
317
+ return autograd::make_variable(at::empty_strided(size, stride, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
318
+ }
319
+ inline at::Tensor empty_strided_symint(c10::SymIntArrayRef size, c10::SymIntArrayRef stride, at::TensorOptions options = {}) {
320
+ at::AutoDispatchBelowADInplaceOrView guard;
321
+ return autograd::make_variable(at::empty_strided_symint(size, stride, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
322
+ }
323
+ inline at::Tensor eye(int64_t n, at::TensorOptions options = {}) {
324
+ at::AutoDispatchBelowADInplaceOrView guard;
325
+ return autograd::make_variable(at::eye(n, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
326
+ }
327
+ inline at::Tensor eye_symint(c10::SymInt n, at::TensorOptions options = {}) {
328
+ at::AutoDispatchBelowADInplaceOrView guard;
329
+ return autograd::make_variable(at::eye_symint(n, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
330
+ }
331
+ inline at::Tensor eye(int64_t n, int64_t m, at::TensorOptions options = {}) {
332
+ at::AutoDispatchBelowADInplaceOrView guard;
333
+ return autograd::make_variable(at::eye(n, m, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
334
+ }
335
+ inline at::Tensor eye_symint(c10::SymInt n, c10::SymInt m, at::TensorOptions options = {}) {
336
+ at::AutoDispatchBelowADInplaceOrView guard;
337
+ return autograd::make_variable(at::eye_symint(n, m, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
338
+ }
339
+ inline at::Tensor full(at::IntArrayRef size, const at::Scalar & fill_value, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
340
+ at::AutoDispatchBelowADInplaceOrView guard;
341
+ return autograd::make_variable(at::full(size, fill_value, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
342
+ }
343
+ inline at::Tensor full(at::IntArrayRef size, const at::Scalar & fill_value, at::TensorOptions options = {}) {
344
+ at::AutoDispatchBelowADInplaceOrView guard;
345
+ return autograd::make_variable(at::full(size, fill_value, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
346
+ }
347
+ inline at::Tensor full_symint(c10::SymIntArrayRef size, const at::Scalar & fill_value, at::TensorOptions options = {}) {
348
+ at::AutoDispatchBelowADInplaceOrView guard;
349
+ return autograd::make_variable(at::full_symint(size, fill_value, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
350
+ }
351
+ inline at::Tensor full_like(const at::Tensor & self, const at::Scalar & fill_value, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
352
+ at::AutoDispatchBelowADInplaceOrView guard;
353
+ return autograd::make_variable(at::full_like(self, fill_value, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
354
+ }
355
+ inline at::Tensor from_file(c10::string_view filename, ::std::optional<bool> shared = ::std::nullopt, ::std::optional<int64_t> size = 0, at::TensorOptions options = {}) {
356
+ at::AutoDispatchBelowADInplaceOrView guard;
357
+ return autograd::make_variable(at::from_file(filename, shared, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
358
+ }
359
+ inline at::Tensor hann_window(int64_t window_length, at::TensorOptions options = {}) {
360
+ at::AutoDispatchBelowADInplaceOrView guard;
361
+ return autograd::make_variable(at::hann_window(window_length, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
362
+ }
363
+ inline at::Tensor hann_window(int64_t window_length, bool periodic, at::TensorOptions options = {}) {
364
+ at::AutoDispatchBelowADInplaceOrView guard;
365
+ return autograd::make_variable(at::hann_window(window_length, periodic, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
366
+ }
367
+ inline at::Tensor hamming_window(int64_t window_length, at::TensorOptions options = {}) {
368
+ at::AutoDispatchBelowADInplaceOrView guard;
369
+ return autograd::make_variable(at::hamming_window(window_length, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
370
+ }
371
+ inline at::Tensor hamming_window(int64_t window_length, bool periodic, at::TensorOptions options = {}) {
372
+ at::AutoDispatchBelowADInplaceOrView guard;
373
+ return autograd::make_variable(at::hamming_window(window_length, periodic, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
374
+ }
375
+ inline at::Tensor hamming_window(int64_t window_length, bool periodic, double alpha, at::TensorOptions options = {}) {
376
+ at::AutoDispatchBelowADInplaceOrView guard;
377
+ return autograd::make_variable(at::hamming_window(window_length, periodic, alpha, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
378
+ }
379
+ inline at::Tensor hamming_window(int64_t window_length, bool periodic, double alpha, double beta, at::TensorOptions options = {}) {
380
+ at::AutoDispatchBelowADInplaceOrView guard;
381
+ return autograd::make_variable(at::hamming_window(window_length, periodic, alpha, beta, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
382
+ }
383
+ inline at::Tensor kaiser_window(int64_t window_length, at::TensorOptions options = {}) {
384
+ at::AutoDispatchBelowADInplaceOrView guard;
385
+ return autograd::make_variable(at::kaiser_window(window_length, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
386
+ }
387
+ inline at::Tensor kaiser_window(int64_t window_length, bool periodic, at::TensorOptions options = {}) {
388
+ at::AutoDispatchBelowADInplaceOrView guard;
389
+ return autograd::make_variable(at::kaiser_window(window_length, periodic, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
390
+ }
391
+ inline at::Tensor kaiser_window(int64_t window_length, bool periodic, double beta, at::TensorOptions options = {}) {
392
+ at::AutoDispatchBelowADInplaceOrView guard;
393
+ return autograd::make_variable(at::kaiser_window(window_length, periodic, beta, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
394
+ }
395
+ inline at::Tensor linspace(const at::Scalar & start, const at::Scalar & end, int64_t steps, at::TensorOptions options = {}) {
396
+ at::AutoDispatchBelowADInplaceOrView guard;
397
+ return autograd::make_variable(at::linspace(start, end, steps, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
398
+ }
399
+ inline at::Tensor linspace(const at::Tensor & start, const at::Tensor & end, int64_t steps, at::TensorOptions options = {}) {
400
+ at::AutoDispatchBelowADInplaceOrView guard;
401
+ return autograd::make_variable(at::linspace(start, end, steps, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
402
+ }
403
+ inline at::Tensor linspace(const at::Tensor & start, const at::Scalar & end, int64_t steps, at::TensorOptions options = {}) {
404
+ at::AutoDispatchBelowADInplaceOrView guard;
405
+ return autograd::make_variable(at::linspace(start, end, steps, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
406
+ }
407
+ inline at::Tensor linspace(const at::Scalar & start, const at::Tensor & end, int64_t steps, at::TensorOptions options = {}) {
408
+ at::AutoDispatchBelowADInplaceOrView guard;
409
+ return autograd::make_variable(at::linspace(start, end, steps, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
410
+ }
411
+ inline at::Tensor logspace(const at::Scalar & start, const at::Scalar & end, int64_t steps, double base = 10.0, at::TensorOptions options = {}) {
412
+ at::AutoDispatchBelowADInplaceOrView guard;
413
+ return autograd::make_variable(at::logspace(start, end, steps, base, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
414
+ }
415
+ inline at::Tensor logspace(const at::Tensor & start, const at::Tensor & end, int64_t steps, double base = 10.0, at::TensorOptions options = {}) {
416
+ at::AutoDispatchBelowADInplaceOrView guard;
417
+ return autograd::make_variable(at::logspace(start, end, steps, base, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
418
+ }
419
+ inline at::Tensor logspace(const at::Tensor & start, const at::Scalar & end, int64_t steps, double base = 10.0, at::TensorOptions options = {}) {
420
+ at::AutoDispatchBelowADInplaceOrView guard;
421
+ return autograd::make_variable(at::logspace(start, end, steps, base, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
422
+ }
423
+ inline at::Tensor logspace(const at::Scalar & start, const at::Tensor & end, int64_t steps, double base = 10.0, at::TensorOptions options = {}) {
424
+ at::AutoDispatchBelowADInplaceOrView guard;
425
+ return autograd::make_variable(at::logspace(start, end, steps, base, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
426
+ }
427
+ inline at::Tensor ones(at::IntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
428
+ at::AutoDispatchBelowADInplaceOrView guard;
429
+ return autograd::make_variable(at::ones(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
430
+ }
431
+ inline at::Tensor ones(at::IntArrayRef size, at::TensorOptions options = {}) {
432
+ at::AutoDispatchBelowADInplaceOrView guard;
433
+ return autograd::make_variable(at::ones(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
434
+ }
435
+ inline at::Tensor ones_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}) {
436
+ at::AutoDispatchBelowADInplaceOrView guard;
437
+ return autograd::make_variable(at::ones_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
438
+ }
439
+ inline at::Tensor ones_like(const at::Tensor & self, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
440
+ at::AutoDispatchBelowADInplaceOrView guard;
441
+ return autograd::make_variable(at::ones_like(self, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
442
+ }
443
+ inline at::Tensor scalar_tensor(const at::Scalar & s, at::TensorOptions options = {}) {
444
+ at::AutoDispatchBelowADInplaceOrView guard;
445
+ return autograd::make_variable(at::scalar_tensor(s, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
446
+ }
447
+ inline at::Tensor rand(at::IntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
448
+ at::AutoDispatchBelowADInplaceOrView guard;
449
+ return autograd::make_variable(at::rand(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
450
+ }
451
+ inline at::Tensor rand_symint(c10::SymIntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
452
+ at::AutoDispatchBelowADInplaceOrView guard;
453
+ return autograd::make_variable(at::rand_symint(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
454
+ }
455
+ inline at::Tensor rand(at::IntArrayRef size, ::std::optional<at::Generator> generator, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
456
+ at::AutoDispatchBelowADInplaceOrView guard;
457
+ return autograd::make_variable(at::rand(size, generator, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
458
+ }
459
+ inline at::Tensor rand_symint(c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
460
+ at::AutoDispatchBelowADInplaceOrView guard;
461
+ return autograd::make_variable(at::rand_symint(size, generator, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
462
+ }
463
+ inline at::Tensor rand(at::IntArrayRef size, at::TensorOptions options = {}) {
464
+ at::AutoDispatchBelowADInplaceOrView guard;
465
+ return autograd::make_variable(at::rand(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
466
+ }
467
+ inline at::Tensor rand_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}) {
468
+ at::AutoDispatchBelowADInplaceOrView guard;
469
+ return autograd::make_variable(at::rand_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
470
+ }
471
+ inline at::Tensor rand(at::IntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = {}) {
472
+ at::AutoDispatchBelowADInplaceOrView guard;
473
+ return autograd::make_variable(at::rand(size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
474
+ }
475
+ inline at::Tensor rand_symint(c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = {}) {
476
+ at::AutoDispatchBelowADInplaceOrView guard;
477
+ return autograd::make_variable(at::rand_symint(size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
478
+ }
479
+ inline at::Tensor rand_like(const at::Tensor & self, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
480
+ at::AutoDispatchBelowADInplaceOrView guard;
481
+ return autograd::make_variable(at::rand_like(self, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
482
+ }
483
+ inline at::Tensor rand_like(const at::Tensor & self, ::std::optional<at::Generator> generator, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
484
+ at::AutoDispatchBelowADInplaceOrView guard;
485
+ return autograd::make_variable(at::rand_like(self, generator, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
486
+ }
487
+ inline at::Tensor randint(int64_t high, at::IntArrayRef size, at::TensorOptions options = at::kLong) {
488
+ at::AutoDispatchBelowADInplaceOrView guard;
489
+ return autograd::make_variable(at::randint(high, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
490
+ }
491
+ inline at::Tensor randint_symint(c10::SymInt high, c10::SymIntArrayRef size, at::TensorOptions options = at::kLong) {
492
+ at::AutoDispatchBelowADInplaceOrView guard;
493
+ return autograd::make_variable(at::randint_symint(high, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
494
+ }
495
+ inline at::Tensor randint(int64_t high, at::IntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
496
+ at::AutoDispatchBelowADInplaceOrView guard;
497
+ return autograd::make_variable(at::randint(high, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
498
+ }
499
+ inline at::Tensor randint_symint(c10::SymInt high, c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
500
+ at::AutoDispatchBelowADInplaceOrView guard;
501
+ return autograd::make_variable(at::randint_symint(high, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
502
+ }
503
+ inline at::Tensor randint(int64_t low, int64_t high, at::IntArrayRef size, at::TensorOptions options = at::kLong) {
504
+ at::AutoDispatchBelowADInplaceOrView guard;
505
+ return autograd::make_variable(at::randint(low, high, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
506
+ }
507
+ inline at::Tensor randint_symint(c10::SymInt low, c10::SymInt high, c10::SymIntArrayRef size, at::TensorOptions options = at::kLong) {
508
+ at::AutoDispatchBelowADInplaceOrView guard;
509
+ return autograd::make_variable(at::randint_symint(low, high, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
510
+ }
511
+ inline at::Tensor randint(int64_t low, int64_t high, at::IntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
512
+ at::AutoDispatchBelowADInplaceOrView guard;
513
+ return autograd::make_variable(at::randint(low, high, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
514
+ }
515
+ inline at::Tensor randint_symint(c10::SymInt low, c10::SymInt high, c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
516
+ at::AutoDispatchBelowADInplaceOrView guard;
517
+ return autograd::make_variable(at::randint_symint(low, high, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
518
+ }
519
+ inline at::Tensor randint_like(const at::Tensor & self, int64_t high, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
520
+ at::AutoDispatchBelowADInplaceOrView guard;
521
+ return autograd::make_variable(at::randint_like(self, high, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
522
+ }
523
+ inline at::Tensor randint_like_symint(const at::Tensor & self, c10::SymInt high, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
524
+ at::AutoDispatchBelowADInplaceOrView guard;
525
+ return autograd::make_variable(at::randint_like_symint(self, high, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
526
+ }
527
+ inline at::Tensor randint_like(const at::Tensor & self, int64_t high, ::std::optional<at::Generator> generator, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
528
+ at::AutoDispatchBelowADInplaceOrView guard;
529
+ return autograd::make_variable(at::randint_like(self, high, generator, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
530
+ }
531
+ inline at::Tensor randint_like_symint(const at::Tensor & self, c10::SymInt high, ::std::optional<at::Generator> generator, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
532
+ at::AutoDispatchBelowADInplaceOrView guard;
533
+ return autograd::make_variable(at::randint_like_symint(self, high, generator, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
534
+ }
535
+ inline at::Tensor randint_like(const at::Tensor & self, const at::Tensor & high, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
536
+ at::AutoDispatchBelowADInplaceOrView guard;
537
+ return autograd::make_variable(at::randint_like(self, high, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
538
+ }
539
+ inline at::Tensor randint_like(const at::Tensor & self, const at::Tensor & high, ::std::optional<at::Generator> generator, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
540
+ at::AutoDispatchBelowADInplaceOrView guard;
541
+ return autograd::make_variable(at::randint_like(self, high, generator, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
542
+ }
543
+ inline at::Tensor randint_like(const at::Tensor & self, int64_t low, int64_t high, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
544
+ at::AutoDispatchBelowADInplaceOrView guard;
545
+ return autograd::make_variable(at::randint_like(self, low, high, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
546
+ }
547
+ inline at::Tensor randint_like_symint(const at::Tensor & self, c10::SymInt low, c10::SymInt high, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
548
+ at::AutoDispatchBelowADInplaceOrView guard;
549
+ return autograd::make_variable(at::randint_like_symint(self, low, high, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
550
+ }
551
+ inline at::Tensor randint_like(const at::Tensor & self, int64_t low, int64_t high, ::std::optional<at::Generator> generator, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
552
+ at::AutoDispatchBelowADInplaceOrView guard;
553
+ return autograd::make_variable(at::randint_like(self, low, high, generator, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
554
+ }
555
+ inline at::Tensor randint_like_symint(const at::Tensor & self, c10::SymInt low, c10::SymInt high, ::std::optional<at::Generator> generator, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
556
+ at::AutoDispatchBelowADInplaceOrView guard;
557
+ return autograd::make_variable(at::randint_like_symint(self, low, high, generator, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
558
+ }
559
+ inline at::Tensor randn(at::IntArrayRef size, at::TensorOptions options = {}) {
560
+ at::AutoDispatchBelowADInplaceOrView guard;
561
+ return autograd::make_variable(at::randn(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
562
+ }
563
+ inline at::Tensor randn_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}) {
564
+ at::AutoDispatchBelowADInplaceOrView guard;
565
+ return autograd::make_variable(at::randn_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
566
+ }
567
+ inline at::Tensor randn(at::IntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = {}) {
568
+ at::AutoDispatchBelowADInplaceOrView guard;
569
+ return autograd::make_variable(at::randn(size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
570
+ }
571
+ inline at::Tensor randn_symint(c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = {}) {
572
+ at::AutoDispatchBelowADInplaceOrView guard;
573
+ return autograd::make_variable(at::randn_symint(size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
574
+ }
575
+ inline at::Tensor randn(at::IntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
576
+ at::AutoDispatchBelowADInplaceOrView guard;
577
+ return autograd::make_variable(at::randn(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
578
+ }
579
+ inline at::Tensor randn_symint(c10::SymIntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
580
+ at::AutoDispatchBelowADInplaceOrView guard;
581
+ return autograd::make_variable(at::randn_symint(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
582
+ }
583
+ inline at::Tensor randn(at::IntArrayRef size, ::std::optional<at::Generator> generator, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
584
+ at::AutoDispatchBelowADInplaceOrView guard;
585
+ return autograd::make_variable(at::randn(size, generator, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
586
+ }
587
+ inline at::Tensor randn_symint(c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
588
+ at::AutoDispatchBelowADInplaceOrView guard;
589
+ return autograd::make_variable(at::randn_symint(size, generator, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
590
+ }
591
+ inline at::Tensor randn_like(const at::Tensor & self, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
592
+ at::AutoDispatchBelowADInplaceOrView guard;
593
+ return autograd::make_variable(at::randn_like(self, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
594
+ }
595
+ inline at::Tensor randn_like(const at::Tensor & self, ::std::optional<at::Generator> generator, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
596
+ at::AutoDispatchBelowADInplaceOrView guard;
597
+ return autograd::make_variable(at::randn_like(self, generator, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
598
+ }
599
+ inline at::Tensor randperm(int64_t n, at::TensorOptions options = at::kLong) {
600
+ at::AutoDispatchBelowADInplaceOrView guard;
601
+ return autograd::make_variable(at::randperm(n, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
602
+ }
603
+ inline at::Tensor randperm_symint(c10::SymInt n, at::TensorOptions options = at::kLong) {
604
+ at::AutoDispatchBelowADInplaceOrView guard;
605
+ return autograd::make_variable(at::randperm_symint(n, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
606
+ }
607
+ inline at::Tensor randperm(int64_t n, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
608
+ at::AutoDispatchBelowADInplaceOrView guard;
609
+ return autograd::make_variable(at::randperm(n, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
610
+ }
611
+ inline at::Tensor randperm_symint(c10::SymInt n, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
612
+ at::AutoDispatchBelowADInplaceOrView guard;
613
+ return autograd::make_variable(at::randperm_symint(n, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
614
+ }
615
+ inline at::Tensor range(const at::Scalar & start, const at::Scalar & end, const at::Scalar & step = 1, at::TensorOptions options = {}) {
616
+ at::AutoDispatchBelowADInplaceOrView guard;
617
+ return autograd::make_variable(at::range(start, end, step, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
618
+ }
619
+ inline at::Tensor range(const at::Scalar & start, const at::Scalar & end, at::TensorOptions options = {}) {
620
+ at::AutoDispatchBelowADInplaceOrView guard;
621
+ return autograd::make_variable(at::range(start, end, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
622
+ }
623
+ inline at::Tensor zeros(at::IntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
624
+ at::AutoDispatchBelowADInplaceOrView guard;
625
+ return autograd::make_variable(at::zeros(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
626
+ }
627
+ inline at::Tensor _efficientzerotensor(at::IntArrayRef size, at::TensorOptions options = {}) {
628
+ at::AutoDispatchBelowADInplaceOrView guard;
629
+ return autograd::make_variable(at::_efficientzerotensor(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
630
+ }
631
+ inline at::Tensor _efficientzerotensor_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}) {
632
+ at::AutoDispatchBelowADInplaceOrView guard;
633
+ return autograd::make_variable(at::_efficientzerotensor_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
634
+ }
635
+ inline at::Tensor zeros(at::IntArrayRef size, at::TensorOptions options = {}) {
636
+ at::AutoDispatchBelowADInplaceOrView guard;
637
+ return autograd::make_variable(at::zeros(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
638
+ }
639
+ inline at::Tensor zeros_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}) {
640
+ at::AutoDispatchBelowADInplaceOrView guard;
641
+ return autograd::make_variable(at::zeros_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
642
+ }
643
+ inline at::Tensor zeros_like(const at::Tensor & self, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
644
+ at::AutoDispatchBelowADInplaceOrView guard;
645
+ return autograd::make_variable(at::zeros_like(self, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
646
+ }
647
+ inline at::Tensor _sparse_compressed_tensor_with_dims(int64_t nnz, int64_t dense_dim, at::IntArrayRef size, at::IntArrayRef blocksize, at::ScalarType index_dtype, at::TensorOptions options) {
648
+ at::AutoDispatchBelowADInplaceOrView guard;
649
+ return autograd::make_variable(at::_sparse_compressed_tensor_with_dims(nnz, dense_dim, size, blocksize, index_dtype, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
650
+ }
651
+ inline at::Tensor sparse_compressed_tensor(const at::Tensor & compressed_indices, const at::Tensor & plain_indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options) {
652
+ at::AutoDispatchBelowADInplaceOrView guard;
653
+ return autograd::make_variable(at::sparse_compressed_tensor(compressed_indices, plain_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
654
+ }
655
+ inline at::Tensor sparse_compressed_tensor_symint(const at::Tensor & compressed_indices, const at::Tensor & plain_indices, const at::Tensor & values, c10::SymIntArrayRef size, at::TensorOptions options) {
656
+ at::AutoDispatchBelowADInplaceOrView guard;
657
+ return autograd::make_variable(at::sparse_compressed_tensor_symint(compressed_indices, plain_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
658
+ }
659
+ inline at::Tensor sparse_csr_tensor(const at::Tensor & crow_indices, const at::Tensor & col_indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options) {
660
+ at::AutoDispatchBelowADInplaceOrView guard;
661
+ return autograd::make_variable(at::sparse_csr_tensor(crow_indices, col_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
662
+ }
663
+ inline at::Tensor sparse_csc_tensor(const at::Tensor & ccol_indices, const at::Tensor & row_indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options) {
664
+ at::AutoDispatchBelowADInplaceOrView guard;
665
+ return autograd::make_variable(at::sparse_csc_tensor(ccol_indices, row_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
666
+ }
667
+ inline at::Tensor sparse_bsr_tensor(const at::Tensor & crow_indices, const at::Tensor & col_indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options) {
668
+ at::AutoDispatchBelowADInplaceOrView guard;
669
+ return autograd::make_variable(at::sparse_bsr_tensor(crow_indices, col_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
670
+ }
671
+ inline at::Tensor sparse_bsc_tensor(const at::Tensor & ccol_indices, const at::Tensor & row_indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options) {
672
+ at::AutoDispatchBelowADInplaceOrView guard;
673
+ return autograd::make_variable(at::sparse_bsc_tensor(ccol_indices, row_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
674
+ }
675
+ inline at::Tensor sparse_compressed_tensor(const at::Tensor & compressed_indices, const at::Tensor & plain_indices, const at::Tensor & values, at::TensorOptions options) {
676
+ at::AutoDispatchBelowADInplaceOrView guard;
677
+ return autograd::make_variable(at::sparse_compressed_tensor(compressed_indices, plain_indices, values, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
678
+ }
679
+ inline at::Tensor sparse_csr_tensor(const at::Tensor & crow_indices, const at::Tensor & col_indices, const at::Tensor & values, at::TensorOptions options) {
680
+ at::AutoDispatchBelowADInplaceOrView guard;
681
+ return autograd::make_variable(at::sparse_csr_tensor(crow_indices, col_indices, values, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
682
+ }
683
+ inline at::Tensor sparse_csc_tensor(const at::Tensor & ccol_indices, const at::Tensor & row_indices, const at::Tensor & values, at::TensorOptions options) {
684
+ at::AutoDispatchBelowADInplaceOrView guard;
685
+ return autograd::make_variable(at::sparse_csc_tensor(ccol_indices, row_indices, values, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
686
+ }
687
+ inline at::Tensor sparse_bsr_tensor(const at::Tensor & crow_indices, const at::Tensor & col_indices, const at::Tensor & values, at::TensorOptions options) {
688
+ at::AutoDispatchBelowADInplaceOrView guard;
689
+ return autograd::make_variable(at::sparse_bsr_tensor(crow_indices, col_indices, values, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
690
+ }
691
+ inline at::Tensor sparse_bsc_tensor(const at::Tensor & ccol_indices, const at::Tensor & row_indices, const at::Tensor & values, at::TensorOptions options) {
692
+ at::AutoDispatchBelowADInplaceOrView guard;
693
+ return autograd::make_variable(at::sparse_bsc_tensor(ccol_indices, row_indices, values, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
694
+ }
695
+ inline at::Tensor _sparse_compressed_tensor_unsafe(const at::Tensor & compressed_indices, const at::Tensor & plain_indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options = {}) {
696
+ at::AutoDispatchBelowADInplaceOrView guard;
697
+ return autograd::make_variable(at::_sparse_compressed_tensor_unsafe(compressed_indices, plain_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
698
+ }
699
+ inline at::Tensor _sparse_compressed_tensor_unsafe_symint(const at::Tensor & compressed_indices, const at::Tensor & plain_indices, const at::Tensor & values, c10::SymIntArrayRef size, at::TensorOptions options = {}) {
700
+ at::AutoDispatchBelowADInplaceOrView guard;
701
+ return autograd::make_variable(at::_sparse_compressed_tensor_unsafe_symint(compressed_indices, plain_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
702
+ }
703
+ inline at::Tensor _sparse_csr_tensor_unsafe(const at::Tensor & crow_indices, const at::Tensor & col_indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options = {}) {
704
+ at::AutoDispatchBelowADInplaceOrView guard;
705
+ return autograd::make_variable(at::_sparse_csr_tensor_unsafe(crow_indices, col_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
706
+ }
707
+ inline at::Tensor _sparse_csc_tensor_unsafe(const at::Tensor & ccol_indices, const at::Tensor & row_indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options = {}) {
708
+ at::AutoDispatchBelowADInplaceOrView guard;
709
+ return autograd::make_variable(at::_sparse_csc_tensor_unsafe(ccol_indices, row_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
710
+ }
711
+ inline at::Tensor _sparse_bsr_tensor_unsafe(const at::Tensor & crow_indices, const at::Tensor & col_indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options = {}) {
712
+ at::AutoDispatchBelowADInplaceOrView guard;
713
+ return autograd::make_variable(at::_sparse_bsr_tensor_unsafe(crow_indices, col_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
714
+ }
715
+ inline at::Tensor _sparse_bsc_tensor_unsafe(const at::Tensor & ccol_indices, const at::Tensor & row_indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options = {}) {
716
+ at::AutoDispatchBelowADInplaceOrView guard;
717
+ return autograd::make_variable(at::_sparse_bsc_tensor_unsafe(ccol_indices, row_indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
718
+ }
719
+ inline at::Tensor sparse_coo_tensor(at::IntArrayRef size, at::TensorOptions options) {
720
+ at::AutoDispatchBelowADInplaceOrView guard;
721
+ return autograd::make_variable(at::sparse_coo_tensor(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
722
+ }
723
+ inline at::Tensor sparse_coo_tensor(const at::Tensor & indices, const at::Tensor & values, at::TensorOptions options = {}, ::std::optional<bool> is_coalesced = ::std::nullopt) {
724
+ at::AutoDispatchBelowADInplaceOrView guard;
725
+ return autograd::make_variable(at::sparse_coo_tensor(indices, values, at::TensorOptions(options).requires_grad(::std::nullopt), is_coalesced), /*requires_grad=*/options.requires_grad());
726
+ }
727
+ inline at::Tensor sparse_coo_tensor(const at::Tensor & indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options = {}, ::std::optional<bool> is_coalesced = ::std::nullopt) {
728
+ at::AutoDispatchBelowADInplaceOrView guard;
729
+ return autograd::make_variable(at::sparse_coo_tensor(indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt), is_coalesced), /*requires_grad=*/options.requires_grad());
730
+ }
731
+ inline at::Tensor _sparse_coo_tensor_unsafe(const at::Tensor & indices, const at::Tensor & values, at::IntArrayRef size, at::TensorOptions options = {}, ::std::optional<bool> is_coalesced = ::std::nullopt) {
732
+ at::AutoDispatchBelowADInplaceOrView guard;
733
+ return autograd::make_variable(at::_sparse_coo_tensor_unsafe(indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt), is_coalesced), /*requires_grad=*/options.requires_grad());
734
+ }
735
+ inline at::Tensor _sparse_coo_tensor_unsafe_symint(const at::Tensor & indices, const at::Tensor & values, c10::SymIntArrayRef size, at::TensorOptions options = {}, ::std::optional<bool> is_coalesced = ::std::nullopt) {
736
+ at::AutoDispatchBelowADInplaceOrView guard;
737
+ return autograd::make_variable(at::_sparse_coo_tensor_unsafe_symint(indices, values, size, at::TensorOptions(options).requires_grad(::std::nullopt), is_coalesced), /*requires_grad=*/options.requires_grad());
738
+ }
739
+ inline at::Tensor _sparse_coo_tensor_with_dims(int64_t sparse_dim, int64_t dense_dim, at::IntArrayRef size, at::TensorOptions options) {
740
+ at::AutoDispatchBelowADInplaceOrView guard;
741
+ return autograd::make_variable(at::_sparse_coo_tensor_with_dims(sparse_dim, dense_dim, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
742
+ }
743
+ inline at::Tensor _sparse_coo_tensor_with_dims_and_tensors(int64_t sparse_dim, int64_t dense_dim, at::IntArrayRef size, const at::Tensor & indices, const at::Tensor & values, at::TensorOptions options, ::std::optional<bool> is_coalesced = ::std::nullopt) {
744
+ at::AutoDispatchBelowADInplaceOrView guard;
745
+ return autograd::make_variable(at::_sparse_coo_tensor_with_dims_and_tensors(sparse_dim, dense_dim, size, indices, values, at::TensorOptions(options).requires_grad(::std::nullopt), is_coalesced), /*requires_grad=*/options.requires_grad());
746
+ }
747
+ inline at::Tensor _sparse_coo_tensor_with_dims_and_tensors_symint(int64_t sparse_dim, int64_t dense_dim, c10::SymIntArrayRef size, const at::Tensor & indices, const at::Tensor & values, at::TensorOptions options, ::std::optional<bool> is_coalesced = ::std::nullopt) {
748
+ at::AutoDispatchBelowADInplaceOrView guard;
749
+ return autograd::make_variable(at::_sparse_coo_tensor_with_dims_and_tensors_symint(sparse_dim, dense_dim, size, indices, values, at::TensorOptions(options).requires_grad(::std::nullopt), is_coalesced), /*requires_grad=*/options.requires_grad());
750
+ }
751
+ inline at::Tensor _to_copy(const at::Tensor & self, at::TensorOptions options = {}, bool non_blocking = false, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
752
+ at::AutoDispatchBelowADInplaceOrView guard;
753
+ return autograd::make_variable(at::_to_copy(self, at::TensorOptions(options).requires_grad(::std::nullopt), non_blocking, memory_format), /*requires_grad=*/options.requires_grad());
754
+ }
755
+ inline at::Tensor tril_indices(int64_t row, int64_t col, int64_t offset = 0, at::TensorOptions options = at::kLong) {
756
+ at::AutoDispatchBelowADInplaceOrView guard;
757
+ return autograd::make_variable(at::tril_indices(row, col, offset, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
758
+ }
759
+ inline at::Tensor triu_indices(int64_t row, int64_t col, int64_t offset = 0, at::TensorOptions options = at::kLong) {
760
+ at::AutoDispatchBelowADInplaceOrView guard;
761
+ return autograd::make_variable(at::triu_indices(row, col, offset, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
762
+ }
763
+ inline at::Tensor normal(double mean, double std, at::IntArrayRef size, ::std::optional<at::Generator> generator = ::std::nullopt, at::TensorOptions options = {}) {
764
+ at::AutoDispatchBelowADInplaceOrView guard;
765
+ return autograd::make_variable(at::normal(mean, std, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
766
+ }
767
+ inline at::Tensor normal_symint(double mean, double std, c10::SymIntArrayRef size, ::std::optional<at::Generator> generator = ::std::nullopt, at::TensorOptions options = {}) {
768
+ at::AutoDispatchBelowADInplaceOrView guard;
769
+ return autograd::make_variable(at::normal_symint(mean, std, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
770
+ }
771
+ inline at::Tensor fft_fftfreq(int64_t n, double d = 1.0, at::TensorOptions options = {}) {
772
+ at::AutoDispatchBelowADInplaceOrView guard;
773
+ return autograd::make_variable(at::fft_fftfreq(n, d, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
774
+ }
775
+ inline at::Tensor fft_rfftfreq(int64_t n, double d = 1.0, at::TensorOptions options = {}) {
776
+ at::AutoDispatchBelowADInplaceOrView guard;
777
+ return autograd::make_variable(at::fft_rfftfreq(n, d, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
778
+ }
779
+
780
+ } // namespace torch
781
+
782
+ #else
783
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
784
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/python_variable_indexing.h ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <c10/core/SymInt.h>
5
+ #include <torch/csrc/autograd/python_variable.h>
6
+ #include <torch/csrc/python_headers.h>
7
+ #include <torch/csrc/utils/pybind.h>
8
+ #include <torch/csrc/utils/python_symnode.h>
9
+
10
+ namespace torch::autograd {
11
+
12
+ struct UnpackedSlice {
13
+ c10::SymInt start;
14
+ c10::SymInt stop;
15
+ c10::SymInt step;
16
+ };
17
+
18
+ // This mirrors Cpython's PySlice_Unpack method
19
+ inline UnpackedSlice __PySlice_Unpack(PyObject* _r) {
20
+ PySliceObject* r = (PySliceObject*)_r;
21
+ /* this is harder to get right than you might think */
22
+
23
+ c10::SymInt start_sym, stop_sym, step_sym;
24
+
25
+ auto clip_val = [](Py_ssize_t val) {
26
+ if (val < c10::SymInt::min_representable_int()) {
27
+ auto r = PyErr_WarnEx(
28
+ PyExc_UserWarning,
29
+ "Truncating the start/stop/step "
30
+ "of slice. This is likely because of "
31
+ "saved old models when the start/stop/step were larger.",
32
+ 1);
33
+ if (r != 0) {
34
+ throw python_error();
35
+ }
36
+ return (Py_ssize_t)(c10::SymInt::min_representable_int());
37
+ }
38
+ return val;
39
+ };
40
+
41
+ if (r->step == Py_None) {
42
+ step_sym = c10::SymInt(1);
43
+ } else {
44
+ if (torch::is_symint(r->step)) {
45
+ step_sym = py::handle(r->step).cast<c10::SymInt>();
46
+ } else {
47
+ Py_ssize_t step = 0;
48
+ if (!_PyEval_SliceIndex(r->step, &step)) {
49
+ throw python_error();
50
+ }
51
+ if (step == 0) {
52
+ PyErr_SetString(PyExc_ValueError, "slice step cannot be zero");
53
+ }
54
+
55
+ step = clip_val(step);
56
+ step_sym = c10::SymInt(step);
57
+ }
58
+ }
59
+
60
+ if (torch::is_symint(r->start)) {
61
+ start_sym = py::handle(r->start).cast<c10::SymInt>();
62
+ } else if (r->start == Py_None) {
63
+ start_sym = c10::SymInt(step_sym < 0 ? PY_SSIZE_T_MAX : 0);
64
+ } else {
65
+ Py_ssize_t start = 0;
66
+ if (!_PyEval_SliceIndex(r->start, &start)) {
67
+ throw python_error();
68
+ }
69
+ start = clip_val(start);
70
+ start_sym = c10::SymInt(start);
71
+ }
72
+
73
+ if (torch::is_symint(r->stop)) {
74
+ stop_sym = py::handle(r->stop).cast<c10::SymInt>();
75
+ } else if (r->stop == Py_None) {
76
+ stop_sym = c10::SymInt(
77
+ step_sym < 0 ? c10::SymInt::min_representable_int() : PY_SSIZE_T_MAX);
78
+ } else {
79
+ Py_ssize_t stop = 0;
80
+ if (!_PyEval_SliceIndex(r->stop, &stop)) {
81
+ throw python_error();
82
+ }
83
+ stop = clip_val(stop);
84
+ stop_sym = c10::SymInt(stop);
85
+ }
86
+
87
+ return UnpackedSlice{
88
+ std::move(start_sym), std::move(stop_sym), std::move(step_sym)};
89
+ }
90
+
91
+ Py_ssize_t THPVariable_length(PyObject* self);
92
+ PyObject* THPVariable_getitem(PyObject* self, PyObject* index);
93
+ int THPVariable_setitem(PyObject* self, PyObject* index, PyObject* value);
94
+
95
+ Variable valueToTensor(
96
+ c10::TensorOptions options,
97
+ PyObject* value,
98
+ const at::Device& device);
99
+
100
+ } // namespace torch::autograd
101
+
102
+ #else
103
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
104
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/record_function_ops.h ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ #include <ATen/record_function.h>
4
+ #include <torch/custom_class.h>
5
+ #include <optional>
6
+
7
+ namespace torch::autograd::profiler {
8
+
9
+ struct PythonRecordFunction : public torch::CustomClassHolder {
10
+ at::RecordFunction record;
11
+
12
+ explicit PythonRecordFunction(
13
+ at::RecordScope scope = at::RecordScope::FUNCTION)
14
+ : record(scope) {}
15
+ };
16
+
17
+ // Creates a new profiling scope using RecordFunction and invokes its starting
18
+ // callbacks.
19
+ TORCH_API c10::intrusive_ptr<PythonRecordFunction> record_function_enter_new(
20
+ const std::string& name,
21
+ const std::optional<std::string>& args = std::nullopt);
22
+
23
+ // Schedules RecordFunction's end callbacks to be run on completion of a future.
24
+ TORCH_API c10::intrusive_ptr<c10::ivalue::Future> _call_end_callbacks_on_fut_new(
25
+ const c10::intrusive_ptr<PythonRecordFunction>& record,
26
+ const c10::intrusive_ptr<c10::ivalue::Future>& fut);
27
+
28
+ } // namespace torch::autograd::profiler
29
+
30
+ #else
31
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
32
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/saved_variable.h ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <c10/core/SafePyObject.h>
5
+ #include <torch/csrc/Export.h>
6
+ #include <torch/csrc/autograd/forward_grad.h>
7
+ #include <torch/csrc/autograd/saved_variable_hooks.h>
8
+
9
+ #include <ATen/core/Tensor.h>
10
+
11
+ #include <cstdint>
12
+ #include <memory>
13
+
14
+ namespace torch::autograd {
15
+
16
+ using Variable = at::Tensor;
17
+ struct Node;
18
+
19
+ TORCH_API extern const char* ERR_BACKWARD_TWICE;
20
+
21
+ /// A snapshot of a variable at a certain version. A `SavedVariable` stores
22
+ /// enough information to reconstruct a variable from a certain point in time.
23
+ class TORCH_API SavedVariable {
24
+ public:
25
+ SavedVariable() = default;
26
+ SavedVariable(
27
+ const Variable& variable,
28
+ bool is_output,
29
+ bool is_inplace_on_view = false);
30
+ SavedVariable(
31
+ const std::optional<Variable>& variable,
32
+ bool is_output,
33
+ bool is_inplace_on_view = false);
34
+ SavedVariable(const SavedVariable&) = delete;
35
+ SavedVariable(SavedVariable&&) = default;
36
+ SavedVariable& operator=(const SavedVariable&) = delete;
37
+ SavedVariable& operator=(SavedVariable&&) = default;
38
+ ~SavedVariable() {
39
+ if (fw_grad_) {
40
+ // See note [ Using ForwardGrad ]
41
+ fw_grad_->clear();
42
+ }
43
+ }
44
+
45
+ /// Reconstructs the saved variable. Pass `saved_for` as the gradient
46
+ /// function if constructing the `SavedVariable` with it would have caused a
47
+ /// circular reference.
48
+ Variable unpack(std::shared_ptr<Node> saved_for = nullptr) const;
49
+
50
+ void register_hooks(std::unique_ptr<SavedVariableHooks>&& hooks);
51
+
52
+ void reset_data();
53
+
54
+ bool has_hooks() const {
55
+ return (bool)hooks_;
56
+ }
57
+
58
+ std::optional<at::Tensor> get_raw_data() const {
59
+ if (hooks_) {
60
+ return std::nullopt;
61
+ } else {
62
+ return data_;
63
+ }
64
+ }
65
+
66
+ // Used by compiled autograd
67
+ std::optional<std::pair<c10::SafePyObject, c10::SafePyObject>>
68
+ retrieve_unpack_hook_data() const {
69
+ if (!hooks_) {
70
+ return std::nullopt;
71
+ }
72
+ return hooks_->retrieve_unpack_hook_data();
73
+ }
74
+
75
+ private:
76
+ // This field contains either:
77
+ // 1. the variable to save
78
+ // 2. or its tensor_data.
79
+ // If storing the variable itself would create a circular reference,
80
+ // we fall into the second case and its metadata is also saved separately.
81
+ // In that case, the grad_fn must be passed in to the unpack function when
82
+ // reconstructing the Variable (except when we are doing an inplace operation
83
+ // on a view, see below). The field saved_original_ below reflects the two
84
+ // cases: its value is true in the first case and false in the second case.
85
+ // The value data_.defined() can be false in three cases:
86
+ // 1. SavedVariable was constructed without a Tensor (the value to save is
87
+ // None), in that case was_default_constructed_ will be kept at true
88
+ // 2. The saved variable has been released by calling
89
+ // SavedVariable::reset_data(), typically during the backward pass
90
+ // 3. Hooks have been registered. In that case, hooks_ will be defined
91
+ // instead. Note that the value of saved_original_ only reflects what happened
92
+ // during the construction of the SavedVariable. If saved_original_ is true,
93
+ // we saved the original tensor in data_, but if the user registers hooks, we
94
+ // will no longer have it (despite the saved_original_ still being true)
95
+ at::Tensor data_;
96
+
97
+ // This field is used to store the forward AD gradients associated with
98
+ // the saved Tensor. Note that this shared_ptr must never be shared with
99
+ // either the saved Tensor or the unpacked Tensor. See note [ Using
100
+ // ForwardGrad ]
101
+ std::shared_ptr<ForwardGrad> fw_grad_;
102
+
103
+ // Weak version of grad_fn_ that prevents leaks in rebase_history() for
104
+ // inplace views.
105
+ // This variable is used when the user chooses to create a SavedVariable with
106
+ // is_inplace_on_view = true.
107
+ // In that case, the grad_fn passed in to the unpack function at unwrapping
108
+ // time is unused.
109
+ std::weak_ptr<Node> weak_grad_fn_;
110
+
111
+ uint32_t saved_version_ = 0;
112
+ uint32_t output_nr_ = 0;
113
+ bool was_default_constructed_ = true;
114
+ bool is_inplace_on_view_ = false;
115
+ bool saved_original_ = false;
116
+ bool is_leaf_ = false;
117
+ bool is_output_ = false;
118
+
119
+ // Hooks are a pair of functions pack_hook/unpack_hook that provides
120
+ // fine-grained control over how the SavedVariable should save its data.
121
+ // pack_hook is called upon registration, while unpack_hook is called when
122
+ // unpacking.
123
+ std::unique_ptr<SavedVariableHooks> hooks_;
124
+ // Fields grad_fn_, grad_accumulator_, and requires_grad_ are only used if
125
+ // hooks are defined. They are set before pack_hook is called and used after
126
+ // unpack_hook is called.
127
+ std::shared_ptr<Node> grad_fn_;
128
+ // For the usual case where leaf tensors are the input, we expect its
129
+ // grad_acc to be kept alive by the graph. The reason SavedVariable holds
130
+ // a owning reference is to support the case where a custom autograd Function
131
+ // saves an intermediate.
132
+ std::shared_ptr<Node> grad_accumulator_;
133
+ bool requires_grad_ = false;
134
+
135
+ void save_metadata(const Variable& data);
136
+ static std::unique_ptr<SavedVariableHooks> get_default_hooks();
137
+ void set_hooks_and_pack_data(
138
+ std::unique_ptr<SavedVariableHooks>&& hooks,
139
+ const Variable& data);
140
+ };
141
+ } // namespace torch::autograd
142
+
143
+ #else
144
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
145
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/saved_variable_hooks.h ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <ATen/core/Tensor.h>
5
+ #include <c10/core/SafePyObject.h>
6
+
7
+ namespace torch::autograd {
8
+
9
+ struct TORCH_API SavedVariableHooks {
10
+ virtual void call_pack_hook(const at::Tensor& tensor) = 0;
11
+ virtual at::Tensor call_unpack_hook() = 0;
12
+ virtual ~SavedVariableHooks() = default;
13
+ virtual std::optional<std::pair<c10::SafePyObject, c10::SafePyObject>>
14
+ retrieve_unpack_hook_data() const {
15
+ TORCH_CHECK(
16
+ false, "Compiled Autograd only supports python saved tensor hooks ");
17
+ }
18
+ };
19
+
20
+ } // namespace torch::autograd
21
+
22
+ #else
23
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
24
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/symbolic.h ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/jit/ir/ir.h>
5
+ #include <torch/csrc/onnx/onnx.h>
6
+
7
+ namespace torch::autograd {
8
+
9
+ struct SymbolicContext {
10
+ jit::Block* block;
11
+ };
12
+
13
+ struct symbolic_unconvertible : public std::runtime_error {
14
+ using std::runtime_error::runtime_error;
15
+ };
16
+
17
+ } // namespace torch::autograd
18
+
19
+ #else
20
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
21
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/error_messages.h ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <sstream>
5
+
6
+ namespace torch::autograd::utils {
7
+
8
+ inline std::string requires_grad_leaf_error(bool requires_grad) {
9
+ std::ostringstream oss;
10
+ oss << "you can only change requires_grad flags of leaf variables.";
11
+ if (requires_grad == false) {
12
+ oss << " If you want to use a computed variable in a subgraph "
13
+ "that doesn't require differentiation use "
14
+ "var_no_grad = var.detach().";
15
+ }
16
+ return oss.str();
17
+ }
18
+
19
+ } // namespace torch::autograd::utils
20
+
21
+ #else
22
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
23
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/grad_layout_contract.h ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <ATen/Tensor.h>
5
+
6
+ namespace torch::autograd::utils {
7
+
8
+ // Helper functions to enforce the "Gradient Layout Contract" described in
9
+ // torch/csrc/autograd/functions/accumulate_grad.h.
10
+
11
+ // Checks if grad obeys the contract with variable.
12
+ inline bool obeys_layout_contract(
13
+ const at::Tensor& grad,
14
+ const at::Tensor& variable) {
15
+ TORCH_INTERNAL_ASSERT(!grad.is_sparse());
16
+ TORCH_INTERNAL_ASSERT(!grad.is_sparse_csr());
17
+ TORCH_INTERNAL_ASSERT(!variable.is_sparse_csr());
18
+
19
+ // NOLINTNEXTLINE(bugprone-branch-clone)
20
+ if (variable.is_nested()) {
21
+ // TODO: Nested Tensor does not have an implementation of detach. The
22
+ // current implementation of nested tensor likely does obey the gradient
23
+ // contract and should return true, but this would likely change in the
24
+ // future
25
+ return false;
26
+ } else if (variable.is_sparse()) {
27
+ // Gradient Layout Contract is not applicable for sparse layouts
28
+ return false;
29
+ } else if (variable.is_non_overlapping_and_dense()) {
30
+ // Only look at stride for dimensions that are not of size 1.
31
+ const auto& grad_sizes = grad.sym_sizes();
32
+ const auto& grad_strides = grad.sym_strides();
33
+ const auto& variable_strides = variable.sym_strides();
34
+ for (const auto idx : c10::irange(grad_sizes.size())) {
35
+ if (grad_sizes[idx] != 1) {
36
+ if (grad_strides[idx] != variable_strides[idx]) {
37
+ return false;
38
+ }
39
+ } else {
40
+ // This should not be needed but we don't check if a Tensor has views
41
+ // before stashing it. And 0-strided Tensors of size 1 are actually
42
+ // views for ops like cat.
43
+ // TODO: Actually detect views in the accumulateGrad function so that
44
+ // this Tensor is not considered at all.
45
+ if (grad_strides[idx] == 0) {
46
+ return false;
47
+ }
48
+ }
49
+ }
50
+ return true;
51
+ } else {
52
+ return grad.is_contiguous(at::MemoryFormat::Contiguous);
53
+ }
54
+ }
55
+
56
+ // Creates a clone of new_grad that obeys the contract with variable.
57
+ // The clone should attach to new_grad's history if GradMode::is_enabled().
58
+ inline at::Tensor clone_obey_contract(
59
+ const at::Tensor& new_grad,
60
+ const at::Tensor& variable) {
61
+ if (variable.is_non_overlapping_and_dense()) {
62
+ // (1)
63
+ // Does this dicey-looking sequence attach the result to new_grad's
64
+ // history if GradMode::is_enabled()? Yes, and @alband says it should.
65
+ return std::move(new_grad
66
+ .new_empty_strided_symint(
67
+ variable.sym_sizes(),
68
+ variable.sym_strides(),
69
+ variable.options()
70
+ .memory_format(std::nullopt)
71
+ .dtype(new_grad.dtype()))
72
+ .copy_(new_grad));
73
+ } else {
74
+ // (2)
75
+ return new_grad.clone(at::MemoryFormat::Contiguous);
76
+ }
77
+ }
78
+
79
+ } // namespace torch::autograd::utils
80
+
81
+ #else
82
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
83
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/lambda_post_hook.h ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/autograd/function_hook.h>
5
+ #include <torch/csrc/dynamo/compiled_autograd.h>
6
+
7
+ namespace torch::autograd::utils {
8
+
9
+ // Turns lambda into a torch::autograd::FunctionPostHook.
10
+ class LambdaPostHook : public torch::autograd::FunctionPostHook {
11
+ using variable_list = std::vector<torch::autograd::Variable>;
12
+ using fn_type =
13
+ std::function<variable_list(const variable_list&, const variable_list&)>;
14
+ using compiled_fn_type = std::function<void(CompiledNodeArgs&)>;
15
+
16
+ public:
17
+ // The lambda function takes as arguments the outputs and inputs of the
18
+ // autograd function and can modify the outputs of the autograd function by
19
+ // returning a new output if needed.
20
+ /* implicit */ LambdaPostHook(fn_type fn) : fn_(std::move(fn)) {}
21
+
22
+ LambdaPostHook(fn_type fn, compiled_fn_type compiled_fn)
23
+ : fn_(std::move(fn)), compiled_fn_(std::move(compiled_fn)) {}
24
+
25
+ variable_list operator()(
26
+ const variable_list& outputs,
27
+ const variable_list& inputs) override {
28
+ return fn_(outputs, inputs);
29
+ }
30
+
31
+ void compiled_args(CompiledNodeArgs& args) const override {
32
+ if (compiled_fn_ != nullptr) {
33
+ return compiled_fn_(args);
34
+ }
35
+ return FunctionPostHook::compiled_args(args);
36
+ }
37
+
38
+ protected:
39
+ std::function<variable_list(const variable_list&, const variable_list&)> fn_;
40
+ compiled_fn_type compiled_fn_;
41
+ };
42
+
43
+ } // namespace torch::autograd::utils
44
+
45
+ #else
46
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
47
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/python_arg_parsing.h ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <ATen/core/Tensor.h>
5
+ #include <torch/csrc/python_headers.h>
6
+
7
+ #include <torch/csrc/utils/python_arg_parser.h>
8
+
9
+ namespace torch::autograd::utils {
10
+
11
+ // The parameter allow_copy is to accept copy for Tensor.to (and by proxy
12
+ // PackedSequences.to) but not nn.Module.to.
13
+ inline std::tuple<
14
+ std::optional<at::Device>,
15
+ std::optional<at::ScalarType>,
16
+ bool,
17
+ bool,
18
+ std::optional<at::MemoryFormat>>
19
+ parse_to_conversion(PythonArgs& r, bool allow_copy) {
20
+ if (r.idx == 0) {
21
+ TORCH_CHECK(
22
+ allow_copy || r.isNone(3), ".to() does not accept copy argument");
23
+ return std::make_tuple(
24
+ r.deviceOptional(0),
25
+ r.scalartypeOptional(1),
26
+ r.toBool(2),
27
+ r.toBool(3),
28
+ r.memoryformatOptional(4));
29
+ } else if (r.idx == 1) {
30
+ TORCH_CHECK(
31
+ allow_copy || r.isNone(2), ".to() does not accept copy argument");
32
+ return std::make_tuple(
33
+ std::nullopt,
34
+ r.scalartype(0),
35
+ r.toBool(1),
36
+ r.toBool(2),
37
+ r.memoryformatOptional(3));
38
+ } else {
39
+ auto tensor = r.tensor(0);
40
+ TORCH_CHECK(
41
+ allow_copy || r.isNone(2), ".to() does not accept copy argument");
42
+ return std::make_tuple(
43
+ tensor.device(),
44
+ tensor.scalar_type(),
45
+ r.toBool(1),
46
+ r.toBool(2),
47
+ r.memoryformatOptional(3));
48
+ }
49
+ }
50
+ } // namespace torch::autograd::utils
51
+
52
+ #else
53
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
54
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/warnings.h ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ #include <c10/util/Exception.h>
4
+
5
+ #include <mutex>
6
+ #include <vector>
7
+
8
+ namespace torch::autograd::utils {
9
+
10
+ // Warning handler for multi-threaded contexts. Gather warnings from
11
+ // all threads into a single queue, then process together at the end
12
+ // in the main thread.
13
+ class DelayWarningHandler : public at::WarningHandler {
14
+ public:
15
+ ~DelayWarningHandler() override = default;
16
+ void replay_warnings();
17
+
18
+ private:
19
+ void process(const c10::Warning& warning) override;
20
+
21
+ std::vector<c10::Warning> warnings_;
22
+ std::mutex mutex_;
23
+ };
24
+
25
+ } // namespace torch::autograd::utils
26
+
27
+ #else
28
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
29
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/wrap_outputs.h ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ // Wrap tensor operation outputs as PyObject*
5
+
6
+ #include <ATen/ScalarOps.h>
7
+ #include <ATen/core/Tensor.h>
8
+ #include <c10/util/irange.h>
9
+ #include <torch/csrc/python_headers.h>
10
+ #include <initializer_list>
11
+ #include <tuple>
12
+
13
+ #include <torch/csrc/Dtype.h>
14
+ #include <torch/csrc/DynamicTypes.h>
15
+ #include <torch/csrc/Layout.h>
16
+ #include <torch/csrc/QScheme.h>
17
+ #include <torch/csrc/autograd/python_variable.h>
18
+ #include <torch/csrc/autograd/variable.h>
19
+ #include <torch/csrc/utils/python_numbers.h>
20
+ #include <torch/csrc/utils/tensor_qschemes.h>
21
+
22
+ namespace torch::autograd::utils {
23
+
24
+ inline PyObject* wrap(bool value) {
25
+ if (value) {
26
+ Py_RETURN_TRUE;
27
+ } else {
28
+ Py_RETURN_FALSE;
29
+ }
30
+ }
31
+
32
+ inline PyObject* wrap(c10::DeviceIndex value) {
33
+ return THPUtils_packDeviceIndex(value);
34
+ }
35
+
36
+ inline PyObject* wrap(int64_t value) {
37
+ return THPUtils_packInt64(value);
38
+ }
39
+
40
+ inline PyObject* wrap(double value) {
41
+ return PyFloat_FromDouble(value);
42
+ }
43
+
44
+ inline PyObject* wrap(c10::complex<double> value) {
45
+ // I could probably also use FromComplex with a reinterpret cast,
46
+ // but... eh.
47
+ return PyComplex_FromDoubles(value.real(), value.imag());
48
+ }
49
+
50
+ inline PyObject* wrap(void* value) {
51
+ return PyLong_FromVoidPtr(value);
52
+ }
53
+
54
+ inline PyObject* wrap(THPDtype* dtype) {
55
+ return Py_NewRef(dtype);
56
+ }
57
+
58
+ inline PyObject* wrap(at::ScalarType scalarType) {
59
+ return Py_NewRef(getTHPDtype(scalarType));
60
+ }
61
+
62
+ inline PyObject* wrap(THPLayout* layout) {
63
+ return Py_NewRef(layout);
64
+ }
65
+
66
+ inline PyObject* wrap(at::Layout layout) {
67
+ return Py_NewRef(getTHPLayout(layout));
68
+ }
69
+
70
+ inline PyObject* wrap(const at::Tensor& tensor) {
71
+ return THPVariable_Wrap(tensor);
72
+ }
73
+
74
+ inline PyObject* wrap(at::Tensor&& tensor) {
75
+ return THPVariable_Wrap(std::move(tensor));
76
+ }
77
+
78
+ inline PyObject* wrap(const at::Scalar& scalar) {
79
+ return wrap(scalar_to_tensor(scalar));
80
+ }
81
+
82
+ inline PyObject* wrap(at::QScheme qscheme) {
83
+ auto* thp_qscheme = torch::utils::getTHPQScheme(qscheme);
84
+ Py_INCREF(thp_qscheme);
85
+ return thp_qscheme;
86
+ }
87
+
88
+ inline PyObject* wrap(at::TensorList tl) {
89
+ auto r = THPObjectPtr{PyTuple_New(static_cast<Py_ssize_t>(tl.size()))};
90
+ if (!r)
91
+ throw python_error();
92
+ for (const auto i : c10::irange(tl.size())) {
93
+ PyTuple_SET_ITEM(r.get(), i, wrap(tl[i]));
94
+ }
95
+ return r.release();
96
+ }
97
+
98
+ inline PyObject* wrap(at::IntArrayRef list) {
99
+ auto r = THPObjectPtr{PyTuple_New(static_cast<Py_ssize_t>(list.size()))};
100
+ if (!r)
101
+ throw python_error();
102
+ for (const auto i : c10::irange(list.size())) {
103
+ PyTuple_SET_ITEM(r.get(), i, wrap(list[i]));
104
+ }
105
+ return r.release();
106
+ }
107
+
108
+ inline PyObject* wrap(at::Stream stream) {
109
+ return THPStream_Wrap(stream);
110
+ }
111
+
112
+ namespace detail {
113
+ template <typename F, typename Tuple, size_t... Is>
114
+ void apply_with_idx_impl(
115
+ const F& f,
116
+ Tuple& t,
117
+ std::index_sequence<Is...> /*indices*/) {
118
+ (void)std::initializer_list<int>{(f(std::get<Is>(t), Is), 0)...};
119
+ }
120
+
121
+ // For tuple(a, b, c), calls f(a, 0), f(b, 1), f(c, 2)
122
+ template <typename F, typename... Ts>
123
+ void apply_with_idx(const F& f, std::tuple<Ts...>& t) {
124
+ apply_with_idx_impl(f, t, std::index_sequence_for<Ts...>{});
125
+ }
126
+ } // namespace detail
127
+
128
+ template <typename... Ts>
129
+ PyObject* wrap(std::tuple<Ts...> values) {
130
+ auto r = THPObjectPtr{PyTuple_New(sizeof...(Ts))};
131
+ if (!r)
132
+ throw python_error();
133
+ detail::apply_with_idx(
134
+ [&](auto& value, size_t idx) {
135
+ PyTuple_SET_ITEM(r.get(), idx, wrap(std::move(value)));
136
+ },
137
+ values);
138
+ return r.release();
139
+ }
140
+
141
+ template <typename... Ts>
142
+ PyObject* wrap(PyTypeObject* type, std::tuple<Ts...> values) {
143
+ auto r = THPObjectPtr{PyStructSequence_New(type)};
144
+ if (!r)
145
+ throw python_error();
146
+ detail::apply_with_idx(
147
+ [&](auto& value, size_t idx) {
148
+ PyStructSequence_SET_ITEM(r.get(), idx, wrap(std::move(value)));
149
+ },
150
+ values);
151
+ return r.release();
152
+ }
153
+
154
+ } // namespace torch::autograd::utils
155
+
156
+ #else
157
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
158
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/variable.h ADDED
@@ -0,0 +1,1016 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/utils/python_stub.h>
5
+
6
+ #include <torch/csrc/Export.h>
7
+ #include <torch/csrc/autograd/cpp_hook.h>
8
+ #include <torch/csrc/autograd/edge.h>
9
+ #include <torch/csrc/autograd/forward_grad.h>
10
+ #include <torch/csrc/autograd/function_hook.h>
11
+
12
+ #include <ATen/NamedTensorUtils.h>
13
+ #include <ATen/core/Tensor.h>
14
+ #include <ATen/core/VariableHooksInterface.h>
15
+ #include <c10/util/Exception.h>
16
+
17
+ #include <cstdint>
18
+ #include <memory>
19
+ #include <mutex>
20
+ #include <string>
21
+ #include <utility>
22
+ #include <vector>
23
+
24
+ namespace torch::autograd {
25
+
26
+ /// `Variable` is exactly the same as `Tensor` (i.e. we have `using Variable =
27
+ /// at::Tensor`). This means you can perform all the usual mathematical and
28
+ /// other operations you can perform on `Tensor`s also on `Variable`s.
29
+ ///
30
+ /// The only reason we are keeping the `Variable` class is backward
31
+ /// compatibility with external user's legacy C++ frontend code. Our intention
32
+ /// is to eliminate the `Variable` class in the near future.
33
+ using Variable = at::Tensor;
34
+
35
+ } // namespace torch::autograd
36
+
37
+ // The following are all internal APIs and should not be shown in libtorch docs.
38
+ // Therefore, we wrap the following code with `#ifndef DOXYGEN_SHOULD_SKIP_THIS
39
+ // ... #endif`
40
+
41
+ #ifndef DOXYGEN_SHOULD_SKIP_THIS
42
+
43
+ namespace torch::autograd {
44
+
45
+ /// Check if this type is supported by the autograd engine.
46
+ /// If you change this, update the doc at the top of the
47
+ /// torch/autograd/__init__.py file and
48
+ /// "test_set_requires_grad_only_for_continuous_types" in test/test_autograd.py
49
+ inline bool isDifferentiableType(at::ScalarType t) {
50
+ return isFloatingType(t) || isComplexType(t);
51
+ }
52
+
53
+ struct Node;
54
+
55
+ ///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56
+ /// Variable
57
+ ///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
+ /// A `Variable` augments a `Tensor` with the ability to interact in our
59
+ /// autograd machinery. Conceptually, `Variable`s travel along `Edge`s between
60
+ /// `Node`s in the autograd graph. A `Variable` can either be a leaf, like a
61
+ /// weight in a neural network, or an interior variable, when it is the result
62
+ /// of an operation between variables. Every `Variable` also stores another
63
+ /// `Variable` called its `grad` (gradient). If the variable is a leaf, its
64
+ /// gradient will be accumulated into this variable.
65
+ ///
66
+ /// Every Tensor is a Variable, but sometimes we colloquially refer to Variables
67
+ /// that don't require gradients as Tensors (since none of the autograd
68
+ /// machinery for Variables applies). Historically, Variables and Tensors
69
+ /// were separate concepts, but now they are exactly the same (i.e. we have
70
+ /// `using Variable = at::Tensor`).
71
+ ///
72
+ /// Gradient Edges
73
+ ///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74
+ /// Furthermore, `Variable`s have the notion of a `gradient_edge`, which is the
75
+ /// edge in the autograd graph that connects the variable to a particular input
76
+ /// of the gradient function that will be invoked with the variable during the
77
+ /// backward pass. More precisely, this gradient function can be one of two
78
+ /// things:
79
+ /// 1. A `grad_fn`, if the variable is in the interior of the graph. This is the
80
+ /// gradient of the function that produced the variable.
81
+ /// 2. A `grad_accumulator`, if the variable is a leaf, which accumulates a
82
+ /// scalar gradient value into its `grad` variable.
83
+ ///
84
+ /// Versioning
85
+ ///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86
+ /// Another major feature of `Variable`s are *versions*. Versions are
87
+ /// incremented when an in-place mutation of a variable occurs. Versions are
88
+ /// useful when constructing `SavedVariable`s, which take a snapshot of a
89
+ /// `Variable` at a certain version. You can retrieve a `Variable`'s version
90
+ /// through its `current_version()` method.
91
+ ///
92
+ /// Views
93
+ ///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94
+ /// It is possible for a `Variable` to be a *view* of another `Variable`, in
95
+ /// which case it tracks that `Variable`'s data and autograd history. Beyond
96
+ /// construction, the interface of a view is identical to that of a regular
97
+ /// `Variable`. You can determine whether `Variable` is in fact a view by
98
+ /// probing its `is_view()` method. Note that the *view* semantics are only
99
+ /// meaningful for `Variable` relations that are relevant to autograd.
100
+ /// See NOTE [ Autograd View Variables ] for more details.
101
+ ///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
102
+
103
+ struct AutogradMeta;
104
+ struct DifferentiableViewMeta;
105
+
106
+ // Private-ish functions for manipulating variables; we don't want to put them
107
+ // on Tensor proper
108
+ namespace impl {
109
+
110
+ // WARNING: This may return a nullptr. If you require AutogradMeta to return
111
+ // a materialized structure, use materialize_autograd_meta instead.
112
+ TORCH_API AutogradMeta* get_autograd_meta(const at::TensorBase& /*self*/);
113
+
114
+ // WARNING: This will return a nullptr if the Tensor is not a view.
115
+ TORCH_API DifferentiableViewMeta* get_view_autograd_meta(
116
+ const at::TensorBase& /*self*/);
117
+
118
+ // Returns the current autograd meta, materializing it if it was previously
119
+ // none. This counts as a *mutating* operation, so do not call it on
120
+ // "read-only" operators; in particular, this is NOT thread safe
121
+ TORCH_API AutogradMeta* materialize_autograd_meta(
122
+ const at::TensorBase& /*self*/);
123
+
124
+ /// Set the gradient accumulator of the `Variable`. This is only applicable to
125
+ /// leaf variables. Interior variables should call `set_gradient_edge()`.
126
+ TORCH_API void set_grad_accumulator(
127
+ const Variable& /*self*/,
128
+ std::weak_ptr<Node> grad_accumulator);
129
+
130
+ /// Attempts to get a pointer to the gradient accumulator of the `Variable`,
131
+ /// if it still exists. If the gradient accumulator function has been
132
+ /// destroyed, returns a `nullptr`.
133
+ TORCH_API std::shared_ptr<Node> try_get_grad_accumulator(
134
+ const Variable& /*self*/);
135
+ TORCH_API std::shared_ptr<Node> try_get_grad_accumulator(
136
+ const at::TensorBase& /*self*/);
137
+
138
+ /// Gets the gradient accumulator of the `Variable` if it has one, or else
139
+ /// create one on the fly and return it.
140
+ TORCH_API std::shared_ptr<Node> grad_accumulator(const Variable& /*self*/);
141
+
142
+ /// Returns the "canonical" gradient edge of this `Variable`, i.e. either the
143
+ /// gradient function if this is an interior `Variable`, or the gradient
144
+ /// accumulator otherwise. If the `Variable` is interior, the returned `Edge`
145
+ /// will store the input index of the `Node` to which this variable is
146
+ /// connected in its `input_nr` field. For leaves, the `input_nr` is always
147
+ /// zero. Note that `set_gradient_edge` and `gradient_edge` are not
148
+ /// symmetric. You must use `set_gradient_edge` to set the `grad_fn` and
149
+ /// `set_grad_accumulator` to set the accumulator.
150
+ TORCH_API Edge gradient_edge(const Variable& /*self*/);
151
+
152
+ /// Set the gradient edge -- i.e. `grad_fn` and `input_nr` -- of the
153
+ /// `Variable`.
154
+ /// NOTE: This will always set the `grad_fn`, even if this is a leaf variable,
155
+ /// and never the `grad_accumulator`. For the latter, use
156
+ /// `set_grad_accumulator`. This allows late construction of an interior
157
+ /// `Variable`.
158
+ TORCH_API void set_gradient_edge(const Variable& /*self*/, Edge edge);
159
+
160
+ // Autograd Graph Interaction
161
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162
+
163
+ /// Update the `grad_fn` of an existing Variable. Called after in-place
164
+ /// modifications.
165
+ ///
166
+ /// For View Variables:
167
+ /// Called after in-place modifications. Modifies the grad_fn of the base
168
+ /// Variable.
169
+ TORCH_API void rebase_history(const Variable& /*self*/, Edge gradient_edge);
170
+
171
+ /// Gets the raw gradient function pointer, whatever it currently is.
172
+ TORCH_API Node* grad_fn_unsafe(const Variable& /*self*/);
173
+
174
+ /// Increments the version count of this `Variable`.
175
+ TORCH_API void bump_version(const Variable& /*self*/);
176
+ TORCH_API void set_version_counter(
177
+ const Variable& /*self*/,
178
+ const c10::VariableVersion& version_counter);
179
+
180
+ /// Retrieves this `Variable`s version counter.
181
+ TORCH_API const c10::VariableVersion& version_counter(const Variable& /*self*/);
182
+
183
+ TORCH_API void set_name(const Variable& /*self*/, const std::string& name);
184
+
185
+ TORCH_API void add_hook(
186
+ const at::TensorBase& /*self*/,
187
+ std::unique_ptr<FunctionPreHook> hook);
188
+ TORCH_API std::vector<std::unique_ptr<FunctionPreHook>>& hooks(
189
+ const Variable& /*self*/);
190
+ TORCH_API void clear_hooks(const at::TensorBase& /*self*/);
191
+
192
+ TORCH_API void set_post_acc_grad_hooks(
193
+ const at::TensorBase& /*self*/,
194
+ std::unique_ptr<PostAccumulateGradHook> dict);
195
+ TORCH_API std::unique_ptr<PostAccumulateGradHook>& post_acc_grad_hooks(
196
+ const Variable& /*self*/);
197
+
198
+ TORCH_API void create_cpp_hook(
199
+ const at::TensorBase& /*self*/,
200
+ bool is_retains_grad_hooks = false);
201
+
202
+ inline bool is_tensor_stealable(
203
+ const at::Tensor& new_grad,
204
+ size_t num_expected_refs = 1) {
205
+ size_t use_count = new_grad.use_count();
206
+ if (use_count <= num_expected_refs) {
207
+ return true;
208
+ }
209
+ if (use_count >= 2 &&
210
+ new_grad.unsafeGetTensorImpl()->pyobj_slot()->has_unique_reference()) {
211
+ // The Python wrapper, if it exists, also has a reference to the Tensor.
212
+ num_expected_refs++;
213
+ }
214
+ return use_count <= num_expected_refs;
215
+ }
216
+
217
+ } // namespace impl
218
+
219
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220
+ // AutogradMeta
221
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
222
+
223
+ /// Each `Variable` has one unique `AutogradMeta` struct, which stores autograd
224
+ /// metadata fields that are necessary for tracking the Variable's autograd
225
+ /// history. As an optimization, a Variable may store a nullptr, in lieu of a
226
+ /// default constructed AutogradMeta.
227
+
228
+ struct TORCH_API AutogradMeta : public c10::AutogradMetaInterface {
229
+ std::string name_;
230
+
231
+ Variable grad_;
232
+ std::shared_ptr<Node> grad_fn_;
233
+ std::weak_ptr<Node> grad_accumulator_;
234
+
235
+ // This field is used to store all the forward AD gradients
236
+ // associated with this AutogradMeta (and the Tensor it corresponds to)
237
+ // There is a semantic 1:1 correspondence between AutogradMeta and
238
+ // ForwardGrad but:
239
+ // - This field is lazily populated.
240
+ // - This field is a shared_ptr but it must never be
241
+ // shared by multiple Tensors. See Note [ Using ForwardGrad ]
242
+ // Any transition from not_initialized to initialized
243
+ // must be protected by mutex_
244
+ mutable std::shared_ptr<ForwardGrad> fw_grad_;
245
+
246
+ // The hooks_ field is actually reused by both python and cpp logic
247
+ // For both cases, we have a data structure, cpp_hooks_list_ (cpp)
248
+ // or dict (python) which is the canonical copy.
249
+ // Then, for both cases, we always register a single hook to
250
+ // hooks_ which wraps all the hooks in the list/dict.
251
+ // And, again in both cases, if the grad_fn exists on that tensor
252
+ // we will additionally register a single hook to the grad_fn.
253
+ //
254
+ // Note that the cpp and python use cases aren't actually aware of
255
+ // each other, so using both is not defined behavior.
256
+ std::vector<std::unique_ptr<FunctionPreHook>> hooks_;
257
+ std::shared_ptr<hooks_list> cpp_hooks_list_;
258
+
259
+ // The post_acc_grad_hooks_ field stores only Python hooks
260
+ // (PyFunctionTensorPostAccGradHooks) that are called after the
261
+ // .grad field has been accumulated into. This is less complicated
262
+ // than the hooks_ field, which encapsulates a lot more.
263
+ std::unique_ptr<PostAccumulateGradHook> post_acc_grad_hooks_ = nullptr;
264
+
265
+ // Only meaningful on leaf variables (must be false otherwise)
266
+ bool requires_grad_{false};
267
+
268
+ // Only meaningful on non-leaf variables (must be false otherwise)
269
+ bool retains_grad_{false};
270
+
271
+ bool is_view_{false};
272
+
273
+ // The "output number" of this variable; e.g., if this variable
274
+ // was the second output of a function, then output_nr == 1.
275
+ // We use this to make sure we can setup the backwards trace
276
+ // correctly when this variable is passed to another function.
277
+ uint32_t output_nr_;
278
+
279
+ // The dtype of the grad field; when nullopt, defaults to tensor's dtype.
280
+ std::optional<at::ScalarType> grad_dtype_;
281
+
282
+ // When true, allows gradient dtype to be different from tensor dtype,
283
+ // bypassing dtype casting and validation in the autograd engine.
284
+ bool allow_grad_dtype_mismatch_{false};
285
+
286
+ // Mutex to ensure that concurrent read operations that modify internal
287
+ // state are still thread-safe. Used by grad_fn(), grad_accumulator(),
288
+ // fw_grad() and set_fw_grad()
289
+ // This is mutable because we need to be able to acquire this from const
290
+ // version of this class for the functions above
291
+ mutable std::mutex mutex_;
292
+
293
+ /// Sets the `requires_grad` property of `Variable`. This should be true for
294
+ /// leaf variables that want to accumulate gradients, and false for all other
295
+ /// variables.
296
+ void set_requires_grad(bool requires_grad, at::TensorImpl* self_impl) final {
297
+ TORCH_CHECK(
298
+ !requires_grad ||
299
+ isDifferentiableType(at::typeMetaToScalarType(self_impl->dtype())),
300
+ "Only Tensors of floating point and complex dtype can require gradients");
301
+ requires_grad_ = requires_grad;
302
+ }
303
+
304
+ bool requires_grad() const override {
305
+ return requires_grad_ || grad_fn_;
306
+ }
307
+
308
+ /// Accesses the gradient `Variable` of this `Variable`.
309
+ Variable& mutable_grad() override {
310
+ return grad_;
311
+ }
312
+
313
+ const Variable& grad() const override {
314
+ return grad_;
315
+ }
316
+
317
+ const Variable& fw_grad(uint64_t level, const at::TensorBase& self)
318
+ const override;
319
+
320
+ void set_fw_grad(
321
+ const at::TensorBase& new_grad,
322
+ const at::TensorBase& self,
323
+ uint64_t level,
324
+ bool is_inplace_op) override;
325
+
326
+ std::optional<at::ScalarType> grad_dtype(const at::TensorBase& self) const;
327
+
328
+ void set_grad_dtype(
329
+ const std::optional<at::ScalarType>& grad_dtype,
330
+ const at::TensorBase& self);
331
+
332
+ AutogradMeta(
333
+ at::TensorImpl* self_impl = nullptr,
334
+ bool requires_grad = false,
335
+ Edge gradient_edge = Edge())
336
+ : grad_fn_(std::move(gradient_edge.function)),
337
+
338
+ output_nr_(gradient_edge.input_nr) {
339
+ // set_requires_grad also checks error conditions.
340
+ if (requires_grad) {
341
+ TORCH_INTERNAL_ASSERT(self_impl);
342
+ set_requires_grad(requires_grad, self_impl);
343
+ }
344
+ TORCH_CHECK(
345
+ !grad_fn_ || !requires_grad_,
346
+ "requires_grad should be false if grad_fn is set");
347
+ }
348
+
349
+ ~AutogradMeta() override {
350
+ // If AutogradMeta is being destroyed, it means that there is no other
351
+ // reference to its corresponding Tensor. It implies that no other thread
352
+ // can be using this object and so there is no need to lock mutex_ here to
353
+ // guard the check if fw_grad_ is populated.
354
+ if (fw_grad_) {
355
+ // See note [ Using ForwardGrad ]
356
+ fw_grad_->clear();
357
+ }
358
+ }
359
+ };
360
+
361
+ /// Base class for view functions, providing reapplication of a view on a new
362
+ /// base. Each view op should get a codegenerated subclass of this class
363
+ /// containing any state needed to reconstruct the view. The class also provides
364
+ /// convenience accessors for saved SymInts / tensor state. This is useful for
365
+ /// e.g. fake-ification, where we want to use symbolic values or fake tensors
366
+ /// instead.
367
+ struct TORCH_API ViewFunc {
368
+ virtual ~ViewFunc() = default;
369
+ /// Returns any SymInts in the saved state.
370
+ virtual std::vector<c10::SymInt> get_symints() const {
371
+ return {};
372
+ }
373
+ /// Returns the number of SymInts in the saved state.
374
+ virtual size_t num_symints() const {
375
+ return 0;
376
+ }
377
+ /// Returns any tensors in the saved state.
378
+ virtual std::vector<at::Tensor> get_tensors() const {
379
+ return {};
380
+ }
381
+ /// Returns the number of tensors in the saved state.
382
+ virtual size_t num_tensors() const {
383
+ return 0;
384
+ }
385
+ /// Reapplies the view on the given base using the saved state.
386
+ virtual at::Tensor operator()(const at::Tensor&) const = 0;
387
+ /// Returns a clone of this ViewFunc, optionally with the specified saved
388
+ /// state.
389
+ virtual std::unique_ptr<ViewFunc> clone_and_set(
390
+ std::optional<std::vector<c10::SymInt>> = std::nullopt,
391
+ std::optional<std::vector<at::Tensor>> = std::nullopt) const = 0;
392
+
393
+ protected:
394
+ /// Sets the values of any SymInts in the saved state. The input vector size
395
+ /// must match the number of SymInts in the saved state (i.e. the size of the
396
+ /// list returned by get_symints()).
397
+ /// NOLINTNEXTLINE(performance-unnecessary-value-param)
398
+ virtual void set_symints(std::vector<c10::SymInt> /*unused*/) {}
399
+ /// Sets the values of any Tensors in the saved state. The input vector size
400
+ /// must match the number of Tensors in the saved state (i.e. the size of the
401
+ /// list returned by get_tensors()).
402
+ /// NOLINTNEXTLINE(performance-unnecessary-value-param)
403
+ virtual void set_tensors(std::vector<at::Tensor> /*unused*/) {}
404
+ };
405
+
406
+ /// ViewFunc that represents a chain of two ViewFuncs.
407
+ struct ChainedViewFunc : public ViewFunc {
408
+ ChainedViewFunc(
409
+ std::unique_ptr<ViewFunc> first,
410
+ std::unique_ptr<ViewFunc> second)
411
+ : first(std::move(first)), second(std::move(second)) {}
412
+ ~ChainedViewFunc() override = default;
413
+ std::vector<c10::SymInt> get_symints() const override;
414
+ size_t num_symints() const override {
415
+ return first->num_symints() + second->num_symints();
416
+ }
417
+ std::vector<at::Tensor> get_tensors() const override;
418
+ size_t num_tensors() const override {
419
+ return first->num_tensors() + second->num_tensors();
420
+ }
421
+ at::Tensor operator()(
422
+ const at::Tensor& /*input_base*/ /*unused*/) const override;
423
+ std::unique_ptr<ViewFunc> clone_and_set(
424
+ std::optional<std::vector<c10::SymInt>> /*symints*/ /*unused*/ =
425
+ std::nullopt,
426
+ std::optional<std::vector<at::Tensor>> /*tensors*/ /*unused*/ =
427
+ std::nullopt) const override;
428
+
429
+ private:
430
+ std::unique_ptr<ViewFunc> first;
431
+ std::unique_ptr<ViewFunc> second;
432
+ };
433
+
434
+ /// ViewFunc that errors with a specified error message when called.
435
+ struct ErroringViewFunc : public ViewFunc {
436
+ ErroringViewFunc(std::string error_msg) : error_msg(std::move(error_msg)) {}
437
+ ~ErroringViewFunc() override = default;
438
+ at::Tensor operator()(const at::Tensor& /*unused*/) const override {
439
+ TORCH_CHECK(false, error_msg);
440
+ }
441
+ std::unique_ptr<ViewFunc> clone_and_set(
442
+ std::optional<std::vector<c10::SymInt>> /*unused*/ = std::nullopt,
443
+ std::optional<std::vector<at::Tensor>> /*unused*/ =
444
+ std::nullopt) const override {
445
+ return std::make_unique<ErroringViewFunc>(error_msg);
446
+ }
447
+
448
+ private:
449
+ std::string error_msg;
450
+ };
451
+
452
+ struct TORCH_API ViewInfo {
453
+ /// The base `Variable`
454
+ /// If this ViewInfo represents a forward (respectively backward) AD gradient,
455
+ /// then this Tensor cannot be a forward (respectively backward) view.
456
+ Variable base_;
457
+
458
+ /// By default we use as_strided to recover views which is more efficient.
459
+ /// view_fn is only saved when as_strided is not supported.
460
+ /// If view_fn has value, we use it to recover views in backward.
461
+ std::unique_ptr<ViewFunc> view_fn_;
462
+
463
+ /// Analogue of view_fn but in reverse: given a view -> produce the base by
464
+ /// applying the inverse view.
465
+ std::function<Variable(const Variable&)> rev_view_fn_;
466
+
467
+ /// Accessors for the view function
468
+ bool has_view_fn() const {
469
+ // assume either BOTH or NEITHER of view_fn_ and rev_view_fn_ exist
470
+ return view_fn_ != nullptr;
471
+ }
472
+
473
+ const ViewFunc& view_fn() const {
474
+ TORCH_CHECK(
475
+ has_view_fn(), "Can only access the view function if it exists.");
476
+ return *view_fn_;
477
+ }
478
+
479
+ std::function<Variable(const Variable&)> rev_view_fn() const {
480
+ TORCH_CHECK(
481
+ has_view_fn(),
482
+ "Can only access the reverse view function if it exists.");
483
+ return rev_view_fn_;
484
+ }
485
+
486
+ /// The chain function can be used to build a new ViewInfo for a
487
+ /// differentiable view function. It will return a new view info that
488
+ /// accurately represents how "tensor" is a view of this instance's "base_".
489
+ /// The "base" and "tensor" are respectively the input and output of the
490
+ /// differentiable view function that happened. They are required to properly
491
+ /// set the optional view_fn_ when it is not provided. The "view_func", if
492
+ /// provided, should be a function that allows to re-do the view between
493
+ /// "base" and "tensor".
494
+ ViewInfo chain(
495
+ const Variable& base,
496
+ const Variable& tensor,
497
+ std::unique_ptr<ViewFunc> view_func = nullptr,
498
+ std::function<Variable(const Variable&)> rev_view_func = nullptr) const;
499
+
500
+ ViewInfo(
501
+ Variable base,
502
+ std::unique_ptr<ViewFunc> view_fn,
503
+ std::function<Variable(const Variable&)> rev_view_fn)
504
+ : base_(std::move(base)),
505
+ view_fn_(std::move(view_fn)),
506
+ rev_view_fn_(std::move(rev_view_fn)) {
507
+ TORCH_CHECK(base_.defined(), "base is undefined");
508
+ }
509
+ };
510
+
511
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
512
+ // DifferentiableViewMeta
513
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
514
+
515
+ /// NOTE [ Autograd View Variables ]
516
+ ///
517
+ /// Many operations return Variable that shares storage with an input Variable.
518
+ /// The returned Variable is called a **view** Variable on the input **base**
519
+ /// Variable.
520
+ ///
521
+ /// In PyTorch, we have two types of views: differentiable views, and
522
+ /// non-differentiable views. In either type, to support proper version
523
+ /// checking, the base and view Variables must always share the same
524
+ /// version_counter.
525
+ ///
526
+ ///
527
+ /// Differentiable Views
528
+ /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
529
+ /// This class allows to track both forward and backward AD differentiable
530
+ /// views. These views can have different base as non-differentiable view for
531
+ /// forward and backward mode AD are not the same.
532
+ ///
533
+ /// Most function are either both forward and backward differentiable views (for
534
+ /// example: view, select, narrow, transpose, etc) or both not forward and not
535
+ /// backward differentiable views (for example: indices, values, eq, lt, etc).
536
+ /// But there are also functions that are forward but not backward
537
+ /// differentiable views (only detach for now) or functions that are backward
538
+ /// but not forward differentiable view (only make_dual and unpack dual for
539
+ /// now).
540
+ ///
541
+ /// A concrete example of two views with different bases is as follow:
542
+ ///
543
+ /// # Have:
544
+ /// # dual is a dual Tensor that is neither a forward or backward view
545
+ /// detached_dual = dual.detach()
546
+ /// view = detached_dual.view_as(dual)
547
+ /// # The forward base of view is dual
548
+ /// # The backward base of view is detached_dual
549
+ ///
550
+ /// - Backward Mode View
551
+ /// Differentiable views are the view variables where you want gradients to flow
552
+ /// back to the base variables. Out-of-place operations on views are quite
553
+ /// straightforward, but in-place ones are very tricky. Even if the base
554
+ /// variable may not require grad when we create the view, we still need to
555
+ /// track the view relation because future in-place ops may require back-proping
556
+ /// through it. For example, we need to support
557
+ ///
558
+ /// (1) in-place operation on view, e.g.,
559
+ ///
560
+ /// # Have:
561
+ /// # base.requires_grad = False
562
+ /// # var.requires_grad = True
563
+ /// base[1] = var # i.e., base[1].copy_(var)
564
+ /// torch.autograd.grad(base.sum(), var) <- should return an all ones
565
+ /// tensor
566
+ ///
567
+ /// (2) in-place operation on base after view is created, e.g.,
568
+ ///
569
+ /// # Have:
570
+ /// # base.requires_grad = False
571
+ /// # var.requires_grad = True
572
+ /// view = base[1]
573
+ /// base.copy_(var)
574
+ /// torch.autograd.grad(view.sum(), var) <- should return a tensor with
575
+ /// var[1] filled with all ones and
576
+ /// zeros everywhere else
577
+ ///
578
+ /// - Forward Mode View
579
+ /// Forward differentiable views follow the same semantic as backward ones but
580
+ /// show up differently as they are computed along with the forward evaluation.
581
+ /// The hard examples above are thus very similar
582
+ ///
583
+ /// (1) in-place operation on view, e.g.,
584
+ ///
585
+ /// # Have:
586
+ /// # base is a regular Tensor
587
+ /// # var is a dual Tensor whose tangent is all ones
588
+ /// base[1] = var # i.e., base[1].copy_(var)
589
+ /// # Now, base is a dual Tensor
590
+ /// _, fw_grad = fwAD.unpack_dual(base) <- fw_grad should be a tensor with
591
+ /// fw_grad[1] filled with all ones
592
+ /// and zeros everywhere else
593
+ ///
594
+ /// (2) in-place operation on base after view is created, e.g.,
595
+ ///
596
+ /// # Have:
597
+ /// # base is a regular Tensor
598
+ /// # var is a dual Tensor whose tangent is all ones
599
+ /// view = base[1]
600
+ /// base.copy_(var)
601
+ /// _, fw_grad = fwAD.unpack_dual(view) <- fw_grad should be an all ones
602
+ /// tensor
603
+ ///
604
+ /// See Note [Forward Grad View/inplace] for more details on how we handle these
605
+ /// hard cases.
606
+ ///
607
+ ///
608
+ /// DifferentiableViewMeta is created to support gradient tracking of
609
+ /// such **in-place** operations. In particular,
610
+ /// + if an in-place op is done on base, the grad_fn field of the view may
611
+ /// become stale. So accesses should always go through grad_fn(), which
612
+ /// reconstructs an updated grad_fn if the version_counter has incremented.
613
+ /// All other fields are always valid.
614
+ /// + if an in-place op is done on view, in rebase_history() of view, which is
615
+ /// called after every in-place op in VariableType.cpp, the grad_fn of base
616
+ /// is updated.
617
+ /// + if a single autograd Node returns multiple differentiable views, if any
618
+ /// output is modified by an inplace operation, the autograd engine will
619
+ /// make an equivalent graph (corresponding to the view operations) without
620
+ /// using equivalent graph, where each output is treated as if it were
621
+ /// produced by a distinct view operation. This discards the original (e.g.,
622
+ /// user provided) grad_fn. If the provided grad_fn does more than the
623
+ /// backward of the view, then the DifferentiableViewMeta must be created
624
+ /// with creation_meta= CreationMeta::MULTI_OUTPUT_NODE to prevent the
625
+ /// engine from ignoring the provided grad_fn.
626
+ ///
627
+ /// Interaction with GradMode:
628
+ /// The particular case that we consider here is:
629
+ ///
630
+ /// # Have:
631
+ /// # base.requires_grad = True or False
632
+ /// with torch.no_grad():
633
+ /// view = base[1]
634
+ /// base.requires_grad_()
635
+ /// view.copy_(var)
636
+ /// torch.autograd.grad(base.sum(), var) <- what should it return?
637
+ ///
638
+ /// Given that this particular code example is ambiguous and can easily be
639
+ /// replace by either moving both inside the no_grad block or both outside, we
640
+ /// explicitly forbid it. For now, it is deprecated by a warning. This is
641
+ /// achieved by setting creation_meta=CreationMeta::NO_GRAD_MODE for all
642
+ /// differentiable views created in no_grad mode.
643
+ ///
644
+ /// See Note [View + Inplace update for base tensor]
645
+ /// and Note [View + Inplace update for view tensor] for the details how
646
+ /// autograd handles inplace update with view ops.
647
+ ///
648
+ /// Non-Differentiable Views
649
+ /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
650
+ /// In certain cases, although function outputs share storage with inputs, they
651
+ /// will **never** require gradient history tracking. Instead of registering the
652
+ /// view relation via DifferentiableViewMeta in autograd, the views will be
653
+ /// using usual AutogradMeta and just share the version counters with the base
654
+ /// Variables.
655
+ /// Such views include:
656
+ /// 1. Views created from .detach()
657
+ /// 2. Views that are non-differentiable by its nature.
658
+ /// E.g., `sparse_tensor.indices()` is a integral view on a (possibly)
659
+ /// floating point tensor.
660
+ /// See top of `derivatives.yaml` on how to specify that outputs of a
661
+ /// function are non-differentiable.
662
+ /// These are called non-differentiable views as the gradients do not flow
663
+ /// through the view relation.
664
+ ///
665
+ /// Relevant logic for both differentiable and non-differentiable views is
666
+ /// implemented in make_variable_(non_)differentiable_view below, and
667
+ /// wrap_output of gen_variable_type.py.
668
+
669
+ /// NOTE [ View + Inplace detection ]
670
+ ///
671
+ /// We want to detect views followed by inplace as they are often forbidden to
672
+ /// ensure correctness of the computed gradients. But since we want to only
673
+ /// notify the user when both happen, we tag the DifferentiableViewMeta when the
674
+ /// view is created via the `make_variable_*_view()` functions. This tag is then
675
+ /// checked by the `check_inplace()` function from `VariableTypeUtils.h` that
676
+ /// should be called before every inplace operation and to detect cases where
677
+ /// other views are modified and this one is rebased by side effect, we also
678
+ /// check in the `VariableHooks::grad_fn()`.
679
+
680
+ /// Flag that gives more information about when this view was created:
681
+ /// - IN_CUSTOM_FUNCTION should be set when the view is created inside a custom
682
+ /// autograd Function is returned.
683
+ /// - NO_GRAD_MODE should be set when a view in created when GradMode is
684
+ /// disabled
685
+ /// - MULTI_OUTPUT_NODE should be set when a Node created by codegen code
686
+ /// returns
687
+ /// multiple differentiable views
688
+ /// - Inference_MODE should be set when a view of normal tensor is created in
689
+ /// InferenceMode.
690
+ /// - DEFAULT is for all other cases
691
+ enum class CreationMeta : uint8_t {
692
+ DEFAULT,
693
+ IN_CUSTOM_FUNCTION,
694
+ MULTI_OUTPUT_NODE,
695
+ NO_GRAD_MODE,
696
+ INFERENCE_MODE
697
+ };
698
+
699
+ /// Handles correctly propagating CreationMeta when a new view is created from a
700
+ /// previous view. In general, we don't want the new view to be _less_
701
+ /// restrictive than the previous view (it's okay to be _more_ restrictive). A
702
+ /// CreationMeta value of DEFAULT is currently the least restrictive, as the
703
+ /// behavior for all other CreationMeta values is to error out for in-place ops.
704
+ /// A CreationMeta value of INFERENCE_MODE is currently the most restrictive, so
705
+ /// it takes precedence in propagation. If this changes, the logic here will
706
+ /// need to be updated to properly handle the new semantics.
707
+ inline CreationMeta propagate_creation_meta(
708
+ CreationMeta prev_view_creation_meta,
709
+ CreationMeta new_view_creation_meta) {
710
+ return (new_view_creation_meta == CreationMeta::DEFAULT)
711
+ ? prev_view_creation_meta
712
+ : (prev_view_creation_meta == CreationMeta::INFERENCE_MODE
713
+ ? prev_view_creation_meta
714
+ : new_view_creation_meta);
715
+ }
716
+
717
+ /// Unified function to handle error checking when rebase happens
718
+ /// indirect=true means that the caller is not doing the inplace, but the
719
+ /// inplace happened somewhere else.
720
+ TORCH_API void handle_view_on_rebase(
721
+ DifferentiableViewMeta* diff_view_meta,
722
+ bool indirect = false);
723
+
724
+ struct TORCH_API DifferentiableViewMeta : public AutogradMeta {
725
+ private:
726
+ /// Information about the views
727
+ std::optional<ViewInfo> backward_info_;
728
+ std::optional<ViewInfo> forward_info_;
729
+
730
+ // Optimization to reduce the number of ViewInfo we create.
731
+ // In the (very common) case where backward_info_ == forward_info_, we only
732
+ // populate backward_info_ (that should be used as both the forward and
733
+ // backward view information) and set shared_view_info_ = true. Invariants:
734
+ // - If shared_view_info_ is false, there is no special constraints on
735
+ // backward_info_ and forward_info_
736
+ // - If shared_view_info_ is true, we must have:
737
+ // - backward_info_.has_value() == true
738
+ // - forward_info_.has_value() == false
739
+ bool shared_view_info_;
740
+
741
+ /// The two following fields are extra information that we track to ensure
742
+ /// that any operation on this backward view is valid.
743
+
744
+ /// The value of the version_counter at the time grad_fn was created. The
745
+ /// grad_fn field is stale if attr_version_ !=
746
+ /// version_counter.current_version().
747
+ uint32_t attr_version_;
748
+ CreationMeta creation_meta_;
749
+
750
+ public:
751
+ /// requires_grad is a backward AD field so we only use the view specific
752
+ /// logic for backward differentiable views
753
+ bool requires_grad() const override {
754
+ return requires_grad_ || grad_fn_ ||
755
+ (has_bw_view() && get_backward_view().base_.requires_grad());
756
+ }
757
+
758
+ bool shared_view_info() const {
759
+ return shared_view_info_;
760
+ }
761
+
762
+ bool has_bw_view() const {
763
+ return backward_info_.has_value();
764
+ }
765
+
766
+ const ViewInfo& get_backward_view() const {
767
+ TORCH_CHECK(
768
+ has_bw_view(), "backward view info can only exist for backward views.");
769
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
770
+ return backward_info_.value();
771
+ }
772
+
773
+ uint32_t get_attr_version() const {
774
+ TORCH_CHECK(
775
+ has_bw_view(), "attr_version can only exist for backward views.");
776
+ return attr_version_;
777
+ }
778
+
779
+ void set_attr_version(uint32_t new_attr_version) {
780
+ TORCH_CHECK(
781
+ has_bw_view(), "attr_version can only exist for backward views.");
782
+ attr_version_ = new_attr_version;
783
+ }
784
+
785
+ CreationMeta get_creation_meta() const {
786
+ TORCH_CHECK(
787
+ has_bw_view(), "creation_meta can only exist for backward views.");
788
+ return creation_meta_;
789
+ }
790
+
791
+ void set_creation_meta(CreationMeta new_creation_meta) {
792
+ TORCH_CHECK(
793
+ has_bw_view(), "creation_meta can only exist for backward views.");
794
+ creation_meta_ = new_creation_meta;
795
+ }
796
+
797
+ bool has_fw_view() const {
798
+ return shared_view_info_ || forward_info_.has_value();
799
+ }
800
+
801
+ const ViewInfo& get_forward_view() const {
802
+ TORCH_CHECK(
803
+ has_fw_view(), "forward view info can only exist for forward views.");
804
+ TORCH_CHECK(
805
+ !shared_view_info_ || has_bw_view(),
806
+ "forward view info can only exist for forward views.");
807
+ // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
808
+ return shared_view_info_ ? backward_info_.value() : forward_info_.value();
809
+ }
810
+
811
+ DifferentiableViewMeta(
812
+ at::TensorImpl* self_impl,
813
+ std::optional<ViewInfo> backward_info,
814
+ std::optional<ViewInfo> forward_info,
815
+ bool shared_view_info,
816
+ CreationMeta creation_meta = CreationMeta::DEFAULT);
817
+ };
818
+
819
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
820
+ // Variable Implementation
821
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
822
+
823
+ // Factory Functions
824
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
825
+
826
+ /// Creates a `Variable` that is a *view* of another (*base*) variable.
827
+ /// The `gradient_edge` is an optional (gradient_function, input_number) pair.
828
+ /// `is_differentiable` is a bool that specifies whether this view is
829
+ /// differentiable, i.e., whether the relation should be tracked by autograd.
830
+ /// See NOTE [ Autograd View Variables ] for details.
831
+
832
+ /// NOTE: `allow_tensor_metadata_change` is set to true by default, because
833
+ /// there are a lot of call sites to these factory functions that need to change
834
+ /// the variable's size or storage afterwards, and they don't expect the
835
+ /// original tensor (where the variable is created from) to be updated. Setting
836
+ /// `allow_tensor_metadata_change_` to false by default would unnecessarily
837
+ /// prevent those changes from happening and is undesirable.
838
+
839
+ // See NOTE [ Autograd View Variables ] for details.
840
+ // Differentiable view. Track history with DifferentiableViewMeta.
841
+ inline Variable make_variable_differentiable_view(
842
+ const at::Tensor& data,
843
+ std::optional<ViewInfo> backward_info,
844
+ std::optional<ViewInfo> forward_info,
845
+ bool shared_view_info,
846
+ CreationMeta creation_meta,
847
+ bool allow_tensor_metadata_change = true) {
848
+ if (data.defined()) {
849
+ TORCH_CHECK(
850
+ data.getIntrusivePtr()->autograd_meta() == nullptr,
851
+ "Attempted to make a tensor into a differentiable view, but the "
852
+ "tensor already had autograd metadata associated with it. If you are "
853
+ "using a __torch_dispatch__ mode, the most common cause for this "
854
+ "problem is that you used torch.overrides.enable_reentrant_dispatch() "
855
+ "improperly; tensors created within the extent of reentrant dispatch "
856
+ "MUST NOT be directly returned from __torch_dispatch__; instead, they "
857
+ "must be wrapped into fresh tensors that serve as the output. If you "
858
+ "are not using wrappers, you probably don't need reentrant dispatch. "
859
+ "If this doesn't seem applicable, please file a bug to PyTorch.");
860
+ at::TensorImpl* data_impl = data.unsafeGetTensorImpl();
861
+ data_impl->set_allow_tensor_metadata_change(allow_tensor_metadata_change);
862
+ data_impl->set_autograd_meta(std::make_unique<DifferentiableViewMeta>(
863
+ data_impl,
864
+ std::move(backward_info),
865
+ std::move(forward_info),
866
+ shared_view_info,
867
+ creation_meta));
868
+ return data;
869
+ }
870
+ return Variable();
871
+ }
872
+
873
+ // See NOTE [ Autograd View Variables ] for details.
874
+ // Non-differentiable view. Just share version counter.
875
+ inline Variable make_variable_non_differentiable_view(
876
+ const Variable& base,
877
+ const at::Tensor& data,
878
+ bool allow_tensor_metadata_change = true,
879
+ bool is_fresh_tensor = false) {
880
+ if (data.defined()) {
881
+ // If we already allocated a new tensor, no need to
882
+ // shallow_copy_and_detach here. (See #163671 history; we tried to
883
+ // fan out to _indices and _values and ran into a SparseTensorImpl
884
+ // can of worms.)
885
+ if (is_fresh_tensor) {
886
+ auto* data_impl = data.unsafeGetTensorImpl();
887
+ data_impl->set_version_counter(impl::version_counter(base));
888
+ data_impl->set_allow_tensor_metadata_change(allow_tensor_metadata_change);
889
+ data_impl->set_autograd_meta(nullptr);
890
+ return data;
891
+ }
892
+ auto data_impl_copy = data.getIntrusivePtr()->shallow_copy_and_detach(
893
+ /*version_counter=*/impl::version_counter(base),
894
+ /*allow_tensor_metadata_change=*/allow_tensor_metadata_change);
895
+ data_impl_copy->set_autograd_meta(nullptr);
896
+ return Variable(std::move(data_impl_copy));
897
+ }
898
+ return Variable();
899
+ }
900
+
901
+ /// Creates a `Variable` from the given `Tensor`, copying its underlying
902
+ /// `TensorImpl`. `requires_grad` should be set only for leaves, and determines
903
+ /// whether the `Variable` will accumulate gradients. NOTE: `data` must *not* be
904
+ /// a `Variable` already. Its dynamic type *must* be `Tensor`.
905
+ ///
906
+ /// TODO: Eliminate this function as much as possible, as it can be expressed
907
+ /// more clearly as detach() or a no-op in most call sites (especially when
908
+ /// there is only one use of the variable).
909
+ inline Variable make_variable(
910
+ at::Tensor data,
911
+ bool requires_grad = false,
912
+ bool allow_tensor_metadata_change = true) {
913
+ if (data.defined()) {
914
+ if (impl::is_tensor_stealable(data) &&
915
+ data.getIntrusivePtr()->unique_version()) {
916
+ auto data_impl = data.unsafeReleaseIntrusivePtr();
917
+ data_impl->set_allow_tensor_metadata_change(allow_tensor_metadata_change);
918
+ if (requires_grad) {
919
+ data_impl->set_autograd_meta(
920
+ std::make_unique<AutogradMeta>(data_impl.get(), requires_grad));
921
+ } else {
922
+ data_impl->set_autograd_meta(nullptr);
923
+ }
924
+ return Variable(std::move(data_impl));
925
+ } else {
926
+ auto data_impl_copy = data.getIntrusivePtr()->shallow_copy_and_detach(
927
+ /*version_counter=*/0,
928
+ /*allow_tensor_metadata_change=*/allow_tensor_metadata_change);
929
+ if (requires_grad) {
930
+ data_impl_copy->set_autograd_meta(std::make_unique<AutogradMeta>(
931
+ data_impl_copy.get(), requires_grad));
932
+ } else {
933
+ data_impl_copy->set_autograd_meta(nullptr);
934
+ }
935
+ return Variable(std::move(data_impl_copy));
936
+ }
937
+ }
938
+ return Variable();
939
+ }
940
+
941
+ /// Creates a `Variable` from the given `Tensor`, copying its underlying
942
+ /// `TensorImpl`. `gradient_edge` should be a (function, input_nr) pair
943
+ /// specifying the function in the autograd graph, and what particular input of
944
+ /// that function, this variable is connected to.
945
+ inline Variable make_variable(
946
+ const at::Tensor& data,
947
+ Edge gradient_edge,
948
+ bool allow_tensor_metadata_change = true) {
949
+ if (data.defined()) {
950
+ auto data_impl_copy = data.getIntrusivePtr()->shallow_copy_and_detach(
951
+ /*version_counter=*/0,
952
+ /*allow_tensor_metadata_change=*/allow_tensor_metadata_change);
953
+ data_impl_copy->set_autograd_meta(std::make_unique<AutogradMeta>(
954
+ data_impl_copy.get(), false, std::move(gradient_edge)));
955
+ return Variable(std::move(data_impl_copy));
956
+ }
957
+ return Variable();
958
+ }
959
+
960
+ struct VariableHooks final : at::impl::VariableHooksInterface {
961
+ at::TensorBase tensor_data(
962
+ const at::TensorBase& /*self*/ /*unused*/) const override;
963
+ at::TensorBase variable_data(
964
+ const at::TensorBase& /*self*/ /*unused*/) const override;
965
+ const std::shared_ptr<torch::autograd::Node>& grad_fn(
966
+ const at::TensorBase& /*self*/ /*unused*/) const override;
967
+ unsigned _register_hook(
968
+ const at::TensorBase& /*self*/ /*unused*/,
969
+ std::function<at::TensorBase(const at::TensorBase&)> hook) const override;
970
+ void remove_hook(const at::TensorBase& /*self*/ /*unused*/, unsigned pos)
971
+ const override;
972
+ bool is_view(const at::TensorBase& /*self*/ /*unused*/) const override;
973
+ const at::TensorBase& base(
974
+ const at::TensorBase& /*self*/ /*unused*/) const override;
975
+ const std::string& name(
976
+ const at::TensorBase& /*self*/ /*unused*/) const override;
977
+ bool is_leaf(const at::TensorBase& /*self*/ /*unused*/) const override;
978
+ int64_t output_nr(const at::TensorBase& /*self*/ /*unused*/) const override;
979
+ void set_data(const at::TensorBase& self, const at::TensorBase& new_data)
980
+ const override;
981
+ at::TensorBase data(const at::TensorBase& self) const override;
982
+ int64_t _version(const at::TensorBase& self) const override;
983
+ void retain_grad(const at::TensorBase& self) const override;
984
+ bool retains_grad(const at::TensorBase& self) const override;
985
+ void _backward(
986
+ const at::Tensor& self,
987
+ at::TensorList inputs,
988
+ const std::optional<at::Tensor>& gradient,
989
+ std::optional<bool> keep_graph,
990
+ bool create_graph) const override;
991
+ void requires_grad_(const at::TensorBase& self, bool _requires_grad)
992
+ const override;
993
+ void basic_autograd_not_implemented_fallback(
994
+ const c10::OperatorHandle& op,
995
+ c10::DispatchKeySet dispatch_keys,
996
+ torch::jit::Stack* stack) const override;
997
+ std::optional<c10::ScalarType> grad_dtype(
998
+ const at::TensorBase& /*self*/ /*unused*/) const override;
999
+ void set_grad_dtype(
1000
+ const at::TensorBase& /*self*/ /*unused*/,
1001
+ const std::optional<c10::ScalarType>& /*grad_dtype*/ /*unused*/)
1002
+ const override;
1003
+ };
1004
+
1005
+ namespace utils {
1006
+
1007
+ TORCH_API bool has_same_meta(const Variable& base, const Variable& other);
1008
+
1009
+ } // namespace utils
1010
+ } // namespace torch::autograd
1011
+
1012
+ #endif /* DOXYGEN_SHOULD_SKIP_THIS */
1013
+
1014
+ #else
1015
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
1016
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/variable_info.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/autograd/variable.h>
5
+
6
+ namespace torch::autograd {
7
+
8
+ struct TORCH_API VariableInfo {
9
+ explicit VariableInfo();
10
+ explicit VariableInfo(const Variable& var, bool use_zeros_like = false);
11
+
12
+ Variable zeros(at::OptionalDeviceGuard& device_guard) const;
13
+
14
+ at::Layout layout = at::Layout::Strided;
15
+ at::Device device = at::kCPU;
16
+ at::ScalarType scalar_type = at::kFloat;
17
+ std::vector<c10::SymInt> size;
18
+ bool requires_grad;
19
+ bool is_empty;
20
+ // needed for e.g. NJTs since they only support zeros_like()
21
+ std::optional<Variable> the_var;
22
+ };
23
+
24
+ } // namespace torch::autograd
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cpu/Module.h ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ #include <torch/csrc/python_headers.h>
4
+
5
+ namespace torch::cpu {
6
+
7
+ void initModule(PyObject* module);
8
+
9
+ } // namespace torch::cpu
10
+
11
+ #else
12
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
13
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/CUDAPluggableAllocator.h ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <c10/core/Allocator.h>
5
+ #include <c10/cuda/CUDAGraphsC10Utils.h>
6
+ #include <c10/cuda/CUDAMacros.h>
7
+ #include <c10/cuda/CUDAStream.h>
8
+
9
+ #include <c10/cuda/CUDACachingAllocator.h>
10
+
11
+ #include <mutex>
12
+
13
+ namespace torch::cuda::CUDAPluggableAllocator {
14
+
15
+ #if defined(USE_ROCM)
16
+ using streamType = c10::hip::HIPStream;
17
+ #else
18
+ using streamType = c10::cuda::CUDAStream;
19
+ #endif
20
+
21
+ TORCH_CUDA_CPP_API std::shared_ptr<
22
+ c10::cuda::CUDACachingAllocator::CUDAAllocator>
23
+ getCurrentAllocator();
24
+ TORCH_CUDA_CPP_API std::shared_ptr<
25
+ c10::cuda::CUDACachingAllocator::CUDAAllocator>
26
+ createCustomAllocator(
27
+ std::function<void*(size_t, int, cudaStream_t)> alloc_fn,
28
+ std::function<void(void*, size_t, int, cudaStream_t)> free_fn);
29
+ TORCH_CUDA_CPP_API void changeCurrentAllocator(
30
+ const std::shared_ptr<c10::cuda::CUDACachingAllocator::CUDAAllocator>&
31
+ allocator);
32
+
33
+ struct _AllocationMetadata {
34
+ _AllocationMetadata();
35
+ _AllocationMetadata(
36
+ size_t size,
37
+ c10::DeviceIndex device_idx,
38
+ cudaStream_t stream);
39
+ size_t size;
40
+ c10::DeviceIndex device_idx;
41
+ cudaStream_t stream{};
42
+ };
43
+
44
+ struct TORCH_CUDA_CPP_API CUDAPluggableAllocator
45
+ : public c10::cuda::CUDACachingAllocator::CUDAAllocator {
46
+ CUDAPluggableAllocator(
47
+ std::function<void*(size_t, int, cudaStream_t)> alloc_fn,
48
+ std::function<void(void*, size_t, int, cudaStream_t)> free_fn);
49
+
50
+ CUDAPluggableAllocator(CUDAPluggableAllocator& other);
51
+ CUDAPluggableAllocator(CUDAPluggableAllocator&& other) = delete;
52
+ CUDAPluggableAllocator& operator=(const CUDAPluggableAllocator& other) =
53
+ delete;
54
+ CUDAPluggableAllocator& operator=(CUDAPluggableAllocator&& other) = delete;
55
+ ~CUDAPluggableAllocator() override = default;
56
+
57
+ void set_init_fn(std::function<void(int)> init_fn);
58
+
59
+ void set_reset_fn(std::function<void()> reset_fn);
60
+
61
+ void set_memory_fraction_fn(
62
+ std::function<void(double, int)> memory_fraction_fn);
63
+
64
+ void set_base_alloc_fn(std::function<void*(void*, size_t*)> base_alloc_fn);
65
+
66
+ void set_record_stream_fn(
67
+ std::function<void(void* ptr, cudaStream_t stream)> record_stream_fn);
68
+
69
+ void set_begin_allocate_to_pool(
70
+ std::function<
71
+ void(int, c10::cuda::MempoolId_t, std::function<bool(cudaStream_t)>)>
72
+ capture_begin_fn);
73
+
74
+ void set_end_allocate_to_pool_fn(
75
+ std::function<void(int, c10::cuda::MempoolId_t)> capture_about_to_end_fn);
76
+
77
+ void set_release_pool(
78
+ std::function<void(int, c10::cuda::MempoolId_t)> capture_destroy_fn);
79
+
80
+ void* malloc(size_t size, c10::DeviceIndex device, cudaStream_t stream);
81
+
82
+ c10::DataPtr allocate(size_t size) override;
83
+ c10::DeleterFnPtr raw_deleter() const override;
84
+
85
+ void* raw_alloc(size_t nbytes) override;
86
+ void* raw_alloc_with_stream(size_t nbytes, cudaStream_t stream) override;
87
+ void raw_delete(void* ptr) override;
88
+ void init(int device_count) override;
89
+ bool initialized() override;
90
+ double getMemoryFraction(c10::DeviceIndex device) override;
91
+ void setMemoryFraction(double fraction, c10::DeviceIndex device) override;
92
+ std::vector<c10::cuda::CUDACachingAllocator::StreamSegmentSize>
93
+ getExpandableSegmentSizes(c10::DeviceIndex device) override;
94
+ void emptyCache(c10::cuda::MempoolId_t mempool_id = {0, 0}) override;
95
+ void enable(bool) override {}
96
+ bool isEnabled() const override {
97
+ return true;
98
+ }
99
+ void cacheInfo(c10::DeviceIndex device, size_t* largestBlock) override;
100
+ void* getBaseAllocation(void* ptr, size_t* size) override;
101
+
102
+ void recordStream(const c10::DataPtr&, streamType stream) override;
103
+
104
+ c10::CachingDeviceAllocator::DeviceStats getDeviceStats(
105
+ c10::DeviceIndex device) override;
106
+ void resetAccumulatedStats(c10::DeviceIndex device) override;
107
+ void resetPeakStats(c10::DeviceIndex device) override;
108
+ c10::cuda::CUDACachingAllocator::SnapshotInfo snapshot(
109
+ c10::cuda::MempoolId_t mempool) override;
110
+ void beginAllocateToPool(
111
+ c10::DeviceIndex device,
112
+ c10::cuda::MempoolId_t mempool_id,
113
+ std::function<bool(cudaStream_t)>) override;
114
+ void endAllocateToPool(
115
+ c10::DeviceIndex device,
116
+ c10::cuda::MempoolId_t mempool_id) override;
117
+ void releasePool(c10::DeviceIndex device, c10::cuda::MempoolId_t mempool_id)
118
+ override;
119
+ std::shared_ptr<void> getIpcDevPtr(std::string handle) override;
120
+ c10::cuda::CUDACachingAllocator::ShareableHandle shareIpcHandle(
121
+ void*) override;
122
+ void recordHistory(
123
+ bool enabled,
124
+ c10::cuda::CUDACachingAllocator::CreateContextFn context_recorder,
125
+ size_t alloc_trace_max_entries,
126
+ c10::cuda::CUDACachingAllocator::RecordContext when,
127
+ bool clearHistory) override;
128
+ void attachOutOfMemoryObserver(
129
+ c10::cuda::CUDACachingAllocator::OutOfMemoryObserver observer) override;
130
+ void attachAllocatorTraceTracker(
131
+ c10::cuda::CUDACachingAllocator::AllocatorTraceTracker tracker) override;
132
+ std::shared_ptr<c10::cuda::CUDACachingAllocator::AllocatorState>
133
+ getCheckpointState(c10::DeviceIndex device, at::cuda::MempoolId_t id)
134
+ override;
135
+ c10::cuda::CUDACachingAllocator::CheckpointDelta setCheckpointPoolState(
136
+ c10::DeviceIndex device,
137
+ std::shared_ptr<c10::cuda::CUDACachingAllocator::AllocatorState> pps)
138
+ override;
139
+ void enablePeerAccess(c10::DeviceIndex dev, c10::DeviceIndex dev_to_access)
140
+ override;
141
+ cudaError_t memcpyAsync(
142
+ void* dst,
143
+ int dstDevice,
144
+ const void* src,
145
+ int srcDevice,
146
+ size_t count,
147
+ cudaStream_t stream,
148
+ bool p2p_enabled) override;
149
+ std::string name() override;
150
+ void copy_data(void* dest, const void* src, std::size_t count) const final;
151
+
152
+ protected:
153
+ std::function<void*(size_t, int, cudaStream_t)> alloc_fn_;
154
+ std::function<void(void*, size_t, int, cudaStream_t)> free_fn_;
155
+ std::function<void(int)> init_fn_;
156
+ std::function<void()> reset_fn_;
157
+ std::function<void(double, int)> memory_fraction_fn_;
158
+ std::function<void*(void*, size_t*)> base_alloc_fn_;
159
+ std::function<void(void* ptr, cudaStream_t stream)> record_stream_fn_;
160
+ std::function<
161
+ void(int, c10::cuda::MempoolId_t, std::function<bool(cudaStream_t)>)>
162
+ begin_allocate_to_pool_fn_;
163
+ std::function<void(int, c10::cuda::MempoolId_t)> end_allocate_to_pool_fn_;
164
+ std::function<void(int, c10::cuda::MempoolId_t)> relase_pool_fn_;
165
+ std::mutex allocator_mutex_;
166
+ // We do the bookkeeping here in order to simplify custom allocators
167
+ std::unordered_map<void*, _AllocationMetadata> allocation_metadata_;
168
+
169
+ bool initialized_ = false;
170
+ };
171
+ } // namespace torch::cuda::CUDAPluggableAllocator
172
+
173
+ #else
174
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
175
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Event.h ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #ifndef THCP_EVENT_INC
3
+ #define THCP_EVENT_INC
4
+
5
+ #include <ATen/cuda/CUDAEvent.h>
6
+ #include <torch/csrc/Event.h>
7
+ #include <torch/csrc/python_headers.h>
8
+
9
+ struct THCPEvent : THPEvent {
10
+ at::cuda::CUDAEvent cuda_event;
11
+ };
12
+ extern PyObject* THCPEventClass;
13
+
14
+ void THCPEvent_init(PyObject* module);
15
+
16
+ inline bool THCPEvent_Check(PyObject* obj) {
17
+ return THCPEventClass && PyObject_IsInstance(obj, THCPEventClass);
18
+ }
19
+
20
+ #endif // THCP_EVENT_INC
21
+
22
+ #else
23
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
24
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/GdsFile.h ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #ifndef THCP_GDSFILE_INC
3
+ #define THCP_GDSFILE_INC
4
+
5
+ #include <torch/csrc/python_headers.h>
6
+
7
+ namespace torch::cuda::shared {
8
+ void initGdsBindings(PyObject* module);
9
+ }
10
+ #endif // THCP_GDSFILE_INC
11
+
12
+ #else
13
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
14
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Module.h ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #ifndef THCP_CUDA_MODULE_INC
3
+ #define THCP_CUDA_MODULE_INC
4
+ #include <torch/csrc/utils/pythoncapi_compat.h>
5
+
6
+ PyObject* THCPModule_getDevice_wrap(PyObject* self);
7
+ PyObject* THCPModule_setDevice_wrap(PyObject* self, PyObject* arg);
8
+ PyObject* THCPModule_getDeviceName_wrap(PyObject* self, PyObject* arg);
9
+ PyObject* THCPModule_getDriverVersion(PyObject* self);
10
+ PyObject* THCPModule_isDriverSufficient(PyObject* self);
11
+ PyObject* THCPModule_getCurrentBlasHandle_wrap(PyObject* self);
12
+
13
+ #endif
14
+
15
+ #else
16
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
17
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Stream.h ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #ifndef THCP_STREAM_INC
3
+ #define THCP_STREAM_INC
4
+
5
+ #include <c10/cuda/CUDAStream.h>
6
+ #include <torch/csrc/Stream.h>
7
+ #include <torch/csrc/python_headers.h>
8
+
9
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
10
+ struct THCPStream : THPStream {
11
+ at::cuda::CUDAStream cuda_stream;
12
+ };
13
+ extern PyObject* THCPStreamClass;
14
+
15
+ void THCPStream_init(PyObject* module);
16
+
17
+ inline bool THCPStream_Check(PyObject* obj) {
18
+ return THCPStreamClass && PyObject_IsInstance(obj, THCPStreamClass);
19
+ }
20
+
21
+ #endif // THCP_STREAM_INC
22
+
23
+ #else
24
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
25
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/THCP.h ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
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/cuda/utils.h>
9
+ #include <torch/csrc/python_headers.h>
10
+
11
+ #else
12
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
13
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/comm.h ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <ATen/ATen.h>
5
+ #include <ATen/cuda/ATenCUDAGeneral.h>
6
+ #include <ATen/cuda/CUDAContext.h>
7
+ #include <torch/csrc/Export.h>
8
+ #include <optional>
9
+
10
+ #include <cstddef>
11
+ #include <vector>
12
+
13
+ namespace torch::cuda {
14
+
15
+ using tensor_list2d = std::vector<std::vector<at::Tensor>>;
16
+
17
+ TORCH_CUDA_CU_API std::vector<at::Tensor>& broadcast_out(
18
+ const at::Tensor& tensor,
19
+ std::vector<at::Tensor>& out_tensors);
20
+ TORCH_CUDA_CU_API std::vector<at::Tensor> broadcast(
21
+ const at::Tensor& tensor,
22
+ at::IntArrayRef devices);
23
+ TORCH_CUDA_CU_API tensor_list2d broadcast_coalesced(
24
+ at::TensorList tensors,
25
+ at::IntArrayRef devices,
26
+ size_t buffer_size);
27
+
28
+ TORCH_CUDA_CU_API std::vector<at::Tensor>& scatter_out(
29
+ const at::Tensor& tensor,
30
+ std::vector<at::Tensor>& out_tensors,
31
+ int64_t dim = 0,
32
+ const std::optional<std::vector<std::optional<at::cuda::CUDAStream>>>&
33
+ streams = std::nullopt);
34
+
35
+ TORCH_CUDA_CU_API std::vector<at::Tensor> scatter(
36
+ const at::Tensor& tensor,
37
+ at::IntArrayRef devices,
38
+ const std::optional<std::vector<int64_t>>& chunk_sizes = std::nullopt,
39
+ int64_t dim = 0,
40
+ const std::optional<std::vector<std::optional<at::cuda::CUDAStream>>>&
41
+ streams = std::nullopt);
42
+
43
+ TORCH_CUDA_CU_API at::Tensor& gather_out(
44
+ at::TensorList tensors,
45
+ at::Tensor& out_tensor,
46
+ int64_t dim);
47
+
48
+ TORCH_CUDA_CU_API at::Tensor gather(
49
+ at::TensorList tensors,
50
+ int64_t dim,
51
+ std::optional<int32_t> destination_index);
52
+
53
+ } // namespace torch::cuda
54
+
55
+ #else
56
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
57
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/device_set.h ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <c10/cuda/CUDAMacros.h>
5
+ #include <bitset>
6
+ #include <cstddef>
7
+
8
+ namespace torch {
9
+
10
+ using device_set = std::bitset<C10_COMPILE_TIME_MAX_GPUS>;
11
+
12
+ } // namespace torch
13
+
14
+ #else
15
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
16
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/memory_snapshot.h ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/Export.h>
5
+ #include <cstdint>
6
+ #include <optional>
7
+ #include <string>
8
+
9
+ namespace torch::cuda {
10
+
11
+ // C++-only versions of these, for python use
12
+ // those defined in cuda/Module.cpp which also record python state.
13
+ TORCH_CUDA_CU_API void _record_memory_history(
14
+ bool enabled,
15
+ bool record_context = true,
16
+ int64_t trace_alloc_max_entries = 1,
17
+ bool trace_alloc_record_context = false,
18
+ bool record_cpp_context = false,
19
+ bool clearHistory = false,
20
+ bool compileContext = false,
21
+ bool globalRecordAllocations = false);
22
+
23
+ TORCH_CUDA_CU_API void _record_memory_history(
24
+ std::optional<std::string> enabled = "all",
25
+ std::optional<std::string> context = "all",
26
+ const std::string& stacks = "all",
27
+ size_t max_entries = SIZE_MAX,
28
+ bool clearHistory = false,
29
+ bool compileContext = false,
30
+ bool globalRecordAllocations = false);
31
+
32
+ TORCH_CUDA_CU_API std::string _memory_snapshot_pickled();
33
+
34
+ } // namespace torch::cuda
35
+
36
+ #else
37
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
38
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/nccl.h ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <ATen/ATen.h>
5
+ #include <ATen/cuda/CUDAContext.h>
6
+
7
+ #include <cstddef>
8
+ #include <optional>
9
+ #include <vector>
10
+
11
+ // NCCL BFloat16 is enabled only for CUDA 11+ and NCCL versions 2.10+, or for
12
+ // HIP 3.1+
13
+ #if defined(__CUDA_BF16_TYPES_EXIST__)
14
+ #define HAS_NCCL_BF16_DATATYPE \
15
+ ((NCCL_MAJOR > 2) || (NCCL_MAJOR == 2) && (NCCL_MINOR >= 10))
16
+ #elif defined(USE_ROCM) && (TORCH_HIP_VERSION >= 301)
17
+ #define HAS_NCCL_BF16_DATATYPE 1
18
+ #else
19
+ #define HAS_NCCL_BF16_DATATYPE 0
20
+ #endif
21
+
22
+ namespace torch::cuda::nccl {
23
+
24
+ /* The following are copied from <nccl.h> and redefined in torch::cuda::nccl
25
+ * namespace */
26
+ /* pytorch should only use the following definition within pytorch scope */
27
+
28
+ /* Opaque handle to communicator to ncclComm*, this will reinterpret as ncclComm
29
+ * in nccl.cpp */
30
+ typedef void* ncclComm_t;
31
+
32
+ /** redefine nccl unique ID in torch scope. this should be identical to native
33
+ * nccl impp. */
34
+ #define NCCL_UNIQUE_ID_BYTES 128
35
+ typedef struct {
36
+ // NOLINTNEXTLINE(*array*)
37
+ char internal[NCCL_UNIQUE_ID_BYTES];
38
+ } ncclUniqueId;
39
+
40
+ /* Error type */
41
+ enum class ncclResult {
42
+ Success = 0,
43
+ UnhandledCudaError = 1,
44
+ SystemError = 2,
45
+ InternalError = 3,
46
+ InvalidArgument = 4,
47
+ InvalidUsage = 5,
48
+ RemoteError = 6,
49
+ InProgress = 7,
50
+ NumResults = 8
51
+ };
52
+
53
+ /* Reduction operation selector */
54
+ enum class ncclRedOp { Sum = 0, Prod = 1, Max = 2, Min = 3, NumOps = 4 };
55
+
56
+ /* Data types */
57
+ enum class ncclDataType {
58
+ Int8 = 0,
59
+ Char = 0,
60
+ Uint8 = 1,
61
+ Int32 = 2,
62
+ Int = 2,
63
+ Uint32 = 3,
64
+ Int64 = 4,
65
+ Uint64 = 5,
66
+ Float16 = 6,
67
+ Half = 6,
68
+ Float32 = 7,
69
+ Float = 7,
70
+ Float64 = 8,
71
+ Double = 8,
72
+ Bfloat16 = 9,
73
+ NumTypes = 10
74
+ };
75
+
76
+ // RAII helper class to manage NCCL group API and CUDA free mutex.
77
+ // The destructor is allowed to throw since this helper class only
78
+ // manages group and lock lifetimes.
79
+ struct TORCH_CUDA_CPP_API AutoNcclGroup {
80
+ AutoNcclGroup();
81
+ AutoNcclGroup(ncclComm_t comm, bool comm_nonblocking);
82
+ ~AutoNcclGroup() noexcept(false);
83
+ ncclComm_t comm_;
84
+ bool comm_nonblocking_;
85
+ };
86
+
87
+ // NOTE: this is exposed only so that python_nccl.cpp can some of these helpers.
88
+ // Don't use them outside of these files.
89
+ namespace detail {
90
+
91
+ TORCH_CUDA_CPP_API void throw_nccl_error(ncclResult status);
92
+
93
+ inline void NCCL_CHECK(ncclResult status) {
94
+ if (status != ncclResult::Success) {
95
+ throw_nccl_error(status);
96
+ }
97
+ }
98
+
99
+ TORCH_CUDA_CPP_API at::ArrayRef<ncclComm_t> get_communicators(
100
+ at::TensorList inputs);
101
+ TORCH_CUDA_CPP_API void check_inputs(
102
+ at::TensorList inputs,
103
+ at::TensorList outputs,
104
+ size_t input_multiplier,
105
+ size_t output_multiplier);
106
+ TORCH_CUDA_CPP_API void check_inputs(
107
+ at::TensorList inputs,
108
+ const at::Tensor& output,
109
+ int root,
110
+ size_t input_multiplier,
111
+ size_t output_multiplier);
112
+
113
+ } // namespace detail
114
+
115
+ using comm_list = std::vector<ncclComm_t>;
116
+ using stream_list = std::vector<std::optional<at::cuda::CUDAStream>>;
117
+
118
+ TORCH_CUDA_CPP_API std::uint64_t version();
119
+ TORCH_CUDA_CPP_API const char* version_suffix();
120
+
121
+ bool is_available(at::TensorList tensors);
122
+
123
+ TORCH_CUDA_CPP_API void get_unique_id(ncclUniqueId& id);
124
+ TORCH_CUDA_CPP_API ncclComm_t
125
+ comm_init_rank(int nranks, const ncclUniqueId& comm_id, int rank);
126
+ TORCH_CUDA_CPP_API void comm_destroy(ncclComm_t comm);
127
+
128
+ TORCH_CUDA_CPP_API void broadcast(
129
+ at::TensorList tensors,
130
+ const stream_list& streams = {},
131
+ const comm_list& user_comms = {});
132
+
133
+ size_t get_max_count();
134
+
135
+ TORCH_CUDA_CPP_API void reduce(
136
+ const std::vector<at::Tensor>& inputs,
137
+ at::Tensor& output,
138
+ int32_t root = 0,
139
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
140
+ const stream_list& streams = {},
141
+ const comm_list& user_comms = {});
142
+
143
+ TORCH_CUDA_CPP_API void reduce(
144
+ std::vector<at::Tensor>& inputs,
145
+ int32_t root = 0,
146
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
147
+ const stream_list& streams = {},
148
+ const comm_list& user_comms = {});
149
+
150
+ TORCH_CUDA_CPP_API void all_reduce(
151
+ const std::vector<at::Tensor>& inputs,
152
+ std::vector<at::Tensor>& outputs,
153
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
154
+ const stream_list& streams = {},
155
+ const comm_list& user_comms = {});
156
+
157
+ TORCH_CUDA_CPP_API void reduce_scatter(
158
+ const std::vector<at::Tensor>& inputs,
159
+ std::vector<at::Tensor>& outputs,
160
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
161
+ const stream_list& streams = {},
162
+ const comm_list& user_comms = {});
163
+
164
+ TORCH_CUDA_CPP_API void scatter(
165
+ const std::vector<at::Tensor>& inputs,
166
+ at::Tensor& outputs,
167
+ ncclComm_t comm,
168
+ at::cuda::CUDAStream& stream,
169
+ int32_t root = 0);
170
+
171
+ TORCH_CUDA_CPP_API void all_gather(
172
+ const std::vector<at::Tensor>& inputs,
173
+ std::vector<at::Tensor>& outputs,
174
+ const stream_list& streams = {},
175
+ const comm_list& user_comms = {});
176
+
177
+ TORCH_CUDA_CPP_API void gather(
178
+ const at::Tensor& inputs,
179
+ std::vector<at::Tensor>& outputs,
180
+ ncclComm_t comm,
181
+ at::cuda::CUDAStream& stream,
182
+ int32_t root = 0);
183
+
184
+ TORCH_CUDA_CPP_API void all2all_single_equal_split(
185
+ at::Tensor& input,
186
+ at::Tensor& output,
187
+ int size,
188
+ ncclComm_t comm,
189
+ at::cuda::CUDAStream& stream);
190
+
191
+ TORCH_CUDA_CPP_API void all2all_single_unequal_split(
192
+ void* sendbuff,
193
+ const size_t* sendcounts,
194
+ const size_t* senddispls,
195
+ void* recvbuff,
196
+ const size_t* recvcounts,
197
+ const size_t* recvdispls,
198
+ size_t size,
199
+ c10::ScalarType type,
200
+ ncclComm_t comm,
201
+ at::cuda::CUDAStream& stream);
202
+
203
+ TORCH_CUDA_CPP_API void all2all(
204
+ std::vector<at::Tensor>& outputTensors,
205
+ std::vector<at::Tensor>& inputTensors,
206
+ ncclComm_t _comm,
207
+ at::cuda::CUDAStream& stream);
208
+
209
+ TORCH_CUDA_CPP_API void send(
210
+ const at::Tensor& input,
211
+ ncclComm_t comm,
212
+ at::cuda::CUDAStream stream,
213
+ int dst);
214
+
215
+ TORCH_CUDA_CPP_API void recv(
216
+ at::Tensor& output,
217
+ ncclComm_t comm,
218
+ at::cuda::CUDAStream stream,
219
+ int src);
220
+ } // namespace torch::cuda::nccl
221
+
222
+ #else
223
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
224
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_comm.h ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/utils/pythoncapi_compat.h>
5
+ namespace torch::cuda::python {
6
+
7
+ void initCommMethods(PyObject* module);
8
+
9
+ } // namespace torch::cuda::python
10
+
11
+ #else
12
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
13
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_nccl.h ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/python_headers.h>
5
+
6
+ PyObject* THCPModule_nccl_version(PyObject* self, PyObject* args);
7
+ PyObject* THCPModule_nccl_version_suffix(PyObject* self, PyObject* args);
8
+ PyObject* THCPModule_nccl_unique_id(PyObject* self, PyObject* args);
9
+ PyObject* THCPModule_nccl_init_rank(PyObject* self, PyObject* args);
10
+ PyObject* THCPModule_nccl_reduce(PyObject* self, PyObject* args);
11
+ PyObject* THCPModule_nccl_all_reduce(PyObject* self, PyObject* args);
12
+ PyObject* THCPModule_nccl_broadcast(PyObject* self, PyObject* args);
13
+ PyObject* THCPModule_nccl_all_gather(PyObject* self, PyObject* args);
14
+ PyObject* THCPModule_nccl_reduce_scatter(PyObject* self, PyObject* args);
15
+
16
+ #else
17
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
18
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/utils.h ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <c10/cuda/CUDAStream.h>
5
+ #include <torch/csrc/utils/python_numbers.h>
6
+
7
+ #include <vector>
8
+
9
+ std::vector<std::optional<at::cuda::CUDAStream>>
10
+ THPUtils_PySequence_to_CUDAStreamList(PyObject* obj);
11
+
12
+ #else
13
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
14
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/Placement.h ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+ /**
4
+ * The implementations in this file are coupled with
5
+ * torch/distributed/tensor/placement_types.py.
6
+ */
7
+
8
+ #include <cstdint>
9
+ #include <optional>
10
+ #include <string>
11
+ #include <string_view>
12
+
13
+ namespace torch::distributed {
14
+
15
+ class Placement {
16
+ public:
17
+ Placement() = default;
18
+ virtual ~Placement() = default;
19
+
20
+ Placement(const Placement&) = default;
21
+ Placement& operator=(const Placement&) = default;
22
+ Placement(Placement&&) noexcept = default;
23
+ Placement& operator=(Placement&&) noexcept = default;
24
+
25
+ virtual bool is_shard(std::optional<std::int64_t> dim) const {
26
+ return false;
27
+ }
28
+
29
+ virtual bool is_replicate() const {
30
+ return false;
31
+ }
32
+
33
+ virtual bool is_partial(
34
+ std::optional<std::string_view> reduce_op = std::nullopt) const {
35
+ return false;
36
+ }
37
+ };
38
+
39
+ class Shard : public Placement {
40
+ public:
41
+ std::int64_t dim;
42
+ explicit Shard(std::int64_t dim) : dim(dim) {}
43
+
44
+ bool is_shard(std::optional<std::int64_t> dim_) const override {
45
+ if (typeid(*this) != typeid(Shard)) {
46
+ return false;
47
+ }
48
+ return !dim_.has_value() || *dim_ == dim;
49
+ }
50
+
51
+ bool operator==(const Shard& rhs) const {
52
+ return dim == rhs.dim;
53
+ }
54
+
55
+ bool operator!=(const Shard& rhs) const {
56
+ return !operator==(rhs);
57
+ }
58
+ };
59
+
60
+ class StridedShard : public Placement {
61
+ public:
62
+ std::int64_t dim;
63
+ std::int64_t split_factor;
64
+ explicit StridedShard(std::int64_t dim, std::int64_t split_factor_)
65
+ : dim(dim), split_factor(split_factor_) {}
66
+
67
+ bool operator==(const StridedShard& rhs) const {
68
+ return dim == rhs.dim && split_factor == rhs.split_factor;
69
+ }
70
+
71
+ bool operator!=(const StridedShard& rhs) const {
72
+ return !operator==(rhs);
73
+ }
74
+ };
75
+
76
+ class Replicate : public Placement {
77
+ public:
78
+ bool is_replicate() const override {
79
+ return true;
80
+ }
81
+
82
+ bool operator==(const Replicate& rhs) const {
83
+ return true;
84
+ }
85
+
86
+ bool operator!=(const Replicate& rhs) const {
87
+ return false;
88
+ }
89
+ };
90
+
91
+ class Partial : public Placement {
92
+ public:
93
+ std::string reduce_op;
94
+
95
+ Partial() : Partial("sum") {}
96
+
97
+ explicit Partial(std::optional<std::string> reduce_op_)
98
+ : reduce_op(
99
+ reduce_op_.has_value() ? std::move(*reduce_op_)
100
+ : std::string("sum")) {}
101
+
102
+ bool is_partial(
103
+ std::optional<std::string_view> op = std::nullopt) const override {
104
+ return !op.has_value() || *op == reduce_op;
105
+ }
106
+
107
+ bool operator==(const Partial& rhs) const {
108
+ return reduce_op == rhs.reduce_op;
109
+ }
110
+
111
+ bool operator!=(const Partial& rhs) const {
112
+ return !operator==(rhs);
113
+ }
114
+ };
115
+
116
+ } // namespace torch::distributed
117
+
118
+ #else
119
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
120
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/autograd.h ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/distributed/autograd/context/container.h>
5
+ #include <torch/csrc/distributed/autograd/engine/dist_engine.h>
6
+
7
+ namespace torch::distributed::autograd {
8
+
9
+ using torch::autograd::variable_list;
10
+
11
+ /// C++ API of Distributed Autograd that kicks off the distributed backward pass
12
+ /// using the provided roots. This currently implements the
13
+ /// :ref:`fast-mode-algorithm` which assumes all RPC messages sent in the same
14
+ /// distributed autograd context across workers would be part of the autograd
15
+ /// graph during the backward pass.
16
+ ///
17
+ /// We use the provided roots to discover the autograd graph and compute
18
+ /// appropriate dependencies. This method blocks until the entire
19
+ /// autograd computation is done.
20
+ /// This function accumulates gradients in the leaves - you might need to zero
21
+ /// them before calling it.
22
+ ///
23
+ /// \param context_id The autograd context id for which we should retrieve the
24
+ /// gradients.
25
+ /// \param roots Tensors which represent the roots of the autograd computation.
26
+ /// All the tensors should be scalars.
27
+ /// \param retain_graph If `false`, the graph used to compute the grad will be
28
+ /// freed. Note that in nearly all cases setting this
29
+ /// option to `true` is not needed and often can be worked
30
+ /// around in a much more efficient way. Usually, you need
31
+ /// to set this to `true` to run backward multiple times.
32
+ TORCH_API void backward(
33
+ int64_t context_id,
34
+ const variable_list& roots,
35
+ bool retain_graph = false);
36
+
37
+ } // namespace torch::distributed::autograd
38
+
39
+ #else
40
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
41
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/context/container.h ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <mutex>
5
+ #include <unordered_map>
6
+
7
+ #include <torch/csrc/distributed/autograd/context/context.h>
8
+
9
+ namespace torch::distributed::autograd {
10
+
11
+ // Singleton class per worker which is responsible for storing the distributed
12
+ // autograd context for each autograd pass and also cleans up data for an
13
+ // autograd pass once its done.
14
+ //
15
+ // Each autograd pass is assigned a unique autograd_context_id and all data for
16
+ // that pass (DistAutogradContext) is stored in this container indexed by the
17
+ // autograd_context_id. The autograd_context_id itself is a 64 bit globally
18
+ // unique id. The first 16 bits is the worker_id and the next 48 bits is an
19
+ // auto-incrementing id for each worker.
20
+ //
21
+ // This container is also responsible for maintaining a globally unique message
22
+ // id, which is used to associate send/recv autograd function pairs. The format
23
+ // is similar to the autograd_context_id where we have a 64 bit integer with
24
+ // first 16 bits being the worker id and next 48 bits are auto-incrementing.
25
+ class TORCH_API DistAutogradContainer {
26
+ public:
27
+ explicit DistAutogradContainer(uint32_t num_shards);
28
+
29
+ // One time initialization of the container.
30
+ static DistAutogradContainer& init(int64_t worker_id);
31
+
32
+ // Retrieve the singleton instance of the container, ensures we have
33
+ // initialized the container.
34
+ static DistAutogradContainer& getInstance();
35
+
36
+ // Create a new context for a distributed autograd pass.
37
+ const ContextPtr newContext();
38
+
39
+ // Clean up resources for a given context_id once the autograd pass is done.
40
+ // Sends RPC to other workers this worker knows about, telling them to clean
41
+ // up their context as well. Throws an exception if the context_id does not
42
+ // exist.
43
+ void releaseContext(int64_t context_id);
44
+
45
+ // Releases an autograd context if it is present on this node. Also sends RPC
46
+ // to other workers this worker knows about, telling them to clean up their
47
+ // context. Does nothing if it is not present.
48
+ void releaseContextIfPresent(int64_t context_id);
49
+
50
+ // Checks if the passed in context_id is valid.
51
+ void isValidContext(int64_t context_id);
52
+
53
+ // Retrieve the autograd context for a given context_id.
54
+ ContextPtr retrieveContext(int64_t context_id);
55
+
56
+ // Retrieves the currently active autograd context for the current thread.
57
+ ContextPtr currentContext();
58
+
59
+ // Checks whether or not the current thread has a valid autograd context.
60
+ bool hasValidContext() const;
61
+
62
+ // Generate a new autograd_message_id for send/recv autograd functions.
63
+ int64_t newAutogradMessageId();
64
+
65
+ // Creates a new autograd context with the provided context_id. If a context
66
+ // already exists with the provided context_id, we just return it.
67
+ // This does not set the current context for the current thread.
68
+ ContextPtr getOrCreateContext(int64_t context_id);
69
+
70
+ // Retrieves the maximum possible autograd_context_id/autograd_message_id that
71
+ // can be generated by this worker.
72
+ int64_t getMaxId();
73
+
74
+ // Retrieves the worker ID for this node
75
+ rpc::worker_id_t getWorkerId() const;
76
+
77
+ // Can set current context id if there is no valid context yet
78
+ static void setCurrentContextId(int64_t contextId);
79
+
80
+ // Forcibly sets the thread local current context id. Should only be used in
81
+ // cases where you know what you're doing and need to override the thread
82
+ // local. Otherwise, use setCurrentContextId instead.
83
+ static void forceCurrentContextId(int64_t contextId);
84
+
85
+ // Clear current context id
86
+ void clearCurrentContext();
87
+
88
+ // Returns the number of autograd contexts in the container.
89
+ size_t numAutogradContexts() const;
90
+
91
+ // Returns the current thread local context id for this thread.
92
+ static int64_t currentContextId();
93
+
94
+ DistAutogradContainer() = delete;
95
+ ~DistAutogradContainer() = default;
96
+ DistAutogradContainer(const DistAutogradContainer&) = delete;
97
+ DistAutogradContainer& operator=(const DistAutogradContainer&) = delete;
98
+ DistAutogradContainer(DistAutogradContainer&&) = delete;
99
+ DistAutogradContainer& operator=(DistAutogradContainer&&) = delete;
100
+
101
+ private:
102
+ // Number of shards for the map storing autograd contexts. We'd like this
103
+ // to be a power of 2 and we don't expect a value much higher than the
104
+ // number of cores would provide much benefit.
105
+ static constexpr uint32_t kNumDefaultShards = 128;
106
+
107
+ // Use cache line size for alignment.
108
+ static constexpr int kCacheLineSize = 64;
109
+
110
+ // Structure holding one shard of the sharded autograd context map with its
111
+ // associated lock. Align to cache line size to avoid contention between
112
+ // adjacent entries.
113
+ struct alignas(kCacheLineSize) ContextsShard {
114
+ // Lock for this shard.
115
+ mutable std::mutex lock;
116
+
117
+ // Map storing autograd contexts for this shard.
118
+ std::unordered_map<int64_t, ContextPtr> contexts;
119
+ };
120
+
121
+ static DistAutogradContainer& getInstanceInternal();
122
+
123
+ // Retrieve the shard for given context_id.
124
+ ContextsShard& getShard(int64_t context_id);
125
+
126
+ // Sends an RPC to the workers that have a context corresponding to passed in
127
+ // context_id. This function should be called with the lock.
128
+ void sendReleaseContextRpc(
129
+ const std::unordered_set<rpc::worker_id_t>& workerIds,
130
+ int64_t context_id);
131
+
132
+ // Erase context_id from the autograd context map, and reset the thread local
133
+ // current context id if it corresponds to the passed in context id. This
134
+ // function should be called with the lock.
135
+ void eraseContextIdAndReset(ContextsShard& shard, int64_t context_id);
136
+
137
+ // Compute the number of shards for the autograd_contexts_ map.
138
+ static uint32_t computeNumShards();
139
+
140
+ // Auto incrementing context id used to identify unique autograd passes.
141
+ // Initialized with the first 16 bits being the worker_id.
142
+ std::atomic<int64_t> next_context_id_;
143
+
144
+ // Unique id to identify a worker in the distributed setting.
145
+ int16_t worker_id_;
146
+
147
+ // Whether or not the container has been initialized appropriately.
148
+ bool initialized_;
149
+
150
+ // Sharded autograd context map.
151
+ std::vector<ContextsShard> autograd_contexts_;
152
+
153
+ // Number of shards for the sharded autograd_contexts_ map.
154
+ uint32_t num_shards_;
155
+
156
+ // Autograd message id to identify unique send/recv autograd function pairs.
157
+ std::atomic<int64_t> next_autograd_message_id_;
158
+
159
+ // Maximum allowed value for autograd_context_id or autograd_message_id.
160
+ int64_t max_id_;
161
+ };
162
+
163
+ } // namespace torch::distributed::autograd
164
+
165
+ #else
166
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
167
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/context/context.h ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <cstdint>
5
+ #include <functional>
6
+
7
+ #include <ATen/core/Dict.h>
8
+ #include <torch/csrc/autograd/engine.h>
9
+ #include <torch/csrc/distributed/autograd/functions/recvrpc_backward.h>
10
+ #include <torch/csrc/distributed/autograd/functions/sendrpc_backward.h>
11
+ #include <torch/csrc/distributed/rpc/rpc_agent.h>
12
+
13
+ namespace torch::distributed::autograd {
14
+
15
+ class RecvRpcBackward;
16
+
17
+ // DistAutogradContext which stores information for a single distributed
18
+ // autograd pass on a worker.
19
+ class TORCH_API DistAutogradContext {
20
+ public:
21
+ using GradCallback = std::function<bool(torch::Tensor&)>;
22
+
23
+ explicit DistAutogradContext(int64_t contextId);
24
+ ~DistAutogradContext() = default;
25
+
26
+ // Retrieves the autograd context id for this context.
27
+ int64_t contextId() const;
28
+
29
+ // Records a 'send' autograd function for this context with the provided
30
+ // message id.
31
+ void addSendFunction(
32
+ const std::shared_ptr<SendRpcBackward>& func,
33
+ int64_t autograd_message_id);
34
+
35
+ // Records a 'recv' autograd function for this context with the provided
36
+ // message id.
37
+ void addRecvFunction(
38
+ std::shared_ptr<RecvRpcBackward>& func,
39
+ int64_t autograd_message_id);
40
+
41
+ // Given an autograd_message_id, retrieve the appropriate send function.
42
+ std::shared_ptr<SendRpcBackward> retrieveSendFunction(
43
+ int64_t autograd_message_id);
44
+
45
+ // Return all send functions for this context.
46
+ std::unordered_map<int64_t, std::shared_ptr<SendRpcBackward>> sendFunctions()
47
+ const;
48
+
49
+ // Return all recv functions for this context.
50
+ std::unordered_map<int64_t, std::shared_ptr<RecvRpcBackward>> recvFunctions()
51
+ const;
52
+
53
+ // Adds a future message recording an outstanding RPC.
54
+ void addOutstandingRpc(const c10::intrusive_ptr<rpc::JitFuture>& jitFuture);
55
+
56
+ // Returns all gradients.
57
+ const c10::Dict<torch::Tensor, torch::Tensor> getGradients() const;
58
+
59
+ // This function gives a mutable grad reference to the callback.
60
+ // If the callback returns true, it means the grad in the context
61
+ // needs to be updated.
62
+ void runGradCallbackForVariable(
63
+ const torch::autograd::Variable& variable,
64
+ const GradCallback& cb);
65
+
66
+ DistAutogradContext(const DistAutogradContext&) = delete;
67
+ DistAutogradContext& operator=(const DistAutogradContext&) = delete;
68
+ DistAutogradContext(DistAutogradContext&&) = delete;
69
+ DistAutogradContext& operator=(DistAutogradContext&&) = delete;
70
+
71
+ // records the workerID of a node that we sent an RPC to.
72
+ // workerIDs are added here when we attach a send function to this autograd
73
+ // context
74
+ void addKnownWorkerId(const rpc::worker_id_t workerId);
75
+
76
+ // Retrieves a set containing the known workerIds for this context
77
+ // These are the different workers that this context has sent RPCs to.
78
+ std::unordered_set<rpc::worker_id_t> getKnownWorkerIds() const;
79
+
80
+ private:
81
+ friend class BackwardPassCleanupGuard;
82
+ friend class DistEngine;
83
+ friend class RecvRpcBackward;
84
+ friend class DistAccumulateGradCaptureHook;
85
+
86
+ // Record that we would like to accumulate the provided gradient on the given
87
+ // variable.
88
+ void accumulateGrad(
89
+ const torch::autograd::Variable& variable,
90
+ const torch::Tensor& grad,
91
+ size_t num_expected_refs);
92
+
93
+ // Retrieve the GraphTask.
94
+ std::shared_ptr<torch::autograd::GraphTask> retrieveGraphTask();
95
+
96
+ // Set the appropriate graph task for the backward pass. Can be called only
97
+ // once.
98
+ void setGraphTask(std::shared_ptr<torch::autograd::GraphTask> graphTask);
99
+
100
+ // Resets the graph task to ensure we can run another distributed backward
101
+ // pass for the same autograd context.
102
+ void resetGraphTask();
103
+
104
+ // Waits for all outstanding RPCs for this context to finish and clears all
105
+ // outstanding rpcs held in this context. This should be called only once.
106
+ c10::intrusive_ptr<c10::ivalue::Future> clearAndWaitForOutstandingRpcsAsync();
107
+
108
+ void clearOutstandingRpcs();
109
+
110
+ // Record an event to mark the completion of gradient computation. These
111
+ // events will later help to properly synchronize gradients consumptions
112
+ // in getGradients(). We need these events because backward and
113
+ // optimizer.step are separate RPC calls, and will occur on different CUDA
114
+ // streams. Without synchronization, it is possible that gradients are
115
+ // consumed before they are ready.
116
+ void recordGradEvent(c10::Device device);
117
+
118
+ const int64_t contextId_;
119
+
120
+ // Set containing known worker IDs, used in cleaning up autograd context.
121
+ // Whenever a sendRpcBackward is attached to the autograd graph for this
122
+ // context, the destination is added here.
123
+ std::unordered_set<rpc::worker_id_t> knownWorkerIds_;
124
+
125
+ // Map from autograd_message_id to appropriate 'send' autograd function.
126
+ std::unordered_map<int64_t, std::shared_ptr<SendRpcBackward>>
127
+ sendAutogradFunctions_;
128
+
129
+ // Map from autograd_message_id to appropriate 'recv' autograd function.
130
+ std::unordered_map<int64_t, std::shared_ptr<RecvRpcBackward>>
131
+ recvAutogradFunctions_;
132
+
133
+ // Gradients accumulated in this context so far. The key is the variable on
134
+ // which the gradient needs to be accumulated and the value is the gradient
135
+ // that needs to be accumulated on that variable..
136
+ c10::Dict<torch::Tensor, torch::Tensor> accumulatedGrads_;
137
+
138
+ // See comments for recordGradEvent(c10::Device device);
139
+ std::unordered_map<c10::Device, c10::Event> gradReadyEvents_;
140
+ const c10::impl::VirtualGuardImpl impl_;
141
+
142
+ // The autograd GraphTask for the backward pass on this node for this context.
143
+ std::shared_ptr<torch::autograd::GraphTask> graphTask_;
144
+
145
+ // List of futures for RPCs initiated by this node to propagate gradients to
146
+ // other nodes. The distributed autograd engine on this node can return
147
+ // successfully only if all these futures are done and are successful.
148
+ std::vector<c10::intrusive_ptr<rpc::JitFuture>> outStandingRpcs_;
149
+
150
+ // Lock to protect concurrent modification of the context.
151
+ mutable std::mutex lock_;
152
+ };
153
+
154
+ using ContextPtr = std::shared_ptr<DistAutogradContext>;
155
+
156
+ // This class stores a shared_ptr to a DistAutogradContext instance in a
157
+ // thread local variable. The instance is given by the call site. The class
158
+ // doesn't know the current context. It's just a util class.
159
+ class TORCH_API ThreadLocalDistAutogradContext {
160
+ public:
161
+ // Store 'new_context' to the thread local variable maintained by this class.
162
+ explicit ThreadLocalDistAutogradContext(ContextPtr&& new_context);
163
+ ~ThreadLocalDistAutogradContext();
164
+
165
+ // Retrieve the stored DistAutogradContext instance.
166
+ static ContextPtr getContextPtr();
167
+
168
+ private:
169
+ ContextPtr prev_context_ptr_;
170
+ };
171
+
172
+ } // namespace torch::distributed::autograd
173
+
174
+ #else
175
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
176
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/engine/dist_engine.h ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <mutex>
5
+ #include <unordered_set>
6
+
7
+ #include <torch/csrc/autograd/engine.h>
8
+ #include <torch/csrc/autograd/function.h>
9
+ #include <torch/csrc/autograd/functions/basic_ops.h>
10
+ #include <torch/csrc/distributed/autograd/context/context.h>
11
+
12
+ namespace torch::distributed::autograd {
13
+
14
+ // Forward declaration.
15
+ class BackwardPassCleanupGuard;
16
+
17
+ // This is a singleton class responsible for running distributed backward
18
+ // passes. This engine relies heavily on the vanilla autograd engine and tries
19
+ // to reuse it as much as possible. This class is mostly responsible for the
20
+ // distributed aspects of autograd and tries to hook into the autograd engine
21
+ // where convenient.
22
+
23
+ // Unlike the vanilla autograd engine, the distributed autograd engine
24
+ // accumulates the gradients in the appropriate DistAutogradContext. This avoids
25
+ // multiple trainer nodes stomping on each others gradients.
26
+ class TORCH_API DistEngine {
27
+ public:
28
+ // Retrieve the singleton instance.
29
+ static DistEngine& getInstance();
30
+
31
+ // Given a list of root variables, start the distributed backwards pass from
32
+ // these variables and accumulate all the gradients in the current autograd
33
+ // context on each node. This method is used to kickoff distributed autograd
34
+ // on a single node.
35
+ void execute(
36
+ int64_t context_id,
37
+ const torch::autograd::variable_list& roots,
38
+ bool retainGraph);
39
+
40
+ // Given a send function to execute in the autograd engine, ensures we compute
41
+ // dependencies once for this node and enqueues the send function for execute
42
+ // in the engine.
43
+ // This method is used to kick off the autograd computation on a node when it
44
+ // receives gradients from the corresponding 'recv' method on another node.
45
+ // The gradients are accumulated in the provided autograd context.
46
+ c10::intrusive_ptr<c10::ivalue::Future> executeSendFunctionAsync(
47
+ const ContextPtr& autogradContext,
48
+ const std::shared_ptr<SendRpcBackward>& sendFunction,
49
+ bool retainGraph);
50
+
51
+ // Number of backward passes currently running for the Distributed Engine.
52
+ size_t numBackwardPasses() const;
53
+
54
+ // Returns key-value pairs consisting of useful debugging information related
55
+ // to distributed autograd.
56
+ std::unordered_map<std::string, int64_t> getDebugInfo() const;
57
+
58
+ DistEngine(const DistEngine&) = delete;
59
+ DistEngine& operator=(const DistEngine&) = delete;
60
+ DistEngine(DistEngine&&) = delete;
61
+ DistEngine& operator=(DistEngine&&) = delete;
62
+
63
+ private:
64
+ // Make sure this is a singleton.
65
+ DistEngine();
66
+ ~DistEngine();
67
+
68
+ // Validates the input roots for the backward computations and retrieves the
69
+ // appropriate root edges and corresponding gradients. Populates root_edges
70
+ // with the appropriate gradient edges and grads with the gradients for each
71
+ // edge.
72
+ void validateRootsAndRetrieveEdges(
73
+ const torch::autograd::variable_list& roots,
74
+ torch::autograd::edge_list& rootEdges,
75
+ torch::autograd::variable_list& grads);
76
+
77
+ // Given the autograd context, root edges and grads, we compute dependencies
78
+ // for the local node and fill out the provided GraphTask and GraphRoot with
79
+ // appropriate information for the local autograd engine.
80
+ // We also determine all leaf nodes(functions) in the graph and accumulate
81
+ // them in outputEdges.
82
+ void computeDependencies(
83
+ const ContextPtr& context,
84
+ const torch::autograd::edge_list& rootEdges,
85
+ const torch::autograd::variable_list& grads,
86
+ const std::shared_ptr<torch::autograd::Node>& graphRoot,
87
+ torch::autograd::edge_list& outputEdges,
88
+ bool retainGraph);
89
+
90
+ // Given a pre-populated GraphTask and a root node, compute the backward pass
91
+ // for the autograd graph until the graph task ready queue is empty.
92
+ //
93
+ // This method assumes that the appropriate GraphTask has already been
94
+ // initialized appropriately. It will construct a local ready queue to
95
+ // traverse the GraphTask instead of using the GraphTask embedded
96
+ // cpu_ready_queue, this is because dist engine might run the same GraphTask
97
+ // from different SendFunctions concurrently in different threads. The method
98
+ // will only mark the GraphTask as completed when it needs to, which means it
99
+ // might not mark as completed for every call as dist engine would like to
100
+ // keep the GraphTask alive when it not receives all gradients.
101
+ //
102
+ // When `incrementOutstandingTasks=false`, the function does not increment
103
+ // 'outstanding_tasks_' in the appropriate GraphTask. It is assumed we've
104
+ // already done this before hand for this task (to ensure we don't pre-mark
105
+ // this graph_task as completed). This is useful in the distributed autograd
106
+ // case where we need to increment 'outstanding_tasks_' first to indicate the
107
+ // local autograd engine the graph task is not completed until it receives the
108
+ // signals from other workers over the network.
109
+ //
110
+ // XXX: calling this function assumes that we will have NO GPU nodetasks be
111
+ // executed for the graph_task, the caller of this function need to ensure
112
+ // this otherwise there will be undefined behaviors. A correct way to fix this
113
+ // is to re-design the autograd engine so that GPU worker thread to behave the
114
+ // same as CPU caller thread, record the operation/thread for the device, and
115
+ // reuse it in backward.
116
+ // TODO: 1. Add assert in the dist engine to ensure no GPU NodeTasks during
117
+ // backward
118
+ // 2. properly setup the thread local ready queue to enable reentrant
119
+ // backwards
120
+ void execute_graph_task_until_ready_queue_empty(
121
+ torch::autograd::NodeTask&& node_task,
122
+ bool incrementOutstandingTasks = true);
123
+
124
+ // Run the local autograd engine using the provided graphTask and graphRoot
125
+ // and accumulate the gradients part 'outputEdges' in the provided autograd
126
+ // context.
127
+ c10::intrusive_ptr<c10::ivalue::Future> runEngineAndAccumulateGradients(
128
+ const ContextPtr& autogradContext,
129
+ const std::shared_ptr<torch::autograd::Node>& graphRoot,
130
+ const torch::autograd::edge_list& outputEdges,
131
+ bool incrementOutStandingTasks = true);
132
+
133
+ // Run after the backward pass is done to appropriately cleanup structures.
134
+ void cleanupBackwardPass(const ContextPtr& autogradContext);
135
+
136
+ // Global thread to execute CPU continuations.
137
+ void globalCpuThread(
138
+ const std::shared_ptr<torch::autograd::ReadyQueue>& ready_queue);
139
+
140
+ // Set of autograd context_ids, which we have already initialized for
141
+ // distributed autograd on this node (e.g.: already computed dependencies)
142
+ std::unordered_set<int64_t> initializedContextIds_;
143
+
144
+ mutable std::mutex initializedContextIdsLock_;
145
+
146
+ // Reference to local autograd engine.
147
+ torch::autograd::Engine& engine_;
148
+
149
+ // Ready queue used by the CPU thread in distributed engine.
150
+ // See Note [GPU to CPU continuations]
151
+ std::shared_ptr<torch::autograd::ReadyQueue> global_cpu_ready_queue_;
152
+
153
+ // See Note [GPU to CPU continuations]
154
+ std::thread global_cpu_thread_;
155
+
156
+ friend class BackwardPassCleanupGuard;
157
+ };
158
+
159
+ // Guard to clean up resources once the backward pass is done.
160
+ class BackwardPassCleanupGuard {
161
+ public:
162
+ explicit BackwardPassCleanupGuard(ContextPtr autogradContext)
163
+ : autogradContext_(std::move(autogradContext)) {}
164
+
165
+ ~BackwardPassCleanupGuard() {
166
+ DistEngine::getInstance().cleanupBackwardPass(autogradContext_);
167
+ }
168
+
169
+ private:
170
+ ContextPtr autogradContext_;
171
+ };
172
+
173
+ } // namespace torch::distributed::autograd
174
+
175
+ #else
176
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
177
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/functions/recvrpc_backward.h ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/autograd/function.h>
5
+ #include <torch/csrc/distributed/autograd/context/context.h>
6
+ #include <torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h>
7
+ #include <torch/csrc/distributed/rpc/rpc_agent.h>
8
+
9
+ namespace torch::distributed::autograd {
10
+
11
+ // Forward declarations.
12
+ class DistAutogradContext;
13
+
14
+ // As part of our distributed autograd implementation, whenever we receive an
15
+ // RPC from a node, we add a 'RecvRpcBackward' autograd function to the
16
+ // autograd graph. This is more or less a placeholder function that is used to
17
+ // pass gradients to the remote host during the backward pass. The inputs to the
18
+ // RPC function are the inputs to this autograd function.
19
+ class TORCH_API RecvRpcBackward : public torch::autograd::Node {
20
+ public:
21
+ explicit RecvRpcBackward(
22
+ const AutogradMetadata& autogradMetadata,
23
+ const std::shared_ptr<DistAutogradContext>& autogradContext,
24
+ rpc::worker_id_t fromWorkerId,
25
+ rpc::DeviceMap deviceMap);
26
+
27
+ torch::autograd::variable_list apply(
28
+ torch::autograd::variable_list&& grads) override;
29
+
30
+ private:
31
+ const AutogradMetadata autogradMetadata_;
32
+
33
+ // Hold a weak reference to the autograd context to avoid circular
34
+ // dependencies with the context (since it holds a reference to
35
+ // RecvRpcBackward).
36
+ std::weak_ptr<DistAutogradContext> autogradContext_;
37
+
38
+ // The worker id from which the RPC was received. During the backward pass,
39
+ // we need to propagate the gradients to this workerId.
40
+ rpc::worker_id_t fromWorkerId_;
41
+
42
+ // Device mapping for tensors sent over RPC.
43
+ const rpc::DeviceMap deviceMap_;
44
+ };
45
+
46
+ } // namespace torch::distributed::autograd
47
+
48
+ #else
49
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
50
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/functions/sendrpc_backward.h ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/autograd/function.h>
5
+
6
+ namespace torch::distributed::autograd {
7
+
8
+ // As part of our distributed autograd implementation, whenever we send an RPC
9
+ // from one node to another, we add a 'SendRpcBackward' autograd function to the
10
+ // autograd graph. This is more or less a placeholder function that is used to
11
+ // kickoff the autograd engine on the current worker on the backward pass. The
12
+ // edges for this autograd function are the inputs to the RPC method.
13
+ //
14
+ // During the backward pass, this function is queued for execution in the
15
+ // autograd engine which eventually runs the rest of the autograd graph.
16
+ struct TORCH_API SendRpcBackward : public torch::autograd::Node {
17
+ public:
18
+ torch::autograd::variable_list apply(
19
+ torch::autograd::variable_list&& inputs) override;
20
+
21
+ // SendRpcBackward is actually the root of an autograd graph on the local
22
+ // node. As a result, it doesn't receive any 'inputs', but rather the RPC
23
+ // framework passes gradients over to this function to kickoff local autograd
24
+ // computation.
25
+ void setGrads(const torch::autograd::variable_list& grads);
26
+
27
+ // Retrieve the grads for the function.
28
+ const torch::autograd::variable_list& getGrads() const;
29
+
30
+ private:
31
+ torch::autograd::variable_list grads_;
32
+ };
33
+
34
+ } // namespace torch::distributed::autograd
35
+
36
+ #else
37
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
38
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/python_autograd.h ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/python_headers.h>
5
+
6
+ namespace torch::distributed::autograd {
7
+
8
+ PyMethodDef* python_functions();
9
+
10
+ } // namespace torch::distributed::autograd
11
+
12
+ #else
13
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
14
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/Export.h>
5
+ #include <cstdint>
6
+
7
+ namespace torch::distributed::autograd {
8
+
9
+ // This structure represents autograd metadata that we need to pass across
10
+ // different nodes when we call an RPC which needs autograd computation.
11
+ struct TORCH_API AutogradMetadata {
12
+ AutogradMetadata(int64_t autogradContextId, int64_t autogradMessageId);
13
+
14
+ // autogradContextId_ is a globally unique integer that identifies a
15
+ // particular distributed autograd pass.
16
+ int64_t autogradContextId;
17
+ // autogradMessageId_ is a globally unique integer that identifies a pair
18
+ // of send/recv autograd functions.
19
+ int64_t autogradMessageId;
20
+ };
21
+
22
+ } // namespace torch::distributed::autograd
23
+
24
+ #else
25
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
26
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_req.h ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h>
5
+ #include <torch/csrc/distributed/rpc/message.h>
6
+ #include <torch/csrc/distributed/rpc/rpc_command_base.h>
7
+
8
+ namespace torch::distributed::autograd {
9
+
10
+ // Used to request other workers to clean up their autograd context.
11
+ class TORCH_API CleanupAutogradContextReq : public rpc::RpcCommandBase {
12
+ public:
13
+ explicit CleanupAutogradContextReq(int64_t context_id);
14
+ // Serialization and deserialization methods.
15
+ c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
16
+ static std::unique_ptr<CleanupAutogradContextReq> fromMessage(
17
+ const rpc::Message& message);
18
+
19
+ // Retrieve the context id we are cleaning up with this message.
20
+ int64_t getContextId();
21
+
22
+ private:
23
+ int64_t context_id_;
24
+ };
25
+
26
+ } // namespace torch::distributed::autograd
27
+
28
+ #else
29
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
30
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
miniconda3/envs/active_proaction/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_resp.h ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ #pragma once
3
+
4
+ #include <torch/csrc/distributed/rpc/message.h>
5
+ #include <torch/csrc/distributed/rpc/rpc_command_base.h>
6
+
7
+ namespace torch::distributed::autograd {
8
+
9
+ // Empty response for CleanupAutogradContextReq. Send to acknowledge receipt of
10
+ // a CleanupAutogradContextReq.
11
+ class TORCH_API CleanupAutogradContextResp : public rpc::RpcCommandBase {
12
+ public:
13
+ CleanupAutogradContextResp() = default;
14
+ // Serialization and deserialization methods.
15
+ c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
16
+ static std::unique_ptr<CleanupAutogradContextResp> fromMessage(
17
+ const rpc::Message& message);
18
+ };
19
+
20
+ } // namespace torch::distributed::autograd
21
+
22
+ #else
23
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
24
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)