jasonfan commited on
Commit
83d54ac
·
verified ·
1 Parent(s): 38af1f7

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. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/python_functions.h +25 -0
  2. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/python_return_types.h +98 -0
  3. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/variable_factories.h +746 -0
  4. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/error_messages.h +18 -0
  5. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/grad_layout_contract.h +76 -0
  6. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/lambda_post_hook.h +42 -0
  7. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/python_arg_parsing.h +49 -0
  8. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/warnings.h +24 -0
  9. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/wrap_outputs.h +149 -0
  10. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cpu/Module.h +8 -0
  11. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/CUDAPluggableAllocator.h +194 -0
  12. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Event.h +19 -0
  13. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/GdsFile.h +9 -0
  14. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Module.h +12 -0
  15. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Stream.h +20 -0
  16. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/THCP.h +8 -0
  17. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/comm.h +52 -0
  18. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/device_set.h +11 -0
  19. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/memory_snapshot.h +33 -0
  20. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/nccl.h +219 -0
  21. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_comm.h +8 -0
  22. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_nccl.h +13 -0
  23. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/utils.h +9 -0
  24. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/autograd.h +36 -0
  25. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/context/container.h +162 -0
  26. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/context/context.h +171 -0
  27. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/engine/dist_engine.h +172 -0
  28. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/functions/recvrpc_backward.h +45 -0
  29. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/functions/sendrpc_backward.h +33 -0
  30. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/python_autograd.h +9 -0
  31. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h +21 -0
  32. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_req.h +25 -0
  33. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_resp.h +19 -0
  34. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/propagate_gradients_req.h +38 -0
  35. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/propagate_gradients_resp.h +20 -0
  36. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_autograd.h +94 -0
  37. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_profiling_req.h +61 -0
  38. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_profiling_resp.h +58 -0
  39. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rref_backward_req.h +38 -0
  40. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rref_backward_resp.h +17 -0
  41. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/utils.h +56 -0
  42. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/Backend.hpp +471 -0
  43. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/Backoff.hpp +52 -0
  44. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/FakeProcessGroup.hpp +199 -0
  45. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/FileStore.hpp +65 -0
  46. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/FlightRecorder.hpp +272 -0
  47. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/FlightRecorderDetail.hpp +550 -0
  48. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/Functional.hpp +3 -0
  49. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/GlooDeviceFactory.hpp +35 -0
  50. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/GroupRegistry.hpp +22 -0
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/python_functions.h ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <Python.h>
4
+
5
+ // @generated from ../tools/autograd/templates/python_functions.h
6
+
7
+ // Python bindings for automatically generated autograd functions
8
+
9
+ namespace torch { namespace autograd { namespace generated {
10
+
11
+ void initialize_autogenerated_functions_0(PyObject* module);
12
+ void initialize_autogenerated_functions_1(PyObject* module);
13
+ void initialize_autogenerated_functions_2(PyObject* module);
14
+ void initialize_autogenerated_functions_3(PyObject* module);
15
+ void initialize_autogenerated_functions_4(PyObject* module);
16
+
17
+ inline void initialize_autogenerated_functions(PyObject* module) {
18
+ initialize_autogenerated_functions_0(module);
19
+ initialize_autogenerated_functions_1(module);
20
+ initialize_autogenerated_functions_2(module);
21
+ initialize_autogenerated_functions_3(module);
22
+ initialize_autogenerated_functions_4(module);
23
+ }
24
+
25
+ }}} // namespace torch::autograd::generated
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/python_return_types.h ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ namespace torch {
4
+ namespace autograd {
5
+ namespace generated {
6
+
7
+ PyTypeObject* get__fake_quantize_per_tensor_affine_cachemask_tensor_qparams_structseq();
8
+ PyTypeObject* get__fused_moving_avg_obs_fq_helper_structseq();
9
+ PyTypeObject* get__linalg_det_structseq();
10
+ PyTypeObject* get__linalg_det_out_structseq();
11
+ PyTypeObject* get__linalg_eigh_structseq();
12
+ PyTypeObject* get__linalg_eigh_out_structseq();
13
+ PyTypeObject* get__linalg_slogdet_structseq();
14
+ PyTypeObject* get__linalg_slogdet_out_structseq();
15
+ PyTypeObject* get__linalg_solve_ex_structseq();
16
+ PyTypeObject* get__linalg_solve_ex_out_structseq();
17
+ PyTypeObject* get__linalg_svd_structseq();
18
+ PyTypeObject* get__linalg_svd_out_structseq();
19
+ PyTypeObject* get__lu_with_info_structseq();
20
+ PyTypeObject* get__scaled_dot_product_cudnn_attention_structseq();
21
+ PyTypeObject* get__scaled_dot_product_efficient_attention_structseq();
22
+ PyTypeObject* get__scaled_dot_product_flash_attention_structseq();
23
+ PyTypeObject* get__scaled_dot_product_flash_attention_for_cpu_structseq();
24
+ PyTypeObject* get__unpack_dual_structseq();
25
+ PyTypeObject* get_aminmax_structseq();
26
+ PyTypeObject* get_aminmax_out_structseq();
27
+ PyTypeObject* get_cummax_structseq();
28
+ PyTypeObject* get_cummax_out_structseq();
29
+ PyTypeObject* get_cummin_structseq();
30
+ PyTypeObject* get_cummin_out_structseq();
31
+ PyTypeObject* get_frexp_structseq();
32
+ PyTypeObject* get_frexp_out_structseq();
33
+ PyTypeObject* get_geqrf_out_structseq();
34
+ PyTypeObject* get_geqrf_structseq();
35
+ PyTypeObject* get_histogram_out_structseq();
36
+ PyTypeObject* get_histogram_structseq();
37
+ PyTypeObject* get_histogramdd_structseq();
38
+ PyTypeObject* get_kthvalue_structseq();
39
+ PyTypeObject* get_kthvalue_out_structseq();
40
+ PyTypeObject* get_linalg_cholesky_ex_structseq();
41
+ PyTypeObject* get_linalg_cholesky_ex_out_structseq();
42
+ PyTypeObject* get_linalg_eig_structseq();
43
+ PyTypeObject* get_linalg_eig_out_structseq();
44
+ PyTypeObject* get_linalg_eigh_structseq();
45
+ PyTypeObject* get_linalg_eigh_out_structseq();
46
+ PyTypeObject* get_linalg_inv_ex_structseq();
47
+ PyTypeObject* get_linalg_inv_ex_out_structseq();
48
+ PyTypeObject* get_linalg_ldl_factor_structseq();
49
+ PyTypeObject* get_linalg_ldl_factor_out_structseq();
50
+ PyTypeObject* get_linalg_ldl_factor_ex_structseq();
51
+ PyTypeObject* get_linalg_ldl_factor_ex_out_structseq();
52
+ PyTypeObject* get_linalg_lstsq_structseq();
53
+ PyTypeObject* get_linalg_lstsq_out_structseq();
54
+ PyTypeObject* get_linalg_lu_structseq();
55
+ PyTypeObject* get_linalg_lu_out_structseq();
56
+ PyTypeObject* get_linalg_lu_factor_structseq();
57
+ PyTypeObject* get_linalg_lu_factor_out_structseq();
58
+ PyTypeObject* get_linalg_lu_factor_ex_structseq();
59
+ PyTypeObject* get_linalg_lu_factor_ex_out_structseq();
60
+ PyTypeObject* get_linalg_qr_structseq();
61
+ PyTypeObject* get_linalg_qr_out_structseq();
62
+ PyTypeObject* get_linalg_slogdet_structseq();
63
+ PyTypeObject* get_linalg_slogdet_out_structseq();
64
+ PyTypeObject* get_linalg_solve_ex_structseq();
65
+ PyTypeObject* get_linalg_solve_ex_out_structseq();
66
+ PyTypeObject* get_linalg_svd_structseq();
67
+ PyTypeObject* get_linalg_svd_out_structseq();
68
+ PyTypeObject* get_lu_unpack_structseq();
69
+ PyTypeObject* get_lu_unpack_out_structseq();
70
+ PyTypeObject* get_max_structseq();
71
+ PyTypeObject* get_max_out_structseq();
72
+ PyTypeObject* get_median_structseq();
73
+ PyTypeObject* get_median_out_structseq();
74
+ PyTypeObject* get_min_structseq();
75
+ PyTypeObject* get_min_out_structseq();
76
+ PyTypeObject* get_mode_structseq();
77
+ PyTypeObject* get_mode_out_structseq();
78
+ PyTypeObject* get_nanmedian_structseq();
79
+ PyTypeObject* get_nanmedian_out_structseq();
80
+ PyTypeObject* get_qr_out_structseq();
81
+ PyTypeObject* get_qr_structseq();
82
+ PyTypeObject* get_slogdet_structseq();
83
+ PyTypeObject* get_slogdet_out_structseq();
84
+ PyTypeObject* get_sort_out_structseq();
85
+ PyTypeObject* get_sort_structseq();
86
+ PyTypeObject* get_svd_out_structseq();
87
+ PyTypeObject* get_svd_structseq();
88
+ PyTypeObject* get_topk_out_structseq();
89
+ PyTypeObject* get_topk_structseq();
90
+ PyTypeObject* get_triangular_solve_out_structseq();
91
+ PyTypeObject* get_triangular_solve_structseq();
92
+
93
+ }
94
+
95
+ void initReturnTypes(PyObject* module);
96
+
97
+ } // namespace autograd
98
+ } // namespace torch
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/generated/variable_factories.h ADDED
@@ -0,0 +1,746 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // @generated from ../tools/autograd/templates/variable_factories.h
4
+
5
+ #include <ATen/core/Tensor.h>
6
+ #include <ATen/TracerMode.h>
7
+ #include <ATen/core/grad_mode.h>
8
+ #include <c10/util/ArrayRef.h>
9
+ #include <c10/core/MemoryFormat.h>
10
+ #include <torch/csrc/api/include/torch/detail/TensorDataContainer.h>
11
+ #include <torch/csrc/autograd/variable.h>
12
+
13
+ #ifndef AT_PER_OPERATOR_HEADERS
14
+ #include <ATen/Functions.h>
15
+ #else
16
+ #include <ATen/ops/from_blob.h>
17
+ #include <ATen/ops/_make_dep_token.h>
18
+ #include <ATen/ops/_cudnn_init_dropout_state.h>
19
+ #include <ATen/ops/arange.h>
20
+ #include <ATen/ops/arange.h>
21
+ #include <ATen/ops/arange.h>
22
+ #include <ATen/ops/bartlett_window.h>
23
+ #include <ATen/ops/bartlett_window.h>
24
+ #include <ATen/ops/blackman_window.h>
25
+ #include <ATen/ops/blackman_window.h>
26
+ #include <ATen/ops/empty.h>
27
+ #include <ATen/ops/empty.h>
28
+ #include <ATen/ops/empty_permuted.h>
29
+ #include <ATen/ops/_empty_affine_quantized.h>
30
+ #include <ATen/ops/_empty_per_channel_affine_quantized.h>
31
+ #include <ATen/ops/empty_quantized.h>
32
+ #include <ATen/ops/empty_like.h>
33
+ #include <ATen/ops/empty_strided.h>
34
+ #include <ATen/ops/eye.h>
35
+ #include <ATen/ops/eye.h>
36
+ #include <ATen/ops/full.h>
37
+ #include <ATen/ops/full.h>
38
+ #include <ATen/ops/full_like.h>
39
+ #include <ATen/ops/from_file.h>
40
+ #include <ATen/ops/hann_window.h>
41
+ #include <ATen/ops/hann_window.h>
42
+ #include <ATen/ops/hamming_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/kaiser_window.h>
47
+ #include <ATen/ops/kaiser_window.h>
48
+ #include <ATen/ops/kaiser_window.h>
49
+ #include <ATen/ops/linspace.h>
50
+ #include <ATen/ops/linspace.h>
51
+ #include <ATen/ops/linspace.h>
52
+ #include <ATen/ops/linspace.h>
53
+ #include <ATen/ops/logspace.h>
54
+ #include <ATen/ops/logspace.h>
55
+ #include <ATen/ops/logspace.h>
56
+ #include <ATen/ops/logspace.h>
57
+ #include <ATen/ops/ones.h>
58
+ #include <ATen/ops/ones.h>
59
+ #include <ATen/ops/ones_like.h>
60
+ #include <ATen/ops/scalar_tensor.h>
61
+ #include <ATen/ops/rand.h>
62
+ #include <ATen/ops/rand.h>
63
+ #include <ATen/ops/rand.h>
64
+ #include <ATen/ops/rand.h>
65
+ #include <ATen/ops/rand_like.h>
66
+ #include <ATen/ops/randint.h>
67
+ #include <ATen/ops/randint.h>
68
+ #include <ATen/ops/randint.h>
69
+ #include <ATen/ops/randint.h>
70
+ #include <ATen/ops/randint_like.h>
71
+ #include <ATen/ops/randint_like.h>
72
+ #include <ATen/ops/randint_like.h>
73
+ #include <ATen/ops/randn.h>
74
+ #include <ATen/ops/randn.h>
75
+ #include <ATen/ops/randn.h>
76
+ #include <ATen/ops/randn.h>
77
+ #include <ATen/ops/randn_like.h>
78
+ #include <ATen/ops/randperm.h>
79
+ #include <ATen/ops/randperm.h>
80
+ #include <ATen/ops/range.h>
81
+ #include <ATen/ops/range.h>
82
+ #include <ATen/ops/zeros.h>
83
+ #include <ATen/ops/_efficientzerotensor.h>
84
+ #include <ATen/ops/zeros.h>
85
+ #include <ATen/ops/zeros_like.h>
86
+ #include <ATen/ops/_sparse_compressed_tensor_with_dims.h>
87
+ #include <ATen/ops/sparse_compressed_tensor.h>
88
+ #include <ATen/ops/sparse_csr_tensor.h>
89
+ #include <ATen/ops/sparse_csc_tensor.h>
90
+ #include <ATen/ops/sparse_bsr_tensor.h>
91
+ #include <ATen/ops/sparse_bsc_tensor.h>
92
+ #include <ATen/ops/sparse_compressed_tensor.h>
93
+ #include <ATen/ops/sparse_csr_tensor.h>
94
+ #include <ATen/ops/sparse_csc_tensor.h>
95
+ #include <ATen/ops/sparse_bsr_tensor.h>
96
+ #include <ATen/ops/sparse_bsc_tensor.h>
97
+ #include <ATen/ops/_sparse_compressed_tensor_unsafe.h>
98
+ #include <ATen/ops/_sparse_csr_tensor_unsafe.h>
99
+ #include <ATen/ops/_sparse_csc_tensor_unsafe.h>
100
+ #include <ATen/ops/_sparse_bsr_tensor_unsafe.h>
101
+ #include <ATen/ops/_sparse_bsc_tensor_unsafe.h>
102
+ #include <ATen/ops/sparse_coo_tensor.h>
103
+ #include <ATen/ops/sparse_coo_tensor.h>
104
+ #include <ATen/ops/sparse_coo_tensor.h>
105
+ #include <ATen/ops/_sparse_coo_tensor_unsafe.h>
106
+ #include <ATen/ops/_sparse_coo_tensor_with_dims.h>
107
+ #include <ATen/ops/_sparse_coo_tensor_with_dims_and_tensors.h>
108
+ #include <ATen/ops/_to_copy.h>
109
+ #include <ATen/ops/tril_indices.h>
110
+ #include <ATen/ops/triu_indices.h>
111
+ #include <ATen/ops/normal.h>
112
+ #include <ATen/ops/fft_fftfreq.h>
113
+ #include <ATen/ops/fft_rfftfreq.h>
114
+ #endif
115
+
116
+ #include <functional>
117
+ #include <initializer_list>
118
+ #include <utility>
119
+
120
+ namespace torch {
121
+
122
+ /// NOTE: Currently `torch::tensor(...)` doesn't support mixed data types
123
+ /// (i.e. `torch::tensor({{bool, 2.0}})` doesn't work). We might be able to
124
+ /// support it in the future by iterating over all sub-lists to find
125
+ /// the largest data type that can represent all of the elements, or by using
126
+ /// variadic templates.
127
+ ///
128
+ /// NOTE: C++ `torch::tensor` with a floating-point type or an `at::ArrayRef` / `std::vector` /
129
+ /// (nested) braced-init-list of floating-point types always produces a tensor of dtype
130
+ /// `torch::get_default_dtype()`, matching Python `torch.tensor` behavior.
131
+ ///
132
+ /// NOTE: C++ `torch::tensor` with an integer type or an `at::ArrayRef` / `std::vector` /
133
+ /// (nested) braced-init-list of integer types always produces a tensor of dtype `at::kLong`
134
+ /// (aka. int64_t), matching Python `torch.tensor` behavior.
135
+ ///
136
+ /// NOTE: The following dtypes are not supported by `torch::tensor` currently:
137
+ /// - `unsigned int`
138
+ /// - `unsigned long int`
139
+ /// - `unsigned long long int`
140
+ /// - `long long int`
141
+ inline at::Tensor tensor(detail::TensorDataContainer tensor_data_container, const at::TensorOptions& options = {}) {
142
+ return autograd::make_variable(
143
+ // note: we remove the requires_grad setting from the TensorOptions because
144
+ // it is ignored anyways (and we actually have an assertion that it isn't set
145
+ // which would fail otherwise). We handle requires_grad explicitly here
146
+ // instead of passing it through to the kernel.
147
+ tensor_data_container.convert_to_tensor(options.requires_grad(::std::nullopt)),
148
+ options.requires_grad());
149
+ }
150
+
151
+ /// A generic deleter function.
152
+ using Deleter = std::function<void(void*)>;
153
+ using at::MemoryFormat;
154
+
155
+ /// Exposes the given `data` as a `Tensor` without taking ownership of the
156
+ /// original data. `sizes` should specify the shape of the tensor, `strides` the
157
+ /// stride in each dimension. The `deleter` function (a
158
+ /// `std::function<void(void*)>`) will be called on the `data` when the Tensor
159
+ /// data would normally be deallocated. The `TensorOptions` specify additional
160
+ /// configuration options for the returned tensor, such as what type to
161
+ /// interpret the `data` as.
162
+ inline at::Tensor from_blob(
163
+ void* data,
164
+ at::IntArrayRef sizes,
165
+ at::IntArrayRef strides,
166
+ const Deleter& deleter,
167
+ const at::TensorOptions& options = at::TensorOptions()) {
168
+ at::Tensor tensor = ([&]() {
169
+ at::AutoDispatchBelowAutograd guard; // TODO: remove
170
+ at::tracer::impl::NoTracerDispatchMode tracer_guard;
171
+ return at::from_blob(data, sizes, strides, deleter, options.requires_grad(::std::nullopt));
172
+ })();
173
+ return autograd::make_variable(tensor, options.requires_grad());
174
+ }
175
+
176
+ /// Exposes the given `data` as a `Tensor` without taking ownership of the
177
+ /// original data. `sizes` should specify the shape of the tensor, `strides` the
178
+ /// stride in each dimension. The `TensorOptions`
179
+ /// specify additional configuration options for the returned tensor, such as
180
+ /// what type to interpret the `data` as.
181
+ inline at::Tensor from_blob(
182
+ void* data,
183
+ at::IntArrayRef sizes,
184
+ at::IntArrayRef strides,
185
+ const at::TensorOptions& options = at::TensorOptions()) {
186
+ at::Tensor tensor = ([&]() {
187
+ at::AutoDispatchBelowAutograd guard; // TODO: remove
188
+ at::tracer::impl::NoTracerDispatchMode tracer_guard;
189
+ return at::from_blob(data, sizes, strides, options.requires_grad(::std::nullopt));
190
+ })();
191
+ return autograd::make_variable(tensor, options.requires_grad());
192
+ }
193
+
194
+ /// Exposes the given `data` as a `Tensor` without taking ownership of the
195
+ /// original data. `sizes` should specify the shape of the tensor. The `deleter`
196
+ /// (a `std::function<void(void*)>`) function will be called on the `data` when
197
+ /// the Tensor data would normally be deallocated. The `TensorOptions` specify
198
+ /// additional configuration options for the returned tensor, such as what type
199
+ /// to interpret the `data` as.
200
+ inline at::Tensor from_blob(
201
+ void* data,
202
+ at::IntArrayRef sizes,
203
+ const Deleter& deleter,
204
+ const at::TensorOptions& options = at::TensorOptions()) {
205
+ at::Tensor tensor = ([&]() {
206
+ at::AutoDispatchBelowAutograd guard; // TODO: remove
207
+ at::tracer::impl::NoTracerDispatchMode tracer_guard;
208
+ return at::from_blob(data, sizes, deleter, options.requires_grad(::std::nullopt));
209
+ })();
210
+ return autograd::make_variable(tensor, options.requires_grad());
211
+ }
212
+
213
+ /// Exposes the given `data` as a `Tensor` without taking ownership of the
214
+ /// original data. `sizes` should specify the shape of the tensor. The
215
+ /// `TensorOptions` specify additional configuration options for the returned
216
+ /// tensor, such as what type to interpret the `data` as.
217
+ inline at::Tensor from_blob(
218
+ void* data,
219
+ at::IntArrayRef sizes,
220
+ const at::TensorOptions& options = at::TensorOptions()) {
221
+ at::Tensor tensor = ([&]() {
222
+ at::AutoDispatchBelowAutograd guard; // TODO: remove
223
+ at::tracer::impl::NoTracerDispatchMode tracer_guard;
224
+ return at::from_blob(data, sizes, options.requires_grad(::std::nullopt));
225
+ })();
226
+ return autograd::make_variable(tensor, options.requires_grad());
227
+ }
228
+
229
+ inline at::Tensor _make_dep_token(at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
230
+ at::AutoDispatchBelowADInplaceOrView guard;
231
+ return autograd::make_variable(at::_make_dep_token(at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
232
+ }
233
+ inline at::Tensor _cudnn_init_dropout_state(double dropout, bool train, int64_t dropout_seed, at::TensorOptions options) {
234
+ at::AutoDispatchBelowADInplaceOrView guard;
235
+ 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());
236
+ }
237
+ inline at::Tensor arange(const at::Scalar & end, at::TensorOptions options = {}) {
238
+ at::AutoDispatchBelowADInplaceOrView guard;
239
+ return autograd::make_variable(at::arange(end, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
240
+ }
241
+ inline at::Tensor arange(const at::Scalar & start, const at::Scalar & end, at::TensorOptions options = {}) {
242
+ at::AutoDispatchBelowADInplaceOrView guard;
243
+ return autograd::make_variable(at::arange(start, end, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
244
+ }
245
+ inline at::Tensor arange(const at::Scalar & start, const at::Scalar & end, const at::Scalar & step, at::TensorOptions options = {}) {
246
+ at::AutoDispatchBelowADInplaceOrView guard;
247
+ return autograd::make_variable(at::arange(start, end, step, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
248
+ }
249
+ inline at::Tensor bartlett_window(int64_t window_length, at::TensorOptions options = {}) {
250
+ at::AutoDispatchBelowADInplaceOrView guard;
251
+ return autograd::make_variable(at::bartlett_window(window_length, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
252
+ }
253
+ inline at::Tensor bartlett_window(int64_t window_length, bool periodic, at::TensorOptions options = {}) {
254
+ at::AutoDispatchBelowADInplaceOrView guard;
255
+ return autograd::make_variable(at::bartlett_window(window_length, periodic, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
256
+ }
257
+ inline at::Tensor blackman_window(int64_t window_length, at::TensorOptions options = {}) {
258
+ at::AutoDispatchBelowADInplaceOrView guard;
259
+ return autograd::make_variable(at::blackman_window(window_length, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
260
+ }
261
+ inline at::Tensor blackman_window(int64_t window_length, bool periodic, at::TensorOptions options = {}) {
262
+ at::AutoDispatchBelowADInplaceOrView guard;
263
+ return autograd::make_variable(at::blackman_window(window_length, periodic, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
264
+ }
265
+ inline at::Tensor empty(at::IntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
266
+ at::AutoDispatchBelowADInplaceOrView guard;
267
+ return autograd::make_variable(at::empty(size, names, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
268
+ }
269
+ inline at::Tensor empty(at::IntArrayRef size, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
270
+ at::AutoDispatchBelowADInplaceOrView guard;
271
+ return autograd::make_variable(at::empty(size, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
272
+ }
273
+ inline at::Tensor empty_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
274
+ at::AutoDispatchBelowADInplaceOrView guard;
275
+ return autograd::make_variable(at::empty_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
276
+ }
277
+ inline at::Tensor empty_permuted(at::IntArrayRef size, at::IntArrayRef physical_layout, at::TensorOptions options = {}) {
278
+ at::AutoDispatchBelowADInplaceOrView guard;
279
+ return autograd::make_variable(at::empty_permuted(size, physical_layout, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
280
+ }
281
+ inline at::Tensor empty_permuted_symint(c10::SymIntArrayRef size, at::IntArrayRef physical_layout, at::TensorOptions options = {}) {
282
+ at::AutoDispatchBelowADInplaceOrView guard;
283
+ return autograd::make_variable(at::empty_permuted_symint(size, physical_layout, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
284
+ }
285
+ 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) {
286
+ at::AutoDispatchBelowADInplaceOrView guard;
287
+ 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());
288
+ }
289
+ 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) {
290
+ at::AutoDispatchBelowADInplaceOrView guard;
291
+ 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());
292
+ }
293
+ 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) {
294
+ at::AutoDispatchBelowADInplaceOrView guard;
295
+ 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());
296
+ }
297
+ 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) {
298
+ at::AutoDispatchBelowADInplaceOrView guard;
299
+ 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());
300
+ }
301
+ inline at::Tensor empty_quantized(at::IntArrayRef size, const at::Tensor & qtensor, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
302
+ at::AutoDispatchBelowADInplaceOrView guard;
303
+ return autograd::make_variable(at::empty_quantized(size, qtensor, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
304
+ }
305
+ inline at::Tensor empty_like(const at::Tensor & self, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
306
+ at::AutoDispatchBelowADInplaceOrView guard;
307
+ return autograd::make_variable(at::empty_like(self, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
308
+ }
309
+ inline at::Tensor empty_strided(at::IntArrayRef size, at::IntArrayRef stride, at::TensorOptions options = {}) {
310
+ at::AutoDispatchBelowADInplaceOrView guard;
311
+ return autograd::make_variable(at::empty_strided(size, stride, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
312
+ }
313
+ inline at::Tensor empty_strided_symint(c10::SymIntArrayRef size, c10::SymIntArrayRef stride, at::TensorOptions options = {}) {
314
+ at::AutoDispatchBelowADInplaceOrView guard;
315
+ return autograd::make_variable(at::empty_strided_symint(size, stride, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
316
+ }
317
+ inline at::Tensor eye(int64_t n, at::TensorOptions options = {}) {
318
+ at::AutoDispatchBelowADInplaceOrView guard;
319
+ return autograd::make_variable(at::eye(n, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
320
+ }
321
+ inline at::Tensor eye_symint(c10::SymInt n, at::TensorOptions options = {}) {
322
+ at::AutoDispatchBelowADInplaceOrView guard;
323
+ return autograd::make_variable(at::eye_symint(n, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
324
+ }
325
+ inline at::Tensor eye(int64_t n, int64_t m, at::TensorOptions options = {}) {
326
+ at::AutoDispatchBelowADInplaceOrView guard;
327
+ return autograd::make_variable(at::eye(n, m, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
328
+ }
329
+ inline at::Tensor eye_symint(c10::SymInt n, c10::SymInt m, at::TensorOptions options = {}) {
330
+ at::AutoDispatchBelowADInplaceOrView guard;
331
+ return autograd::make_variable(at::eye_symint(n, m, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
332
+ }
333
+ inline at::Tensor full(at::IntArrayRef size, const at::Scalar & fill_value, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
334
+ at::AutoDispatchBelowADInplaceOrView guard;
335
+ return autograd::make_variable(at::full(size, fill_value, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
336
+ }
337
+ inline at::Tensor full(at::IntArrayRef size, const at::Scalar & fill_value, at::TensorOptions options = {}) {
338
+ at::AutoDispatchBelowADInplaceOrView guard;
339
+ return autograd::make_variable(at::full(size, fill_value, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
340
+ }
341
+ inline at::Tensor full_symint(c10::SymIntArrayRef size, const at::Scalar & fill_value, at::TensorOptions options = {}) {
342
+ at::AutoDispatchBelowADInplaceOrView guard;
343
+ return autograd::make_variable(at::full_symint(size, fill_value, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
344
+ }
345
+ 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) {
346
+ at::AutoDispatchBelowADInplaceOrView guard;
347
+ return autograd::make_variable(at::full_like(self, fill_value, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
348
+ }
349
+ inline at::Tensor from_file(c10::string_view filename, ::std::optional<bool> shared = ::std::nullopt, ::std::optional<int64_t> size = 0, at::TensorOptions options = {}) {
350
+ at::AutoDispatchBelowADInplaceOrView guard;
351
+ return autograd::make_variable(at::from_file(filename, shared, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
352
+ }
353
+ inline at::Tensor hann_window(int64_t window_length, at::TensorOptions options = {}) {
354
+ at::AutoDispatchBelowADInplaceOrView guard;
355
+ return autograd::make_variable(at::hann_window(window_length, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
356
+ }
357
+ inline at::Tensor hann_window(int64_t window_length, bool periodic, at::TensorOptions options = {}) {
358
+ at::AutoDispatchBelowADInplaceOrView guard;
359
+ return autograd::make_variable(at::hann_window(window_length, periodic, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
360
+ }
361
+ inline at::Tensor hamming_window(int64_t window_length, at::TensorOptions options = {}) {
362
+ at::AutoDispatchBelowADInplaceOrView guard;
363
+ return autograd::make_variable(at::hamming_window(window_length, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
364
+ }
365
+ inline at::Tensor hamming_window(int64_t window_length, bool periodic, at::TensorOptions options = {}) {
366
+ at::AutoDispatchBelowADInplaceOrView guard;
367
+ return autograd::make_variable(at::hamming_window(window_length, periodic, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
368
+ }
369
+ inline at::Tensor hamming_window(int64_t window_length, bool periodic, double alpha, at::TensorOptions options = {}) {
370
+ at::AutoDispatchBelowADInplaceOrView guard;
371
+ return autograd::make_variable(at::hamming_window(window_length, periodic, alpha, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
372
+ }
373
+ inline at::Tensor hamming_window(int64_t window_length, bool periodic, double alpha, double beta, at::TensorOptions options = {}) {
374
+ at::AutoDispatchBelowADInplaceOrView guard;
375
+ return autograd::make_variable(at::hamming_window(window_length, periodic, alpha, beta, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
376
+ }
377
+ inline at::Tensor kaiser_window(int64_t window_length, at::TensorOptions options = {}) {
378
+ at::AutoDispatchBelowADInplaceOrView guard;
379
+ return autograd::make_variable(at::kaiser_window(window_length, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
380
+ }
381
+ inline at::Tensor kaiser_window(int64_t window_length, bool periodic, at::TensorOptions options = {}) {
382
+ at::AutoDispatchBelowADInplaceOrView guard;
383
+ return autograd::make_variable(at::kaiser_window(window_length, periodic, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
384
+ }
385
+ inline at::Tensor kaiser_window(int64_t window_length, bool periodic, double beta, at::TensorOptions options = {}) {
386
+ at::AutoDispatchBelowADInplaceOrView guard;
387
+ return autograd::make_variable(at::kaiser_window(window_length, periodic, beta, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
388
+ }
389
+ inline at::Tensor linspace(const at::Scalar & start, const at::Scalar & end, int64_t steps, at::TensorOptions options = {}) {
390
+ at::AutoDispatchBelowADInplaceOrView guard;
391
+ return autograd::make_variable(at::linspace(start, end, steps, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
392
+ }
393
+ inline at::Tensor linspace(const at::Tensor & start, const at::Tensor & end, int64_t steps, at::TensorOptions options = {}) {
394
+ at::AutoDispatchBelowADInplaceOrView guard;
395
+ return autograd::make_variable(at::linspace(start, end, steps, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
396
+ }
397
+ inline at::Tensor linspace(const at::Tensor & start, const at::Scalar & end, int64_t steps, at::TensorOptions options = {}) {
398
+ at::AutoDispatchBelowADInplaceOrView guard;
399
+ return autograd::make_variable(at::linspace(start, end, steps, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
400
+ }
401
+ inline at::Tensor linspace(const at::Scalar & start, const at::Tensor & end, int64_t steps, at::TensorOptions options = {}) {
402
+ at::AutoDispatchBelowADInplaceOrView guard;
403
+ return autograd::make_variable(at::linspace(start, end, steps, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
404
+ }
405
+ inline at::Tensor logspace(const at::Scalar & start, const at::Scalar & end, int64_t steps, double base = 10.0, at::TensorOptions options = {}) {
406
+ at::AutoDispatchBelowADInplaceOrView guard;
407
+ return autograd::make_variable(at::logspace(start, end, steps, base, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
408
+ }
409
+ inline at::Tensor logspace(const at::Tensor & start, const at::Tensor & end, int64_t steps, double base = 10.0, at::TensorOptions options = {}) {
410
+ at::AutoDispatchBelowADInplaceOrView guard;
411
+ return autograd::make_variable(at::logspace(start, end, steps, base, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
412
+ }
413
+ inline at::Tensor logspace(const at::Tensor & start, const at::Scalar & end, int64_t steps, double base = 10.0, at::TensorOptions options = {}) {
414
+ at::AutoDispatchBelowADInplaceOrView guard;
415
+ return autograd::make_variable(at::logspace(start, end, steps, base, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
416
+ }
417
+ inline at::Tensor logspace(const at::Scalar & start, const at::Tensor & end, int64_t steps, double base = 10.0, at::TensorOptions options = {}) {
418
+ at::AutoDispatchBelowADInplaceOrView guard;
419
+ return autograd::make_variable(at::logspace(start, end, steps, base, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
420
+ }
421
+ inline at::Tensor ones(at::IntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
422
+ at::AutoDispatchBelowADInplaceOrView guard;
423
+ return autograd::make_variable(at::ones(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
424
+ }
425
+ inline at::Tensor ones(at::IntArrayRef size, at::TensorOptions options = {}) {
426
+ at::AutoDispatchBelowADInplaceOrView guard;
427
+ return autograd::make_variable(at::ones(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
428
+ }
429
+ inline at::Tensor ones_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}) {
430
+ at::AutoDispatchBelowADInplaceOrView guard;
431
+ return autograd::make_variable(at::ones_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
432
+ }
433
+ inline at::Tensor ones_like(const at::Tensor & self, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
434
+ at::AutoDispatchBelowADInplaceOrView guard;
435
+ return autograd::make_variable(at::ones_like(self, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
436
+ }
437
+ inline at::Tensor scalar_tensor(const at::Scalar & s, at::TensorOptions options = {}) {
438
+ at::AutoDispatchBelowADInplaceOrView guard;
439
+ return autograd::make_variable(at::scalar_tensor(s, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
440
+ }
441
+ inline at::Tensor rand(at::IntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
442
+ at::AutoDispatchBelowADInplaceOrView guard;
443
+ return autograd::make_variable(at::rand(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
444
+ }
445
+ inline at::Tensor rand_symint(c10::SymIntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
446
+ at::AutoDispatchBelowADInplaceOrView guard;
447
+ return autograd::make_variable(at::rand_symint(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
448
+ }
449
+ inline at::Tensor rand(at::IntArrayRef size, ::std::optional<at::Generator> generator, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
450
+ at::AutoDispatchBelowADInplaceOrView guard;
451
+ return autograd::make_variable(at::rand(size, generator, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
452
+ }
453
+ inline at::Tensor rand_symint(c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
454
+ at::AutoDispatchBelowADInplaceOrView guard;
455
+ return autograd::make_variable(at::rand_symint(size, generator, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
456
+ }
457
+ inline at::Tensor rand(at::IntArrayRef size, at::TensorOptions options = {}) {
458
+ at::AutoDispatchBelowADInplaceOrView guard;
459
+ return autograd::make_variable(at::rand(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
460
+ }
461
+ inline at::Tensor rand_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}) {
462
+ at::AutoDispatchBelowADInplaceOrView guard;
463
+ return autograd::make_variable(at::rand_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
464
+ }
465
+ inline at::Tensor rand(at::IntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = {}) {
466
+ at::AutoDispatchBelowADInplaceOrView guard;
467
+ return autograd::make_variable(at::rand(size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
468
+ }
469
+ inline at::Tensor rand_symint(c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = {}) {
470
+ at::AutoDispatchBelowADInplaceOrView guard;
471
+ return autograd::make_variable(at::rand_symint(size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
472
+ }
473
+ inline at::Tensor rand_like(const at::Tensor & self, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
474
+ at::AutoDispatchBelowADInplaceOrView guard;
475
+ return autograd::make_variable(at::rand_like(self, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
476
+ }
477
+ inline at::Tensor randint(int64_t high, at::IntArrayRef size, at::TensorOptions options = at::kLong) {
478
+ at::AutoDispatchBelowADInplaceOrView guard;
479
+ return autograd::make_variable(at::randint(high, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
480
+ }
481
+ inline at::Tensor randint_symint(c10::SymInt high, c10::SymIntArrayRef size, at::TensorOptions options = at::kLong) {
482
+ at::AutoDispatchBelowADInplaceOrView guard;
483
+ return autograd::make_variable(at::randint_symint(high, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
484
+ }
485
+ inline at::Tensor randint(int64_t high, at::IntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
486
+ at::AutoDispatchBelowADInplaceOrView guard;
487
+ return autograd::make_variable(at::randint(high, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
488
+ }
489
+ inline at::Tensor randint_symint(c10::SymInt high, c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
490
+ at::AutoDispatchBelowADInplaceOrView guard;
491
+ return autograd::make_variable(at::randint_symint(high, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
492
+ }
493
+ inline at::Tensor randint(int64_t low, int64_t high, at::IntArrayRef size, at::TensorOptions options = at::kLong) {
494
+ at::AutoDispatchBelowADInplaceOrView guard;
495
+ return autograd::make_variable(at::randint(low, high, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
496
+ }
497
+ inline at::Tensor randint_symint(c10::SymInt low, c10::SymInt high, c10::SymIntArrayRef size, at::TensorOptions options = at::kLong) {
498
+ at::AutoDispatchBelowADInplaceOrView guard;
499
+ return autograd::make_variable(at::randint_symint(low, high, size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
500
+ }
501
+ inline at::Tensor randint(int64_t low, int64_t high, at::IntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
502
+ at::AutoDispatchBelowADInplaceOrView guard;
503
+ return autograd::make_variable(at::randint(low, high, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
504
+ }
505
+ inline at::Tensor randint_symint(c10::SymInt low, c10::SymInt high, c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
506
+ at::AutoDispatchBelowADInplaceOrView guard;
507
+ return autograd::make_variable(at::randint_symint(low, high, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
508
+ }
509
+ inline at::Tensor randint_like(const at::Tensor & self, int64_t high, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
510
+ at::AutoDispatchBelowADInplaceOrView guard;
511
+ return autograd::make_variable(at::randint_like(self, high, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
512
+ }
513
+ inline at::Tensor randint_like_symint(const at::Tensor & self, c10::SymInt high, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
514
+ at::AutoDispatchBelowADInplaceOrView guard;
515
+ return autograd::make_variable(at::randint_like_symint(self, high, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
516
+ }
517
+ inline at::Tensor randint_like(const at::Tensor & self, const at::Tensor & high, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
518
+ at::AutoDispatchBelowADInplaceOrView guard;
519
+ return autograd::make_variable(at::randint_like(self, high, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
520
+ }
521
+ 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) {
522
+ at::AutoDispatchBelowADInplaceOrView guard;
523
+ return autograd::make_variable(at::randint_like(self, low, high, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
524
+ }
525
+ 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) {
526
+ at::AutoDispatchBelowADInplaceOrView guard;
527
+ 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());
528
+ }
529
+ inline at::Tensor randn(at::IntArrayRef size, at::TensorOptions options = {}) {
530
+ at::AutoDispatchBelowADInplaceOrView guard;
531
+ return autograd::make_variable(at::randn(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
532
+ }
533
+ inline at::Tensor randn_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}) {
534
+ at::AutoDispatchBelowADInplaceOrView guard;
535
+ return autograd::make_variable(at::randn_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
536
+ }
537
+ inline at::Tensor randn(at::IntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = {}) {
538
+ at::AutoDispatchBelowADInplaceOrView guard;
539
+ return autograd::make_variable(at::randn(size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
540
+ }
541
+ inline at::Tensor randn_symint(c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, at::TensorOptions options = {}) {
542
+ at::AutoDispatchBelowADInplaceOrView guard;
543
+ return autograd::make_variable(at::randn_symint(size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
544
+ }
545
+ inline at::Tensor randn(at::IntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
546
+ at::AutoDispatchBelowADInplaceOrView guard;
547
+ return autograd::make_variable(at::randn(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
548
+ }
549
+ inline at::Tensor randn_symint(c10::SymIntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
550
+ at::AutoDispatchBelowADInplaceOrView guard;
551
+ return autograd::make_variable(at::randn_symint(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
552
+ }
553
+ inline at::Tensor randn(at::IntArrayRef size, ::std::optional<at::Generator> generator, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
554
+ at::AutoDispatchBelowADInplaceOrView guard;
555
+ return autograd::make_variable(at::randn(size, generator, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
556
+ }
557
+ inline at::Tensor randn_symint(c10::SymIntArrayRef size, ::std::optional<at::Generator> generator, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
558
+ at::AutoDispatchBelowADInplaceOrView guard;
559
+ return autograd::make_variable(at::randn_symint(size, generator, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
560
+ }
561
+ inline at::Tensor randn_like(const at::Tensor & self, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
562
+ at::AutoDispatchBelowADInplaceOrView guard;
563
+ return autograd::make_variable(at::randn_like(self, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
564
+ }
565
+ inline at::Tensor randperm(int64_t n, at::TensorOptions options = at::kLong) {
566
+ at::AutoDispatchBelowADInplaceOrView guard;
567
+ return autograd::make_variable(at::randperm(n, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
568
+ }
569
+ inline at::Tensor randperm_symint(c10::SymInt n, at::TensorOptions options = at::kLong) {
570
+ at::AutoDispatchBelowADInplaceOrView guard;
571
+ return autograd::make_variable(at::randperm_symint(n, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
572
+ }
573
+ inline at::Tensor randperm(int64_t n, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
574
+ at::AutoDispatchBelowADInplaceOrView guard;
575
+ return autograd::make_variable(at::randperm(n, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
576
+ }
577
+ inline at::Tensor randperm_symint(c10::SymInt n, ::std::optional<at::Generator> generator, at::TensorOptions options = at::kLong) {
578
+ at::AutoDispatchBelowADInplaceOrView guard;
579
+ return autograd::make_variable(at::randperm_symint(n, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
580
+ }
581
+ inline at::Tensor range(const at::Scalar & start, const at::Scalar & end, const at::Scalar & step = 1, at::TensorOptions options = {}) {
582
+ at::AutoDispatchBelowADInplaceOrView guard;
583
+ return autograd::make_variable(at::range(start, end, step, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
584
+ }
585
+ inline at::Tensor range(const at::Scalar & start, const at::Scalar & end, at::TensorOptions options = {}) {
586
+ at::AutoDispatchBelowADInplaceOrView guard;
587
+ return autograd::make_variable(at::range(start, end, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
588
+ }
589
+ inline at::Tensor zeros(at::IntArrayRef size, ::std::optional<at::DimnameList> names, at::TensorOptions options = {}) {
590
+ at::AutoDispatchBelowADInplaceOrView guard;
591
+ return autograd::make_variable(at::zeros(size, names, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
592
+ }
593
+ inline at::Tensor _efficientzerotensor(at::IntArrayRef size, at::TensorOptions options = {}) {
594
+ at::AutoDispatchBelowADInplaceOrView guard;
595
+ return autograd::make_variable(at::_efficientzerotensor(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
596
+ }
597
+ inline at::Tensor _efficientzerotensor_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}) {
598
+ at::AutoDispatchBelowADInplaceOrView guard;
599
+ return autograd::make_variable(at::_efficientzerotensor_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
600
+ }
601
+ inline at::Tensor zeros(at::IntArrayRef size, at::TensorOptions options = {}) {
602
+ at::AutoDispatchBelowADInplaceOrView guard;
603
+ return autograd::make_variable(at::zeros(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
604
+ }
605
+ inline at::Tensor zeros_symint(c10::SymIntArrayRef size, at::TensorOptions options = {}) {
606
+ at::AutoDispatchBelowADInplaceOrView guard;
607
+ return autograd::make_variable(at::zeros_symint(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
608
+ }
609
+ inline at::Tensor zeros_like(const at::Tensor & self, at::TensorOptions options = {}, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
610
+ at::AutoDispatchBelowADInplaceOrView guard;
611
+ return autograd::make_variable(at::zeros_like(self, at::TensorOptions(options).requires_grad(::std::nullopt), memory_format), /*requires_grad=*/options.requires_grad());
612
+ }
613
+ 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) {
614
+ at::AutoDispatchBelowADInplaceOrView guard;
615
+ 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());
616
+ }
617
+ 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) {
618
+ at::AutoDispatchBelowADInplaceOrView guard;
619
+ 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());
620
+ }
621
+ 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) {
622
+ at::AutoDispatchBelowADInplaceOrView guard;
623
+ 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());
624
+ }
625
+ 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) {
626
+ at::AutoDispatchBelowADInplaceOrView guard;
627
+ 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());
628
+ }
629
+ 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) {
630
+ at::AutoDispatchBelowADInplaceOrView guard;
631
+ 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());
632
+ }
633
+ 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) {
634
+ at::AutoDispatchBelowADInplaceOrView guard;
635
+ 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());
636
+ }
637
+ 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) {
638
+ at::AutoDispatchBelowADInplaceOrView guard;
639
+ 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());
640
+ }
641
+ inline at::Tensor sparse_compressed_tensor(const at::Tensor & compressed_indices, const at::Tensor & plain_indices, const at::Tensor & values, at::TensorOptions options) {
642
+ at::AutoDispatchBelowADInplaceOrView guard;
643
+ 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());
644
+ }
645
+ inline at::Tensor sparse_csr_tensor(const at::Tensor & crow_indices, const at::Tensor & col_indices, const at::Tensor & values, at::TensorOptions options) {
646
+ at::AutoDispatchBelowADInplaceOrView guard;
647
+ 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());
648
+ }
649
+ inline at::Tensor sparse_csc_tensor(const at::Tensor & ccol_indices, const at::Tensor & row_indices, const at::Tensor & values, at::TensorOptions options) {
650
+ at::AutoDispatchBelowADInplaceOrView guard;
651
+ 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());
652
+ }
653
+ inline at::Tensor sparse_bsr_tensor(const at::Tensor & crow_indices, const at::Tensor & col_indices, const at::Tensor & values, at::TensorOptions options) {
654
+ at::AutoDispatchBelowADInplaceOrView guard;
655
+ 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());
656
+ }
657
+ inline at::Tensor sparse_bsc_tensor(const at::Tensor & ccol_indices, const at::Tensor & row_indices, const at::Tensor & values, at::TensorOptions options) {
658
+ at::AutoDispatchBelowADInplaceOrView guard;
659
+ 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());
660
+ }
661
+ 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 = {}) {
662
+ at::AutoDispatchBelowADInplaceOrView guard;
663
+ 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());
664
+ }
665
+ 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 = {}) {
666
+ at::AutoDispatchBelowADInplaceOrView guard;
667
+ 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());
668
+ }
669
+ 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 = {}) {
670
+ at::AutoDispatchBelowADInplaceOrView guard;
671
+ 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());
672
+ }
673
+ 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 = {}) {
674
+ at::AutoDispatchBelowADInplaceOrView guard;
675
+ 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());
676
+ }
677
+ 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 = {}) {
678
+ at::AutoDispatchBelowADInplaceOrView guard;
679
+ 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());
680
+ }
681
+ 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 = {}) {
682
+ at::AutoDispatchBelowADInplaceOrView guard;
683
+ 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());
684
+ }
685
+ inline at::Tensor sparse_coo_tensor(at::IntArrayRef size, at::TensorOptions options) {
686
+ at::AutoDispatchBelowADInplaceOrView guard;
687
+ return autograd::make_variable(at::sparse_coo_tensor(size, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
688
+ }
689
+ inline at::Tensor sparse_coo_tensor(const at::Tensor & indices, const at::Tensor & values, at::TensorOptions options = {}, ::std::optional<bool> is_coalesced = ::std::nullopt) {
690
+ at::AutoDispatchBelowADInplaceOrView guard;
691
+ return autograd::make_variable(at::sparse_coo_tensor(indices, values, at::TensorOptions(options).requires_grad(::std::nullopt), is_coalesced), /*requires_grad=*/options.requires_grad());
692
+ }
693
+ 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) {
694
+ at::AutoDispatchBelowADInplaceOrView guard;
695
+ 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());
696
+ }
697
+ 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) {
698
+ at::AutoDispatchBelowADInplaceOrView guard;
699
+ 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());
700
+ }
701
+ 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) {
702
+ at::AutoDispatchBelowADInplaceOrView guard;
703
+ 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());
704
+ }
705
+ inline at::Tensor _sparse_coo_tensor_with_dims(int64_t sparse_dim, int64_t dense_dim, at::IntArrayRef size, at::TensorOptions options) {
706
+ at::AutoDispatchBelowADInplaceOrView guard;
707
+ 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());
708
+ }
709
+ 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) {
710
+ at::AutoDispatchBelowADInplaceOrView guard;
711
+ 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());
712
+ }
713
+ 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) {
714
+ at::AutoDispatchBelowADInplaceOrView guard;
715
+ 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());
716
+ }
717
+ inline at::Tensor _to_copy(const at::Tensor & self, at::TensorOptions options = {}, bool non_blocking = false, ::std::optional<at::MemoryFormat> memory_format = ::std::nullopt) {
718
+ at::AutoDispatchBelowADInplaceOrView guard;
719
+ return autograd::make_variable(at::_to_copy(self, at::TensorOptions(options).requires_grad(::std::nullopt), non_blocking, memory_format), /*requires_grad=*/options.requires_grad());
720
+ }
721
+ inline at::Tensor tril_indices(int64_t row, int64_t col, int64_t offset = 0, at::TensorOptions options = at::kLong) {
722
+ at::AutoDispatchBelowADInplaceOrView guard;
723
+ return autograd::make_variable(at::tril_indices(row, col, offset, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
724
+ }
725
+ inline at::Tensor triu_indices(int64_t row, int64_t col, int64_t offset = 0, at::TensorOptions options = at::kLong) {
726
+ at::AutoDispatchBelowADInplaceOrView guard;
727
+ return autograd::make_variable(at::triu_indices(row, col, offset, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
728
+ }
729
+ inline at::Tensor normal(double mean, double std, at::IntArrayRef size, ::std::optional<at::Generator> generator = ::std::nullopt, at::TensorOptions options = {}) {
730
+ at::AutoDispatchBelowADInplaceOrView guard;
731
+ return autograd::make_variable(at::normal(mean, std, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
732
+ }
733
+ inline at::Tensor normal_symint(double mean, double std, c10::SymIntArrayRef size, ::std::optional<at::Generator> generator = ::std::nullopt, at::TensorOptions options = {}) {
734
+ at::AutoDispatchBelowADInplaceOrView guard;
735
+ return autograd::make_variable(at::normal_symint(mean, std, size, generator, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
736
+ }
737
+ inline at::Tensor fft_fftfreq(int64_t n, double d = 1.0, at::TensorOptions options = {}) {
738
+ at::AutoDispatchBelowADInplaceOrView guard;
739
+ return autograd::make_variable(at::fft_fftfreq(n, d, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
740
+ }
741
+ inline at::Tensor fft_rfftfreq(int64_t n, double d = 1.0, at::TensorOptions options = {}) {
742
+ at::AutoDispatchBelowADInplaceOrView guard;
743
+ return autograd::make_variable(at::fft_rfftfreq(n, d, at::TensorOptions(options).requires_grad(::std::nullopt)), /*requires_grad=*/options.requires_grad());
744
+ }
745
+
746
+ } // namespace torch
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/error_messages.h ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <sstream>
4
+
5
+ namespace torch::autograd::utils {
6
+
7
+ inline std::string requires_grad_leaf_error(bool requires_grad) {
8
+ std::ostringstream oss;
9
+ oss << "you can only change requires_grad flags of leaf variables.";
10
+ if (requires_grad == false) {
11
+ oss << " If you want to use a computed variable in a subgraph "
12
+ "that doesn't require differentiation use "
13
+ "var_no_grad = var.detach().";
14
+ }
15
+ return oss.str();
16
+ }
17
+
18
+ } // namespace torch::autograd::utils
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/grad_layout_contract.h ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/Tensor.h>
4
+
5
+ namespace torch::autograd::utils {
6
+
7
+ // Helper functions to enforce the "Gradient Layout Contract" described in
8
+ // torch/csrc/autograd/functions/accumulate_grad.h.
9
+
10
+ // Checks if grad obeys the contract with variable.
11
+ inline bool obeys_layout_contract(
12
+ const at::Tensor& grad,
13
+ const at::Tensor& variable) {
14
+ TORCH_INTERNAL_ASSERT(!grad.is_sparse());
15
+ TORCH_INTERNAL_ASSERT(!grad.is_sparse_csr());
16
+ TORCH_INTERNAL_ASSERT(!variable.is_sparse_csr());
17
+
18
+ // NOLINTNEXTLINE(bugprone-branch-clone)
19
+ if (variable.is_nested()) {
20
+ // TODO: Nested Tensor does not have an implementation of detach. The
21
+ // current implementation of nested tensor likely does obey the gradient
22
+ // contract and should return true, but this would likely change in the
23
+ // future
24
+ return false;
25
+ } else if (variable.is_sparse()) {
26
+ // Gradient Layout Contract is not applicable for sparse layouts
27
+ return false;
28
+ } else if (variable.is_non_overlapping_and_dense()) {
29
+ // Only look at stride for dimensions that are not of size 1.
30
+ const auto& grad_sizes = grad.sym_sizes();
31
+ const auto& grad_strides = grad.sym_strides();
32
+ const auto& variable_strides = variable.sym_strides();
33
+ for (const auto idx : c10::irange(grad_sizes.size())) {
34
+ if (grad_sizes[idx] != 1) {
35
+ if (grad_strides[idx] != variable_strides[idx]) {
36
+ return false;
37
+ }
38
+ } else {
39
+ // This should not be needed but we don't check if a Tensor has views
40
+ // before stashing it. And 0-strided Tensors of size 1 are actually
41
+ // views for ops like cat.
42
+ // TODO: Actually detect views in the accumulateGrad function so that
43
+ // this Tensor is not considered at all.
44
+ if (grad_strides[idx] == 0) {
45
+ return false;
46
+ }
47
+ }
48
+ }
49
+ return true;
50
+ } else {
51
+ return grad.is_contiguous(at::MemoryFormat::Contiguous);
52
+ }
53
+ }
54
+
55
+ // Creates a clone of new_grad that obeys the contract with variable.
56
+ // The clone should attach to new_grad's history if GradMode::is_enabled().
57
+ inline at::Tensor clone_obey_contract(
58
+ const at::Tensor& new_grad,
59
+ const at::Tensor& variable) {
60
+ if (variable.is_non_overlapping_and_dense()) {
61
+ // (1)
62
+ // Does this dicey-looking sequence attach the result to new_grad's
63
+ // history if GradMode::is_enabled()? Yes, and @alband says it should.
64
+ return std::move(new_grad
65
+ .new_empty_strided_symint(
66
+ variable.sym_sizes(),
67
+ variable.sym_strides(),
68
+ variable.options().memory_format(std::nullopt))
69
+ .copy_(new_grad));
70
+ } else {
71
+ // (2)
72
+ return new_grad.clone(at::MemoryFormat::Contiguous);
73
+ }
74
+ }
75
+
76
+ } // namespace torch::autograd::utils
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/lambda_post_hook.h ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/autograd/function_hook.h>
4
+ #include <torch/csrc/dynamo/compiled_autograd.h>
5
+
6
+ namespace torch::autograd::utils {
7
+
8
+ // Turns lambda into a torch::autograd::FunctionPostHook.
9
+ class LambdaPostHook : public torch::autograd::FunctionPostHook {
10
+ using variable_list = std::vector<torch::autograd::Variable>;
11
+ using fn_type =
12
+ std::function<variable_list(const variable_list&, const variable_list&)>;
13
+ using compiled_fn_type = std::function<void(CompiledNodeArgs&)>;
14
+
15
+ public:
16
+ // The lambda function takes as arguments the outputs and inputs of the
17
+ // autograd function and can modify the outputs of the autograd function by
18
+ // returning a new output if needed.
19
+ /* implicit */ LambdaPostHook(fn_type fn) : fn_(std::move(fn)) {}
20
+
21
+ LambdaPostHook(fn_type fn, compiled_fn_type compiled_fn)
22
+ : fn_(std::move(fn)), compiled_fn_(std::move(compiled_fn)) {}
23
+
24
+ variable_list operator()(
25
+ const variable_list& outputs,
26
+ const variable_list& inputs) override {
27
+ return fn_(outputs, inputs);
28
+ }
29
+
30
+ void compiled_args(CompiledNodeArgs& args) const override {
31
+ if (compiled_fn_ != nullptr) {
32
+ return compiled_fn_(args);
33
+ }
34
+ return FunctionPostHook::compiled_args(args);
35
+ }
36
+
37
+ protected:
38
+ std::function<variable_list(const variable_list&, const variable_list&)> fn_;
39
+ compiled_fn_type compiled_fn_{};
40
+ };
41
+
42
+ } // namespace torch::autograd::utils
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/python_arg_parsing.h ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/core/Tensor.h>
4
+ #include <torch/csrc/python_headers.h>
5
+
6
+ #include <torch/csrc/utils/python_arg_parser.h>
7
+
8
+ namespace torch::autograd::utils {
9
+
10
+ // The parameter allow_copy is to accept copy for Tensor.to (and by proxy
11
+ // PackedSequences.to) but not nn.Module.to.
12
+ inline std::tuple<
13
+ std::optional<at::Device>,
14
+ std::optional<at::ScalarType>,
15
+ bool,
16
+ bool,
17
+ std::optional<at::MemoryFormat>>
18
+ parse_to_conversion(PythonArgs& r, bool allow_copy) {
19
+ if (r.idx == 0) {
20
+ if (!allow_copy && !r.isNone(3))
21
+ throw std::runtime_error(".to() does not accept copy argument");
22
+ return std::make_tuple(
23
+ r.deviceOptional(0),
24
+ r.scalartypeOptional(1),
25
+ r.toBool(2),
26
+ r.toBool(3),
27
+ r.memoryformatOptional(4));
28
+ } else if (r.idx == 1) {
29
+ if (!allow_copy && !r.isNone(2))
30
+ throw std::runtime_error(".to() does not accept copy argument");
31
+ return std::make_tuple(
32
+ std::nullopt,
33
+ r.scalartype(0),
34
+ r.toBool(1),
35
+ r.toBool(2),
36
+ r.memoryformatOptional(3));
37
+ } else {
38
+ auto tensor = r.tensor(0);
39
+ if (!allow_copy && !r.isNone(2))
40
+ throw std::runtime_error(".to() does not accept copy argument");
41
+ return std::make_tuple(
42
+ tensor.device(),
43
+ tensor.scalar_type(),
44
+ r.toBool(1),
45
+ r.toBool(2),
46
+ r.memoryformatOptional(3));
47
+ }
48
+ }
49
+ } // namespace torch::autograd::utils
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/warnings.h ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #include <c10/util/Exception.h>
3
+
4
+ #include <mutex>
5
+ #include <vector>
6
+
7
+ namespace torch::autograd::utils {
8
+
9
+ // Warning handler for multi-threaded contexts. Gather warnings from
10
+ // all threads into a single queue, then process together at the end
11
+ // in the main thread.
12
+ class DelayWarningHandler : public at::WarningHandler {
13
+ public:
14
+ ~DelayWarningHandler() override = default;
15
+ void replay_warnings();
16
+
17
+ private:
18
+ void process(const c10::Warning& warning) override;
19
+
20
+ std::vector<c10::Warning> warnings_;
21
+ std::mutex mutex_;
22
+ };
23
+
24
+ } // namespace torch::autograd::utils
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/autograd/utils/wrap_outputs.h ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ // Wrap tensor operation outputs as PyObject*
4
+
5
+ #include <ATen/ScalarOps.h>
6
+ #include <ATen/core/Tensor.h>
7
+ #include <c10/util/irange.h>
8
+ #include <torch/csrc/python_headers.h>
9
+ #include <initializer_list>
10
+ #include <tuple>
11
+
12
+ #include <torch/csrc/Dtype.h>
13
+ #include <torch/csrc/DynamicTypes.h>
14
+ #include <torch/csrc/Layout.h>
15
+ #include <torch/csrc/QScheme.h>
16
+ #include <torch/csrc/autograd/python_variable.h>
17
+ #include <torch/csrc/autograd/variable.h>
18
+ #include <torch/csrc/utils/python_numbers.h>
19
+ #include <torch/csrc/utils/tensor_qschemes.h>
20
+
21
+ namespace torch::autograd::utils {
22
+
23
+ inline PyObject* wrap(bool value) {
24
+ if (value) {
25
+ Py_RETURN_TRUE;
26
+ } else {
27
+ Py_RETURN_FALSE;
28
+ }
29
+ }
30
+
31
+ inline PyObject* wrap(c10::DeviceIndex value) {
32
+ return THPUtils_packDeviceIndex(value);
33
+ }
34
+
35
+ inline PyObject* wrap(int64_t value) {
36
+ return THPUtils_packInt64(value);
37
+ }
38
+
39
+ inline PyObject* wrap(double value) {
40
+ return PyFloat_FromDouble(value);
41
+ }
42
+
43
+ inline PyObject* wrap(c10::complex<double> value) {
44
+ // I could probably also use FromComplex with a reinterpret cast,
45
+ // but... eh.
46
+ return PyComplex_FromDoubles(value.real(), value.imag());
47
+ }
48
+
49
+ inline PyObject* wrap(void* value) {
50
+ return PyLong_FromVoidPtr(value);
51
+ }
52
+
53
+ inline PyObject* wrap(THPDtype* dtype) {
54
+ return Py_NewRef(dtype);
55
+ }
56
+
57
+ inline PyObject* wrap(at::ScalarType scalarType) {
58
+ return Py_NewRef(getTHPDtype(scalarType));
59
+ }
60
+
61
+ inline PyObject* wrap(THPLayout* layout) {
62
+ return Py_NewRef(layout);
63
+ }
64
+
65
+ inline PyObject* wrap(at::Layout layout) {
66
+ return Py_NewRef(getTHPLayout(layout));
67
+ }
68
+
69
+ inline PyObject* wrap(const at::Tensor& tensor) {
70
+ return THPVariable_Wrap(tensor);
71
+ }
72
+
73
+ inline PyObject* wrap(const at::Scalar& scalar) {
74
+ return wrap(scalar_to_tensor(scalar));
75
+ }
76
+
77
+ inline PyObject* wrap(at::QScheme qscheme) {
78
+ auto* thp_qscheme = torch::utils::getTHPQScheme(qscheme);
79
+ Py_INCREF(thp_qscheme);
80
+ return thp_qscheme;
81
+ }
82
+
83
+ inline PyObject* wrap(at::TensorList tl) {
84
+ auto r = THPObjectPtr{PyTuple_New(static_cast<Py_ssize_t>(tl.size()))};
85
+ if (!r)
86
+ throw python_error();
87
+ for (const auto i : c10::irange(tl.size())) {
88
+ PyTuple_SET_ITEM(r.get(), i, wrap(tl[i]));
89
+ }
90
+ return r.release();
91
+ }
92
+
93
+ inline PyObject* wrap(at::IntArrayRef list) {
94
+ auto r = THPObjectPtr{PyTuple_New(static_cast<Py_ssize_t>(list.size()))};
95
+ if (!r)
96
+ throw python_error();
97
+ for (const auto i : c10::irange(list.size())) {
98
+ PyTuple_SET_ITEM(r.get(), i, wrap(list[i]));
99
+ }
100
+ return r.release();
101
+ }
102
+
103
+ inline PyObject* wrap(at::Stream stream) {
104
+ return THPStream_Wrap(stream);
105
+ }
106
+
107
+ namespace detail {
108
+ template <typename F, typename Tuple, size_t... Is>
109
+ void apply_with_idx_impl(
110
+ const F& f,
111
+ Tuple& t,
112
+ std::index_sequence<Is...> /*indices*/) {
113
+ (void)std::initializer_list<int>{(f(std::get<Is>(t), Is), 0)...};
114
+ }
115
+
116
+ // For tuple(a, b, c), calls f(a, 0), f(b, 1), f(c, 2)
117
+ template <typename F, typename... Ts>
118
+ void apply_with_idx(const F& f, std::tuple<Ts...>& t) {
119
+ apply_with_idx_impl(f, t, std::index_sequence_for<Ts...>{});
120
+ }
121
+ } // namespace detail
122
+
123
+ template <typename... Ts>
124
+ PyObject* wrap(std::tuple<Ts...> values) {
125
+ auto r = THPObjectPtr{PyTuple_New(sizeof...(Ts))};
126
+ if (!r)
127
+ throw python_error();
128
+ detail::apply_with_idx(
129
+ [&](auto& value, size_t idx) {
130
+ PyTuple_SET_ITEM(r.get(), idx, wrap(std::move(value)));
131
+ },
132
+ values);
133
+ return r.release();
134
+ }
135
+
136
+ template <typename... Ts>
137
+ PyObject* wrap(PyTypeObject* type, std::tuple<Ts...> values) {
138
+ auto r = THPObjectPtr{PyStructSequence_New(type)};
139
+ if (!r)
140
+ throw python_error();
141
+ detail::apply_with_idx(
142
+ [&](auto& value, size_t idx) {
143
+ PyStructSequence_SET_ITEM(r.get(), idx, wrap(std::move(value)));
144
+ },
145
+ values);
146
+ return r.release();
147
+ }
148
+
149
+ } // namespace torch::autograd::utils
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cpu/Module.h ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #include <torch/csrc/python_headers.h>
3
+
4
+ namespace torch::cpu {
5
+
6
+ void initModule(PyObject* module);
7
+
8
+ } // namespace torch::cpu
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/CUDAPluggableAllocator.h ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <c10/core/Allocator.h>
4
+ #include <c10/cuda/CUDAGraphsC10Utils.h>
5
+ #include <c10/cuda/CUDAMacros.h>
6
+ #include <c10/cuda/CUDAStream.h>
7
+
8
+ #include <c10/cuda/CUDACachingAllocator.h>
9
+
10
+ #include <mutex>
11
+
12
+ namespace torch::cuda::CUDAPluggableAllocator {
13
+
14
+ using MallocFuncType = void*(size_t, int, cudaStream_t);
15
+ using FreeFuncType = void(void*, size_t, int, cudaStream_t);
16
+
17
+ // A CUDAPluggableAllocatorDeleterContext object is used as the `ctx`
18
+ // argument for DataPtr. We need context because a user can use
19
+ // multiple allocators in the same PyTorch program, and
20
+ // the allocators can have different free functions, such as:
21
+ // free, cudaFree, cudaFreeAsync, ncclMemFree etc.
22
+ struct TORCH_CUDA_CPP_API CUDAPluggableAllocatorDeleterContext {
23
+ explicit CUDAPluggableAllocatorDeleterContext(
24
+ std::function<FreeFuncType> free_fn,
25
+ void* data,
26
+ size_t size,
27
+ int device,
28
+ cudaStream_t stream);
29
+
30
+ void free();
31
+
32
+ private:
33
+ std::function<FreeFuncType> free_fn_;
34
+ void* data_;
35
+ size_t size_;
36
+ int device_;
37
+ cudaStream_t stream_{};
38
+ };
39
+
40
+ #if defined(USE_ROCM)
41
+ using streamType = c10::hip::HIPStream;
42
+ #else
43
+ using streamType = c10::cuda::CUDAStream;
44
+ #endif
45
+
46
+ TORCH_CUDA_CPP_API std::shared_ptr<
47
+ c10::cuda::CUDACachingAllocator::CUDAAllocator>
48
+ getCurrentAllocator();
49
+ TORCH_CUDA_CPP_API std::shared_ptr<
50
+ c10::cuda::CUDACachingAllocator::CUDAAllocator>
51
+ createCustomAllocator(
52
+ std::function<MallocFuncType> alloc_fn,
53
+ std::function<FreeFuncType> free_fn);
54
+ TORCH_CUDA_CPP_API void changeCurrentAllocator(
55
+ const std::shared_ptr<c10::cuda::CUDACachingAllocator::CUDAAllocator>&
56
+ allocator);
57
+
58
+ struct _AllocationMetadata {
59
+ _AllocationMetadata();
60
+ _AllocationMetadata(
61
+ size_t size,
62
+ c10::DeviceIndex device_idx,
63
+ cudaStream_t stream);
64
+ size_t size;
65
+ c10::DeviceIndex device_idx;
66
+ cudaStream_t stream{};
67
+ };
68
+
69
+ struct TORCH_CUDA_CPP_API CUDAPluggableAllocator
70
+ : public c10::cuda::CUDACachingAllocator::CUDAAllocator {
71
+ CUDAPluggableAllocator(
72
+ std::function<MallocFuncType> alloc_fn,
73
+ std::function<FreeFuncType> free_fn);
74
+
75
+ CUDAPluggableAllocator(CUDAPluggableAllocator& other);
76
+ CUDAPluggableAllocator(CUDAPluggableAllocator&& other) = delete;
77
+ CUDAPluggableAllocator& operator=(const CUDAPluggableAllocator& other) =
78
+ delete;
79
+ CUDAPluggableAllocator& operator=(CUDAPluggableAllocator&& other) = delete;
80
+ ~CUDAPluggableAllocator() override = default;
81
+
82
+ void set_init_fn(std::function<void(int)> init_fn);
83
+
84
+ void set_reset_fn(std::function<void()> reset_fn);
85
+
86
+ void set_memory_fraction_fn(
87
+ std::function<void(double, int)> memory_fraction_fn);
88
+
89
+ void set_base_alloc_fn(std::function<void*(void*, size_t*)> base_alloc_fn);
90
+
91
+ void set_record_stream_fn(
92
+ std::function<void(void* ptr, cudaStream_t stream)> record_stream_fn);
93
+
94
+ void set_begin_allocate_to_pool(
95
+ std::function<
96
+ void(int, c10::cuda::MempoolId_t, std::function<bool(cudaStream_t)>)>
97
+ capture_begin_fn);
98
+
99
+ void set_end_allocate_to_pool_fn(
100
+ std::function<void(int, c10::cuda::MempoolId_t)> capture_about_to_end_fn);
101
+
102
+ void set_release_pool(
103
+ std::function<void(int, c10::cuda::MempoolId_t)> capture_destroy_fn);
104
+
105
+ void* malloc(size_t size, c10::DeviceIndex device, cudaStream_t stream);
106
+
107
+ c10::DataPtr allocate(size_t size) override;
108
+ c10::DeleterFnPtr raw_deleter() const override;
109
+
110
+ void* raw_alloc(size_t nbytes) override;
111
+ void* raw_alloc_with_stream(size_t nbytes, cudaStream_t stream) override;
112
+ void raw_delete(void* ptr) override;
113
+ void init(int device_count) override;
114
+ bool initialized() override;
115
+ double getMemoryFraction(c10::DeviceIndex device) override;
116
+ void setMemoryFraction(double fraction, c10::DeviceIndex device) override;
117
+ void emptyCache(c10::cuda::MempoolId_t mempool_id = {0, 0}) override;
118
+ void enable(bool) override {}
119
+ bool isEnabled() const override {
120
+ return true;
121
+ }
122
+ void cacheInfo(c10::DeviceIndex device, size_t* largestBlock) override;
123
+ void* getBaseAllocation(void* ptr, size_t* size) override;
124
+
125
+ void recordStream(const c10::DataPtr&, streamType stream) override;
126
+
127
+ c10::CachingDeviceAllocator::DeviceStats getDeviceStats(
128
+ c10::DeviceIndex device) override;
129
+ void resetAccumulatedStats(c10::DeviceIndex device) override;
130
+ void resetPeakStats(c10::DeviceIndex device) override;
131
+ c10::cuda::CUDACachingAllocator::SnapshotInfo snapshot(
132
+ c10::cuda::MempoolId_t mempool) override;
133
+ void beginAllocateToPool(
134
+ c10::DeviceIndex device,
135
+ c10::cuda::MempoolId_t mempool_id,
136
+ std::function<bool(cudaStream_t)>) override;
137
+ void endAllocateToPool(
138
+ c10::DeviceIndex device,
139
+ c10::cuda::MempoolId_t mempool_id) override;
140
+ void releasePool(c10::DeviceIndex device, c10::cuda::MempoolId_t mempool_id)
141
+ override;
142
+ std::shared_ptr<void> getIpcDevPtr(std::string handle) override;
143
+ c10::cuda::CUDACachingAllocator::ShareableHandle shareIpcHandle(
144
+ void*) override;
145
+ void recordHistory(
146
+ bool enabled,
147
+ c10::cuda::CUDACachingAllocator::CreateContextFn context_recorder,
148
+ size_t alloc_trace_max_entries,
149
+ c10::cuda::CUDACachingAllocator::RecordContext when,
150
+ bool clearHistory) override;
151
+ void attachOutOfMemoryObserver(
152
+ c10::cuda::CUDACachingAllocator::OutOfMemoryObserver observer) override;
153
+ void attachAllocatorTraceTracker(
154
+ c10::cuda::CUDACachingAllocator::AllocatorTraceTracker tracker) override;
155
+ std::shared_ptr<c10::cuda::CUDACachingAllocator::AllocatorState>
156
+ getCheckpointState(c10::DeviceIndex device, at::cuda::MempoolId_t id)
157
+ override;
158
+ c10::cuda::CUDACachingAllocator::CheckpointDelta setCheckpointPoolState(
159
+ c10::DeviceIndex device,
160
+ std::shared_ptr<c10::cuda::CUDACachingAllocator::AllocatorState> pps)
161
+ override;
162
+ void enablePeerAccess(c10::DeviceIndex dev, c10::DeviceIndex dev_to_access)
163
+ override;
164
+ cudaError_t memcpyAsync(
165
+ void* dst,
166
+ int dstDevice,
167
+ const void* src,
168
+ int srcDevice,
169
+ size_t count,
170
+ cudaStream_t stream,
171
+ bool p2p_enabled) override;
172
+ std::string name() override;
173
+ void copy_data(void* dest, const void* src, std::size_t count) const final;
174
+
175
+ protected:
176
+ std::function<MallocFuncType> alloc_fn_;
177
+ std::function<FreeFuncType> free_fn_;
178
+ std::function<void(int)> init_fn_;
179
+ std::function<void()> reset_fn_;
180
+ std::function<void(double, int)> memory_fraction_fn_;
181
+ std::function<void*(void*, size_t*)> base_alloc_fn_;
182
+ std::function<void(void* ptr, cudaStream_t stream)> record_stream_fn_;
183
+ std::function<
184
+ void(int, c10::cuda::MempoolId_t, std::function<bool(cudaStream_t)>)>
185
+ begin_allocate_to_pool_fn_;
186
+ std::function<void(int, c10::cuda::MempoolId_t)> end_allocate_to_pool_fn_;
187
+ std::function<void(int, c10::cuda::MempoolId_t)> relase_pool_fn_;
188
+ std::mutex allocator_mutex_;
189
+ // We do the bookkeeping here in order to simplify custom allocators
190
+ std::unordered_map<void*, _AllocationMetadata> allocation_metadata_;
191
+
192
+ bool initialized_ = false;
193
+ };
194
+ } // namespace torch::cuda::CUDAPluggableAllocator
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Event.h ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef THCP_EVENT_INC
2
+ #define THCP_EVENT_INC
3
+
4
+ #include <ATen/cuda/CUDAEvent.h>
5
+ #include <torch/csrc/Event.h>
6
+ #include <torch/csrc/python_headers.h>
7
+
8
+ struct THCPEvent : THPEvent {
9
+ at::cuda::CUDAEvent cuda_event;
10
+ };
11
+ extern PyObject* THCPEventClass;
12
+
13
+ void THCPEvent_init(PyObject* module);
14
+
15
+ inline bool THCPEvent_Check(PyObject* obj) {
16
+ return THCPEventClass && PyObject_IsInstance(obj, THCPEventClass);
17
+ }
18
+
19
+ #endif // THCP_EVENT_INC
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/GdsFile.h ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef THCP_GDSFILE_INC
2
+ #define THCP_GDSFILE_INC
3
+
4
+ #include <torch/csrc/python_headers.h>
5
+
6
+ namespace torch::cuda::shared {
7
+ void initGdsBindings(PyObject* module);
8
+ }
9
+ #endif // THCP_GDSFILE_INC
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Module.h ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef THCP_CUDA_MODULE_INC
2
+ #define THCP_CUDA_MODULE_INC
3
+ #include <torch/csrc/utils/pythoncapi_compat.h>
4
+
5
+ PyObject* THCPModule_getDevice_wrap(PyObject* self);
6
+ PyObject* THCPModule_setDevice_wrap(PyObject* self, PyObject* arg);
7
+ PyObject* THCPModule_getDeviceName_wrap(PyObject* self, PyObject* arg);
8
+ PyObject* THCPModule_getDriverVersion(PyObject* self);
9
+ PyObject* THCPModule_isDriverSufficient(PyObject* self);
10
+ PyObject* THCPModule_getCurrentBlasHandle_wrap(PyObject* self);
11
+
12
+ #endif
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/Stream.h ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef THCP_STREAM_INC
2
+ #define THCP_STREAM_INC
3
+
4
+ #include <c10/cuda/CUDAStream.h>
5
+ #include <torch/csrc/Stream.h>
6
+ #include <torch/csrc/python_headers.h>
7
+
8
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
9
+ struct THCPStream : THPStream {
10
+ at::cuda::CUDAStream cuda_stream;
11
+ };
12
+ extern PyObject* THCPStreamClass;
13
+
14
+ void THCPStream_init(PyObject* module);
15
+
16
+ inline bool THCPStream_Check(PyObject* obj) {
17
+ return THCPStreamClass && PyObject_IsInstance(obj, THCPStreamClass);
18
+ }
19
+
20
+ #endif // THCP_STREAM_INC
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/THCP.h ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/THP.h>
4
+ #include <torch/csrc/cuda/Event.h>
5
+ #include <torch/csrc/cuda/Module.h>
6
+ #include <torch/csrc/cuda/Stream.h>
7
+ #include <torch/csrc/cuda/utils.h>
8
+ #include <torch/csrc/python_headers.h>
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/comm.h ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/ATen.h>
4
+ #include <ATen/cuda/ATenCUDAGeneral.h>
5
+ #include <ATen/cuda/CUDAContext.h>
6
+ #include <torch/csrc/Export.h>
7
+ #include <optional>
8
+
9
+ #include <cstddef>
10
+ #include <vector>
11
+
12
+ namespace torch::cuda {
13
+
14
+ using tensor_list2d = std::vector<std::vector<at::Tensor>>;
15
+
16
+ TORCH_CUDA_CU_API std::vector<at::Tensor>& broadcast_out(
17
+ const at::Tensor& tensor,
18
+ std::vector<at::Tensor>& out_tensors);
19
+ TORCH_CUDA_CU_API std::vector<at::Tensor> broadcast(
20
+ const at::Tensor& tensor,
21
+ at::IntArrayRef devices);
22
+ TORCH_CUDA_CU_API tensor_list2d broadcast_coalesced(
23
+ at::TensorList tensors,
24
+ at::IntArrayRef devices,
25
+ size_t buffer_size);
26
+
27
+ TORCH_CUDA_CU_API std::vector<at::Tensor>& scatter_out(
28
+ const at::Tensor& tensor,
29
+ std::vector<at::Tensor>& out_tensors,
30
+ int64_t dim = 0,
31
+ const std::optional<std::vector<std::optional<at::cuda::CUDAStream>>>&
32
+ streams = std::nullopt);
33
+
34
+ TORCH_CUDA_CU_API std::vector<at::Tensor> scatter(
35
+ const at::Tensor& tensor,
36
+ at::IntArrayRef devices,
37
+ const std::optional<std::vector<int64_t>>& chunk_sizes = std::nullopt,
38
+ int64_t dim = 0,
39
+ const std::optional<std::vector<std::optional<at::cuda::CUDAStream>>>&
40
+ streams = std::nullopt);
41
+
42
+ TORCH_CUDA_CU_API at::Tensor& gather_out(
43
+ at::TensorList tensors,
44
+ at::Tensor& out_tensor,
45
+ int64_t dim);
46
+
47
+ TORCH_CUDA_CU_API at::Tensor gather(
48
+ at::TensorList tensors,
49
+ int64_t dim,
50
+ std::optional<int32_t> destination_index);
51
+
52
+ } // namespace torch::cuda
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/device_set.h ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <c10/cuda/CUDAMacros.h>
4
+ #include <bitset>
5
+ #include <cstddef>
6
+
7
+ namespace torch {
8
+
9
+ using device_set = std::bitset<C10_COMPILE_TIME_MAX_GPUS>;
10
+
11
+ } // namespace torch
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/memory_snapshot.h ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/Export.h>
4
+ #include <cstdint>
5
+ #include <optional>
6
+ #include <string>
7
+
8
+ namespace torch::cuda {
9
+
10
+ // C++-only versions of these, for python use
11
+ // those defined in cuda/Module.cpp which also record python state.
12
+ TORCH_CUDA_CU_API void _record_memory_history(
13
+ bool enabled,
14
+ bool record_context = true,
15
+ int64_t trace_alloc_max_entries = 1,
16
+ bool trace_alloc_record_context = false,
17
+ bool record_cpp_context = false,
18
+ bool clearHistory = false,
19
+ bool compileContext = false,
20
+ bool globalRecordAllocations = false);
21
+
22
+ TORCH_CUDA_CU_API void _record_memory_history(
23
+ std::optional<std::string> enabled = "all",
24
+ std::optional<std::string> context = "all",
25
+ const std::string& stacks = "all",
26
+ size_t max_entries = SIZE_MAX,
27
+ bool clearHistory = false,
28
+ bool compileContext = false,
29
+ bool globalRecordAllocations = false);
30
+
31
+ TORCH_CUDA_CU_API std::string _memory_snapshot_pickled();
32
+
33
+ } // namespace torch::cuda
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/nccl.h ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <ATen/ATen.h>
4
+ #include <ATen/cuda/CUDAContext.h>
5
+
6
+ #include <cstddef>
7
+ #include <optional>
8
+ #include <vector>
9
+
10
+ // NCCL BFloat16 is enabled only for CUDA 11+ and NCCL versions 2.10+, or for
11
+ // HIP 3.1+
12
+ #if defined(__CUDA_BF16_TYPES_EXIST__)
13
+ #define HAS_NCCL_BF16_DATATYPE \
14
+ ((NCCL_MAJOR > 2) || (NCCL_MAJOR == 2) && (NCCL_MINOR >= 10))
15
+ #elif defined(USE_ROCM) && (TORCH_HIP_VERSION >= 301)
16
+ #define HAS_NCCL_BF16_DATATYPE 1
17
+ #else
18
+ #define HAS_NCCL_BF16_DATATYPE 0
19
+ #endif
20
+
21
+ namespace torch::cuda::nccl {
22
+
23
+ /* The following are copied from <nccl.h> and redefined in torch::cuda::nccl
24
+ * namespace */
25
+ /* pytorch should only use the following definition within pytorch scope */
26
+
27
+ /* Opaque handle to communicator to ncclComm*, this will reinterpret as ncclComm
28
+ * in nccl.cpp */
29
+ typedef void* ncclComm_t;
30
+
31
+ /** redefine nccl unique ID in torch scope. this should be identical to native
32
+ * nccl impp. */
33
+ #define NCCL_UNIQUE_ID_BYTES 128
34
+ typedef struct {
35
+ // NOLINTNEXTLINE(*array*)
36
+ char internal[NCCL_UNIQUE_ID_BYTES];
37
+ } ncclUniqueId;
38
+
39
+ /* Error type */
40
+ enum class ncclResult {
41
+ Success = 0,
42
+ UnhandledCudaError = 1,
43
+ SystemError = 2,
44
+ InternalError = 3,
45
+ InvalidArgument = 4,
46
+ InvalidUsage = 5,
47
+ RemoteError = 6,
48
+ InProgress = 7,
49
+ NumResults = 8
50
+ };
51
+
52
+ /* Reduction operation selector */
53
+ enum class ncclRedOp { Sum = 0, Prod = 1, Max = 2, Min = 3, NumOps = 4 };
54
+
55
+ /* Data types */
56
+ enum class ncclDataType {
57
+ Int8 = 0,
58
+ Char = 0,
59
+ Uint8 = 1,
60
+ Int32 = 2,
61
+ Int = 2,
62
+ Uint32 = 3,
63
+ Int64 = 4,
64
+ Uint64 = 5,
65
+ Float16 = 6,
66
+ Half = 6,
67
+ Float32 = 7,
68
+ Float = 7,
69
+ Float64 = 8,
70
+ Double = 8,
71
+ Bfloat16 = 9,
72
+ NumTypes = 10
73
+ };
74
+
75
+ // RAII helper class to manage NCCL group API and CUDA free mutex.
76
+ // The destructor is allowed to throw since this helper class only
77
+ // manages group and lock lifetimes.
78
+ struct TORCH_CUDA_CPP_API AutoNcclGroup {
79
+ AutoNcclGroup();
80
+ AutoNcclGroup(ncclComm_t comm, bool comm_nonblocking);
81
+ ~AutoNcclGroup() noexcept(false);
82
+ ncclComm_t comm_;
83
+ bool comm_nonblocking_;
84
+ };
85
+
86
+ // NOTE: this is exposed only so that python_nccl.cpp can some of these helpers.
87
+ // Don't use them outside of these files.
88
+ namespace detail {
89
+
90
+ TORCH_CUDA_CPP_API void throw_nccl_error(ncclResult status);
91
+
92
+ inline void NCCL_CHECK(ncclResult status) {
93
+ if (status != ncclResult::Success) {
94
+ throw_nccl_error(status);
95
+ }
96
+ }
97
+
98
+ TORCH_CUDA_CPP_API at::ArrayRef<ncclComm_t> get_communicators(
99
+ at::TensorList inputs);
100
+ TORCH_CUDA_CPP_API void check_inputs(
101
+ at::TensorList inputs,
102
+ at::TensorList outputs,
103
+ size_t input_multiplier,
104
+ size_t output_multiplier);
105
+ TORCH_CUDA_CPP_API void check_inputs(
106
+ at::TensorList inputs,
107
+ const at::Tensor& output,
108
+ int root,
109
+ size_t input_multiplier,
110
+ size_t output_multiplier);
111
+
112
+ } // namespace detail
113
+
114
+ using comm_list = std::vector<ncclComm_t>;
115
+ using stream_list = std::vector<std::optional<at::cuda::CUDAStream>>;
116
+
117
+ TORCH_CUDA_CPP_API std::uint64_t version();
118
+ TORCH_CUDA_CPP_API const char* version_suffix();
119
+
120
+ bool is_available(at::TensorList tensors);
121
+
122
+ TORCH_CUDA_CPP_API void get_unique_id(ncclUniqueId& id);
123
+ TORCH_CUDA_CPP_API ncclComm_t
124
+ comm_init_rank(int nranks, const ncclUniqueId& comm_id, int rank);
125
+ TORCH_CUDA_CPP_API void comm_destroy(ncclComm_t comm);
126
+
127
+ TORCH_CUDA_CPP_API void broadcast(
128
+ at::TensorList tensors,
129
+ const stream_list& streams = {},
130
+ const comm_list& user_comms = {});
131
+
132
+ size_t get_max_count();
133
+
134
+ TORCH_CUDA_CPP_API void reduce(
135
+ const std::vector<at::Tensor>& inputs,
136
+ at::Tensor& output,
137
+ int32_t root = 0,
138
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
139
+ const stream_list& streams = {},
140
+ const comm_list& user_comms = {});
141
+
142
+ TORCH_CUDA_CPP_API void reduce(
143
+ std::vector<at::Tensor>& inputs,
144
+ int32_t root = 0,
145
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
146
+ const stream_list& streams = {},
147
+ const comm_list& user_comms = {});
148
+
149
+ TORCH_CUDA_CPP_API void all_reduce(
150
+ const std::vector<at::Tensor>& inputs,
151
+ std::vector<at::Tensor>& outputs,
152
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
153
+ const stream_list& streams = {},
154
+ const comm_list& user_comms = {});
155
+
156
+ TORCH_CUDA_CPP_API void reduce_scatter(
157
+ const std::vector<at::Tensor>& inputs,
158
+ std::vector<at::Tensor>& outputs,
159
+ int32_t op = static_cast<int>(ncclRedOp::Sum),
160
+ const stream_list& streams = {},
161
+ const comm_list& user_comms = {});
162
+
163
+ TORCH_CUDA_CPP_API void scatter(
164
+ const std::vector<at::Tensor>& inputs,
165
+ at::Tensor& outputs,
166
+ ncclComm_t comm,
167
+ at::cuda::CUDAStream& stream,
168
+ int32_t root = 0);
169
+
170
+ TORCH_CUDA_CPP_API void all_gather(
171
+ const std::vector<at::Tensor>& inputs,
172
+ std::vector<at::Tensor>& outputs,
173
+ const stream_list& streams = {},
174
+ const comm_list& user_comms = {});
175
+
176
+ TORCH_CUDA_CPP_API void gather(
177
+ const at::Tensor& inputs,
178
+ std::vector<at::Tensor>& outputs,
179
+ ncclComm_t comm,
180
+ at::cuda::CUDAStream& stream,
181
+ int32_t root = 0);
182
+
183
+ TORCH_CUDA_CPP_API void all2all_single_equal_split(
184
+ at::Tensor& input,
185
+ at::Tensor& output,
186
+ int size,
187
+ ncclComm_t comm,
188
+ at::cuda::CUDAStream& stream);
189
+
190
+ TORCH_CUDA_CPP_API void all2all_single_unequal_split(
191
+ void* sendbuff,
192
+ const size_t* sendcounts,
193
+ const size_t* senddispls,
194
+ void* recvbuff,
195
+ const size_t* recvcounts,
196
+ const size_t* recvdispls,
197
+ size_t size,
198
+ c10::ScalarType type,
199
+ ncclComm_t comm,
200
+ at::cuda::CUDAStream& stream);
201
+
202
+ TORCH_CUDA_CPP_API void all2all(
203
+ std::vector<at::Tensor>& outputTensors,
204
+ std::vector<at::Tensor>& inputTensors,
205
+ ncclComm_t _comm,
206
+ at::cuda::CUDAStream& stream);
207
+
208
+ TORCH_CUDA_CPP_API void send(
209
+ const at::Tensor& input,
210
+ ncclComm_t comm,
211
+ at::cuda::CUDAStream stream,
212
+ int dst);
213
+
214
+ TORCH_CUDA_CPP_API void recv(
215
+ at::Tensor& output,
216
+ ncclComm_t comm,
217
+ at::cuda::CUDAStream stream,
218
+ int src);
219
+ } // namespace torch::cuda::nccl
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_comm.h ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/utils/pythoncapi_compat.h>
4
+ namespace torch::cuda::python {
5
+
6
+ void initCommMethods(PyObject* module);
7
+
8
+ } // namespace torch::cuda::python
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/python_nccl.h ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/python_headers.h>
4
+
5
+ PyObject* THCPModule_nccl_version(PyObject* self, PyObject* args);
6
+ PyObject* THCPModule_nccl_version_suffix(PyObject* self, PyObject* args);
7
+ PyObject* THCPModule_nccl_unique_id(PyObject* self, PyObject* args);
8
+ PyObject* THCPModule_nccl_init_rank(PyObject* self, PyObject* args);
9
+ PyObject* THCPModule_nccl_reduce(PyObject* self, PyObject* args);
10
+ PyObject* THCPModule_nccl_all_reduce(PyObject* self, PyObject* args);
11
+ PyObject* THCPModule_nccl_broadcast(PyObject* self, PyObject* args);
12
+ PyObject* THCPModule_nccl_all_gather(PyObject* self, PyObject* args);
13
+ PyObject* THCPModule_nccl_reduce_scatter(PyObject* self, PyObject* args);
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/cuda/utils.h ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <c10/cuda/CUDAStream.h>
4
+ #include <torch/csrc/utils/python_numbers.h>
5
+
6
+ #include <vector>
7
+
8
+ std::vector<std::optional<at::cuda::CUDAStream>>
9
+ THPUtils_PySequence_to_CUDAStreamList(PyObject* obj);
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/autograd.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/autograd/context/container.h>
4
+ #include <torch/csrc/distributed/autograd/engine/dist_engine.h>
5
+
6
+ namespace torch::distributed::autograd {
7
+
8
+ using torch::autograd::variable_list;
9
+
10
+ /// C++ API of Distributed Autograd that kicks off the distributed backward pass
11
+ /// using the provided roots. This currently implements the
12
+ /// :ref:`fast-mode-algorithm` which assumes all RPC messages sent in the same
13
+ /// distributed autograd context across workers would be part of the autograd
14
+ /// graph during the backward pass.
15
+ ///
16
+ /// We use the provided roots to discover the autograd graph and compute
17
+ /// appropriate dependencies. This method blocks until the entire
18
+ /// autograd computation is done.
19
+ /// This function accumulates gradients in the leaves - you might need to zero
20
+ /// them before calling it.
21
+ ///
22
+ /// \param context_id The autograd context id for which we should retrieve the
23
+ /// gradients.
24
+ /// \param roots Tensors which represent the roots of the autograd computation.
25
+ /// All the tensors should be scalars.
26
+ /// \param retain_graph If `false`, the graph used to compute the grad will be
27
+ /// freed. Note that in nearly all cases setting this
28
+ /// option to `true` is not needed and often can be worked
29
+ /// around in a much more efficient way. Usually, you need
30
+ /// to set this to `true` to run backward multiple times.
31
+ TORCH_API void backward(
32
+ int64_t context_id,
33
+ const variable_list& roots,
34
+ bool retain_graph = false);
35
+
36
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/context/container.h ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <mutex>
4
+ #include <unordered_map>
5
+
6
+ #include <torch/csrc/distributed/autograd/context/context.h>
7
+
8
+ namespace torch::distributed::autograd {
9
+
10
+ // Singleton class per worker which is responsible for storing the distributed
11
+ // autograd context for each autograd pass and also cleans up data for an
12
+ // autograd pass once its done.
13
+ //
14
+ // Each autograd pass is assigned a unique autograd_context_id and all data for
15
+ // that pass (DistAutogradContext) is stored in this container indexed by the
16
+ // autograd_context_id. The autograd_context_id itself is a 64 bit globally
17
+ // unique id. The first 16 bits is the worker_id and the next 48 bits is an
18
+ // auto-incrementing id for each worker.
19
+ //
20
+ // This container is also responsible for maintaining a globally unique message
21
+ // id, which is used to associate send/recv autograd function pairs. The format
22
+ // is similar to the autograd_context_id where we have a 64 bit integer with
23
+ // first 16 bits being the worker id and next 48 bits are auto-incrementing.
24
+ class TORCH_API DistAutogradContainer {
25
+ public:
26
+ explicit DistAutogradContainer(uint32_t num_shards);
27
+
28
+ // One time initialization of the container.
29
+ static DistAutogradContainer& init(int64_t worker_id);
30
+
31
+ // Retrieve the singleton instance of the container, ensures we have
32
+ // initialized the container.
33
+ static DistAutogradContainer& getInstance();
34
+
35
+ // Create a new context for a distributed autograd pass.
36
+ const ContextPtr newContext();
37
+
38
+ // Clean up resources for a given context_id once the autograd pass is done.
39
+ // Sends RPC to other workers this worker knows about, telling them to clean
40
+ // up their context as well. Throws an exception if the context_id does not
41
+ // exist.
42
+ void releaseContext(int64_t context_id);
43
+
44
+ // Releases an autograd context if it is present on this node. Also sends RPC
45
+ // to other workers this worker knows about, telling them to clean up their
46
+ // context. Does nothing if it is not present.
47
+ void releaseContextIfPresent(int64_t context_id);
48
+
49
+ // Checks if the passed in context_id is valid.
50
+ void isValidContext(int64_t context_id);
51
+
52
+ // Retrieve the autograd context for a given context_id.
53
+ ContextPtr retrieveContext(int64_t context_id);
54
+
55
+ // Retrieves the currently active autograd context for the current thread.
56
+ ContextPtr currentContext();
57
+
58
+ // Checks whether or not the current thread has a valid autograd context.
59
+ bool hasValidContext() const;
60
+
61
+ // Generate a new autograd_message_id for send/recv autograd functions.
62
+ int64_t newAutogradMessageId();
63
+
64
+ // Creates a new autograd context with the provided context_id. If a context
65
+ // already exists with the provided context_id, we just return it.
66
+ // This does not set the current context for the current thread.
67
+ ContextPtr getOrCreateContext(int64_t context_id);
68
+
69
+ // Retrieves the maximum possible autograd_context_id/autograd_message_id that
70
+ // can be generated by this worker.
71
+ int64_t getMaxId();
72
+
73
+ // Retrieves the worker ID for this node
74
+ rpc::worker_id_t getWorkerId() const;
75
+
76
+ // Can set current context id if there is no valid context yet
77
+ static void setCurrentContextId(int64_t contextId);
78
+
79
+ // Forcibly sets the thread local current context id. Should only be used in
80
+ // cases where you know what you're doing and need to override the thread
81
+ // local. Otherwise, use setCurrentContextId instead.
82
+ static void forceCurrentContextId(int64_t contextId);
83
+
84
+ // Clear current context id
85
+ void clearCurrentContext();
86
+
87
+ // Returns the number of autograd contexts in the container.
88
+ size_t numAutogradContexts() const;
89
+
90
+ // Returns the current thread local context id for this thread.
91
+ static int64_t currentContextId();
92
+
93
+ DistAutogradContainer() = delete;
94
+ ~DistAutogradContainer() = default;
95
+ DistAutogradContainer(const DistAutogradContainer&) = delete;
96
+ DistAutogradContainer& operator=(const DistAutogradContainer&) = delete;
97
+ DistAutogradContainer(DistAutogradContainer&&) = delete;
98
+ DistAutogradContainer& operator=(DistAutogradContainer&&) = delete;
99
+
100
+ private:
101
+ // Number of shards for the map storing autograd contexts. We'd like this
102
+ // to be a power of 2 and we don't expect a value much higher than the
103
+ // number of cores would provide much benefit.
104
+ static constexpr uint32_t kNumDefaultShards = 128;
105
+
106
+ // Use cache line size for alignment.
107
+ static constexpr int kCacheLineSize = 64;
108
+
109
+ // Structure holding one shard of the sharded autograd context map with its
110
+ // associated lock. Align to cache line size to avoid contention between
111
+ // adjacent entries.
112
+ struct alignas(kCacheLineSize) ContextsShard {
113
+ // Lock for this shard.
114
+ mutable std::mutex lock;
115
+
116
+ // Map storing autograd contexts for this shard.
117
+ std::unordered_map<int64_t, ContextPtr> contexts;
118
+ };
119
+
120
+ static DistAutogradContainer& getInstanceInternal();
121
+
122
+ // Retrieve the shard for given context_id.
123
+ ContextsShard& getShard(int64_t context_id);
124
+
125
+ // Sends an RPC to the workers that have a context corresponding to passed in
126
+ // context_id. This function should be called with the lock.
127
+ void sendReleaseContextRpc(
128
+ const std::unordered_set<rpc::worker_id_t>& workerIds,
129
+ int64_t context_id);
130
+
131
+ // Erase context_id from the autograd context map, and reset the thread local
132
+ // current context id if it corresponds to the passed in context id. This
133
+ // function should be called with the lock.
134
+ void eraseContextIdAndReset(ContextsShard& shard, int64_t context_id);
135
+
136
+ // Compute the number of shards for the autograd_contexts_ map.
137
+ static uint32_t computeNumShards();
138
+
139
+ // Auto incrementing context id used to identify unique autograd passes.
140
+ // Initialized with the first 16 bits being the worker_id.
141
+ std::atomic<int64_t> next_context_id_;
142
+
143
+ // Unique id to identify a worker in the distributed setting.
144
+ int16_t worker_id_;
145
+
146
+ // Whether or not the container has been initialized appropriately.
147
+ bool initialized_;
148
+
149
+ // Sharded autograd context map.
150
+ std::vector<ContextsShard> autograd_contexts_;
151
+
152
+ // Number of shards for the sharded autograd_contexts_ map.
153
+ uint32_t num_shards_;
154
+
155
+ // Autograd message id to identify unique send/recv autograd function pairs.
156
+ std::atomic<int64_t> next_autograd_message_id_;
157
+
158
+ // Maximum allowed value for autograd_context_id or autograd_message_id.
159
+ int64_t max_id_;
160
+ };
161
+
162
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/context/context.h ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <cstdint>
4
+ #include <functional>
5
+
6
+ #include <ATen/core/Dict.h>
7
+ #include <torch/csrc/autograd/engine.h>
8
+ #include <torch/csrc/distributed/autograd/functions/recvrpc_backward.h>
9
+ #include <torch/csrc/distributed/autograd/functions/sendrpc_backward.h>
10
+ #include <torch/csrc/distributed/rpc/rpc_agent.h>
11
+
12
+ namespace torch::distributed::autograd {
13
+
14
+ class RecvRpcBackward;
15
+
16
+ // DistAutogradContext which stores information for a single distributed
17
+ // autograd pass on a worker.
18
+ class TORCH_API DistAutogradContext {
19
+ public:
20
+ using GradCallback = std::function<bool(torch::Tensor&)>;
21
+
22
+ explicit DistAutogradContext(int64_t contextId);
23
+ ~DistAutogradContext() = default;
24
+
25
+ // Retrieves the autograd context id for this context.
26
+ int64_t contextId() const;
27
+
28
+ // Records a 'send' autograd function for this context with the provided
29
+ // message id.
30
+ void addSendFunction(
31
+ const std::shared_ptr<SendRpcBackward>& func,
32
+ int64_t autograd_message_id);
33
+
34
+ // Records a 'recv' autograd function for this context with the provided
35
+ // message id.
36
+ void addRecvFunction(
37
+ std::shared_ptr<RecvRpcBackward>& func,
38
+ int64_t autograd_message_id);
39
+
40
+ // Given an autograd_message_id, retrieve the appropriate send function.
41
+ std::shared_ptr<SendRpcBackward> retrieveSendFunction(
42
+ int64_t autograd_message_id);
43
+
44
+ // Return all send functions for this context.
45
+ std::unordered_map<int64_t, std::shared_ptr<SendRpcBackward>> sendFunctions()
46
+ const;
47
+
48
+ // Return all recv functions for this context.
49
+ std::unordered_map<int64_t, std::shared_ptr<RecvRpcBackward>> recvFunctions()
50
+ const;
51
+
52
+ // Adds a future message recording an outstanding RPC.
53
+ void addOutstandingRpc(const c10::intrusive_ptr<rpc::JitFuture>& jitFuture);
54
+
55
+ // Returns all gradients.
56
+ const c10::Dict<torch::Tensor, torch::Tensor> getGradients() const;
57
+
58
+ // This function gives a mutable grad reference to the callback.
59
+ // If the callback returns true, it means the grad in the context
60
+ // needs to be updated.
61
+ void runGradCallbackForVariable(
62
+ const torch::autograd::Variable& variable,
63
+ const GradCallback& cb);
64
+
65
+ DistAutogradContext(const DistAutogradContext&) = delete;
66
+ DistAutogradContext& operator=(const DistAutogradContext&) = delete;
67
+ DistAutogradContext(DistAutogradContext&&) = delete;
68
+ DistAutogradContext& operator=(DistAutogradContext&&) = delete;
69
+
70
+ // records the workerID of a node that we sent an RPC to.
71
+ // workerIDs are added here when we attach a send function to this autograd
72
+ // context
73
+ void addKnownWorkerId(const rpc::worker_id_t workerId);
74
+
75
+ // Retrieves a set containing the known workerIds for this context
76
+ // These are the different workers that this context has sent RPCs to.
77
+ std::unordered_set<rpc::worker_id_t> getKnownWorkerIds() const;
78
+
79
+ private:
80
+ friend class BackwardPassCleanupGuard;
81
+ friend class DistEngine;
82
+ friend class RecvRpcBackward;
83
+ friend class DistAccumulateGradCaptureHook;
84
+
85
+ // Record that we would like to accumulate the provided gradient on the given
86
+ // variable.
87
+ void accumulateGrad(
88
+ const torch::autograd::Variable& variable,
89
+ const torch::Tensor& grad,
90
+ size_t num_expected_refs);
91
+
92
+ // Retrieve the GraphTask.
93
+ std::shared_ptr<torch::autograd::GraphTask> retrieveGraphTask();
94
+
95
+ // Set the appropriate graph task for the backward pass. Can be called only
96
+ // once.
97
+ void setGraphTask(std::shared_ptr<torch::autograd::GraphTask> graphTask);
98
+
99
+ // Resets the graph task to ensure we can run another distributed backward
100
+ // pass for the same autograd context.
101
+ void resetGraphTask();
102
+
103
+ // Waits for all outstanding RPCs for this context to finish and clears all
104
+ // outstanding rpcs held in this context. This should be called only once.
105
+ c10::intrusive_ptr<c10::ivalue::Future> clearAndWaitForOutstandingRpcsAsync();
106
+
107
+ void clearOutstandingRpcs();
108
+
109
+ // Record an event to mark the completion of gradient computation. These
110
+ // events will later help to properly synchronize gradients consumptions
111
+ // in getGradients(). We need these events because backward and
112
+ // optimizer.step are separate RPC calls, and will occur on different CUDA
113
+ // streams. Without synchronization, it is possible that gradients are
114
+ // consumed before they are ready.
115
+ void recordGradEvent(c10::Device device);
116
+
117
+ const int64_t contextId_;
118
+
119
+ // Set containing known worker IDs, used in cleaning up autograd context.
120
+ // Whenever a sendRpcBackward is attached to the autograd graph for this
121
+ // context, the destination is added here.
122
+ std::unordered_set<rpc::worker_id_t> knownWorkerIds_;
123
+
124
+ // Map from autograd_message_id to appropriate 'send' autograd function.
125
+ std::unordered_map<int64_t, std::shared_ptr<SendRpcBackward>>
126
+ sendAutogradFunctions_;
127
+
128
+ // Map from autograd_message_id to appropriate 'recv' autograd function.
129
+ std::unordered_map<int64_t, std::shared_ptr<RecvRpcBackward>>
130
+ recvAutogradFunctions_;
131
+
132
+ // Gradients accumulated in this context so far. The key is the variable on
133
+ // which the gradient needs to be accumulated and the value is the gradient
134
+ // that needs to be accumulated on that variable..
135
+ c10::Dict<torch::Tensor, torch::Tensor> accumulatedGrads_;
136
+
137
+ // See comments for recordGradEvent(c10::Device device);
138
+ std::unordered_map<c10::Device, c10::Event> gradReadyEvents_;
139
+ const c10::impl::VirtualGuardImpl impl_;
140
+
141
+ // The autograd GraphTask for the backward pass on this node for this context.
142
+ std::shared_ptr<torch::autograd::GraphTask> graphTask_;
143
+
144
+ // List of futures for RPCs initiated by this node to propagate gradients to
145
+ // other nodes. The distributed autograd engine on this node can return
146
+ // successfully only if all these futures are done and are successful.
147
+ std::vector<c10::intrusive_ptr<rpc::JitFuture>> outStandingRpcs_;
148
+
149
+ // Lock to protect concurrent modification of the context.
150
+ mutable std::mutex lock_;
151
+ };
152
+
153
+ using ContextPtr = std::shared_ptr<DistAutogradContext>;
154
+
155
+ // This class stores a shared_ptr to a DistAutogradContext instance in a
156
+ // thread local variable. The instance is given by the call site. The class
157
+ // doesn't know the current context. It's just a util class.
158
+ class TORCH_API ThreadLocalDistAutogradContext {
159
+ public:
160
+ // Store 'new_context' to the thread local variable maintained by this class.
161
+ explicit ThreadLocalDistAutogradContext(ContextPtr&& new_context);
162
+ ~ThreadLocalDistAutogradContext();
163
+
164
+ // Retrieve the stored DistAutogradContext instance.
165
+ static ContextPtr getContextPtr();
166
+
167
+ private:
168
+ ContextPtr prev_context_ptr_;
169
+ };
170
+
171
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/engine/dist_engine.h ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <mutex>
4
+ #include <unordered_set>
5
+
6
+ #include <torch/csrc/autograd/engine.h>
7
+ #include <torch/csrc/autograd/function.h>
8
+ #include <torch/csrc/autograd/functions/basic_ops.h>
9
+ #include <torch/csrc/distributed/autograd/context/context.h>
10
+
11
+ namespace torch::distributed::autograd {
12
+
13
+ // Forward declaration.
14
+ class BackwardPassCleanupGuard;
15
+
16
+ // This is a singleton class responsible for running distributed backward
17
+ // passes. This engine relies heavily on the vanilla autograd engine and tries
18
+ // to reuse it as much as possible. This class is mostly responsible for the
19
+ // distributed aspects of autograd and tries to hook into the autograd engine
20
+ // where convenient.
21
+
22
+ // Unlike the vanilla autograd engine, the distributed autograd engine
23
+ // accumulates the gradients in the appropriate DistAutogradContext. This avoids
24
+ // multiple trainer nodes stomping on each others gradients.
25
+ class TORCH_API DistEngine {
26
+ public:
27
+ // Retrieve the singleton instance.
28
+ static DistEngine& getInstance();
29
+
30
+ // Given a list of root variables, start the distributed backwards pass from
31
+ // these variables and accumulate all the gradients in the current autograd
32
+ // context on each node. This method is used to kickoff distributed autograd
33
+ // on a single node.
34
+ void execute(
35
+ int64_t context_id,
36
+ const torch::autograd::variable_list& roots,
37
+ bool retainGraph);
38
+
39
+ // Given a send function to execute in the autograd engine, ensures we compute
40
+ // dependencies once for this node and enqueues the send function for execute
41
+ // in the engine.
42
+ // This method is used to kick off the autograd computation on a node when it
43
+ // receives gradients from the corresponding 'recv' method on another node.
44
+ // The gradients are accumulated in the provided autograd context.
45
+ c10::intrusive_ptr<c10::ivalue::Future> executeSendFunctionAsync(
46
+ const ContextPtr& autogradContext,
47
+ const std::shared_ptr<SendRpcBackward>& sendFunction,
48
+ bool retainGraph);
49
+
50
+ // Number of backward passes currently running for the Distributed Engine.
51
+ size_t numBackwardPasses() const;
52
+
53
+ // Returns key-value pairs consisting of useful debugging information related
54
+ // to distributed autograd.
55
+ std::unordered_map<std::string, int64_t> getDebugInfo() const;
56
+
57
+ DistEngine(const DistEngine&) = delete;
58
+ DistEngine& operator=(const DistEngine&) = delete;
59
+ DistEngine(DistEngine&&) = delete;
60
+ DistEngine& operator=(DistEngine&&) = delete;
61
+
62
+ private:
63
+ // Make sure this is a singleton.
64
+ DistEngine();
65
+ ~DistEngine();
66
+
67
+ // Validates the input roots for the backward computations and retrieves the
68
+ // appropriate root edges and corresponding gradients. Populates root_edges
69
+ // with the appropriate gradient edges and grads with the gradients for each
70
+ // edge.
71
+ void validateRootsAndRetrieveEdges(
72
+ const torch::autograd::variable_list& roots,
73
+ torch::autograd::edge_list& rootEdges,
74
+ torch::autograd::variable_list& grads);
75
+
76
+ // Given the autograd context, root edges and grads, we compute dependencies
77
+ // for the local node and fill out the provided GraphTask and GraphRoot with
78
+ // appropriate information for the local autograd engine.
79
+ // We also determine all leaf nodes(functions) in the graph and accumulate
80
+ // them in outputEdges.
81
+ void computeDependencies(
82
+ const ContextPtr& context,
83
+ const torch::autograd::edge_list& rootEdges,
84
+ const torch::autograd::variable_list& grads,
85
+ const std::shared_ptr<torch::autograd::Node>& graphRoot,
86
+ torch::autograd::edge_list& outputEdges,
87
+ bool retainGraph);
88
+
89
+ // Given a pre-populated GraphTask and a root node, compute the backward pass
90
+ // for the autograd graph until the graph task ready queue is empty.
91
+ //
92
+ // This method assumes that the appropriate GraphTask has already been
93
+ // initialized appropriately. It will construct a local ready queue to
94
+ // traverse the GraphTask instead of using the GraphTask embedded
95
+ // cpu_ready_queue, this is because dist engine might run the same GraphTask
96
+ // from different SendFunctions concurrently in different threads. The method
97
+ // will only mark the GraphTask as completed when it needs to, which means it
98
+ // might not mark as completed for every call as dist engine would like to
99
+ // keep the GraphTask alive when it not receives all gradients.
100
+ //
101
+ // When `incrementOutstandingTasks=false`, the function does not increment
102
+ // 'outstanding_tasks_' in the appropriate GraphTask. It is assumed we've
103
+ // already done this before hand for this task (to ensure we don't pre-mark
104
+ // this graph_task as completed). This is useful in the distributed autograd
105
+ // case where we need to increment 'outstanding_tasks_' first to indicate the
106
+ // local autograd engine the graph task is not completed until it receives the
107
+ // signals from other workers over the network.
108
+ //
109
+ // XXX: calling this function assumes that we will have NO GPU nodetasks be
110
+ // executed for the graph_task, the caller of this function need to ensure
111
+ // this otherwise there will be undefined behaviors. A correct way to fix this
112
+ // is to re-design the autograd engine so that GPU worker thread to behave the
113
+ // same as CPU caller thread, record the operation/thread for the device, and
114
+ // reuse it in backward.
115
+ // TODO: 1. Add assert in the dist engine to ensure no GPU NodeTasks during
116
+ // backward
117
+ // 2. properly setup the thread local ready queue to enable reentrant
118
+ // backwards
119
+ void execute_graph_task_until_ready_queue_empty(
120
+ torch::autograd::NodeTask&& node_task,
121
+ bool incrementOutstandingTasks = true);
122
+
123
+ // Run the local autograd engine using the provided graphTask and graphRoot
124
+ // and accumulate the gradients part 'outputEdges' in the provided autograd
125
+ // context.
126
+ c10::intrusive_ptr<c10::ivalue::Future> runEngineAndAccumulateGradients(
127
+ const ContextPtr& autogradContext,
128
+ const std::shared_ptr<torch::autograd::Node>& graphRoot,
129
+ const torch::autograd::edge_list& outputEdges,
130
+ bool incrementOutStandingTasks = true);
131
+
132
+ // Run after the backward pass is done to appropriately cleanup structures.
133
+ void cleanupBackwardPass(const ContextPtr& autogradContext);
134
+
135
+ // Global thread to execute CPU continuations.
136
+ void globalCpuThread(
137
+ const std::shared_ptr<torch::autograd::ReadyQueue>& ready_queue);
138
+
139
+ // Set of autograd context_ids, which we have already initialized for
140
+ // distributed autograd on this node (e.g.: already computed dependencies)
141
+ std::unordered_set<int64_t> initializedContextIds_;
142
+
143
+ mutable std::mutex initializedContextIdsLock_;
144
+
145
+ // Reference to local autograd engine.
146
+ torch::autograd::Engine& engine_;
147
+
148
+ // Ready queue used by the CPU thread in distributed engine.
149
+ // See Note [GPU to CPU continuations]
150
+ std::shared_ptr<torch::autograd::ReadyQueue> global_cpu_ready_queue_;
151
+
152
+ // See Note [GPU to CPU continuations]
153
+ std::thread global_cpu_thread_;
154
+
155
+ friend class BackwardPassCleanupGuard;
156
+ };
157
+
158
+ // Guard to clean up resources once the backward pass is done.
159
+ class BackwardPassCleanupGuard {
160
+ public:
161
+ explicit BackwardPassCleanupGuard(ContextPtr autogradContext)
162
+ : autogradContext_(std::move(autogradContext)) {}
163
+
164
+ ~BackwardPassCleanupGuard() {
165
+ DistEngine::getInstance().cleanupBackwardPass(autogradContext_);
166
+ }
167
+
168
+ private:
169
+ ContextPtr autogradContext_;
170
+ };
171
+
172
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/functions/recvrpc_backward.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/autograd/function.h>
4
+ #include <torch/csrc/distributed/autograd/context/context.h>
5
+ #include <torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h>
6
+ #include <torch/csrc/distributed/rpc/rpc_agent.h>
7
+
8
+ namespace torch::distributed::autograd {
9
+
10
+ // Forward declarations.
11
+ class DistAutogradContext;
12
+
13
+ // As part of our distributed autograd implementation, whenever we receive an
14
+ // RPC from a node, we add a 'RecvRpcBackward' autograd function to the
15
+ // autograd graph. This is more or less a placeholder function that is used to
16
+ // pass gradients to the remote host during the backward pass. The inputs to the
17
+ // RPC function are the inputs to this autograd function.
18
+ class TORCH_API RecvRpcBackward : public torch::autograd::Node {
19
+ public:
20
+ explicit RecvRpcBackward(
21
+ const AutogradMetadata& autogradMetadata,
22
+ const std::shared_ptr<DistAutogradContext>& autogradContext,
23
+ rpc::worker_id_t fromWorkerId,
24
+ rpc::DeviceMap deviceMap);
25
+
26
+ torch::autograd::variable_list apply(
27
+ torch::autograd::variable_list&& grads) override;
28
+
29
+ private:
30
+ const AutogradMetadata autogradMetadata_;
31
+
32
+ // Hold a weak reference to the autograd context to avoid circular
33
+ // dependencies with the context (since it holds a reference to
34
+ // RecvRpcBackward).
35
+ std::weak_ptr<DistAutogradContext> autogradContext_;
36
+
37
+ // The worker id from which the RPC was received. During the backward pass,
38
+ // we need to propagate the gradients to this workerId.
39
+ rpc::worker_id_t fromWorkerId_;
40
+
41
+ // Device mapping for tensors sent over RPC.
42
+ const rpc::DeviceMap deviceMap_;
43
+ };
44
+
45
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/functions/sendrpc_backward.h ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/autograd/function.h>
4
+
5
+ namespace torch::distributed::autograd {
6
+
7
+ // As part of our distributed autograd implementation, whenever we send an RPC
8
+ // from one node to another, we add a 'SendRpcBackward' autograd function to the
9
+ // autograd graph. This is more or less a placeholder function that is used to
10
+ // kickoff the autograd engine on the current worker on the backward pass. The
11
+ // edges for this autograd function are the inputs to the RPC method.
12
+ //
13
+ // During the backward pass, this function is queued for execution in the
14
+ // autograd engine which eventually runs the rest of the autograd graph.
15
+ struct TORCH_API SendRpcBackward : public torch::autograd::Node {
16
+ public:
17
+ torch::autograd::variable_list apply(
18
+ torch::autograd::variable_list&& inputs) override;
19
+
20
+ // SendRpcBackward is actually the root of an autograd graph on the local
21
+ // node. As a result, it doesn't receive any 'inputs', but rather the RPC
22
+ // framework passes gradients over to this function to kickoff local autograd
23
+ // computation.
24
+ void setGrads(const torch::autograd::variable_list& grads);
25
+
26
+ // Retrieve the grads for the function.
27
+ const torch::autograd::variable_list& getGrads() const;
28
+
29
+ private:
30
+ torch::autograd::variable_list grads_;
31
+ };
32
+
33
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/python_autograd.h ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/python_headers.h>
4
+
5
+ namespace torch::distributed::autograd {
6
+
7
+ PyMethodDef* python_functions();
8
+
9
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/Export.h>
4
+ #include <cstdint>
5
+
6
+ namespace torch::distributed::autograd {
7
+
8
+ // This structure represents autograd metadata that we need to pass across
9
+ // different nodes when we call an RPC which needs autograd computation.
10
+ struct TORCH_API AutogradMetadata {
11
+ AutogradMetadata(int64_t autogradContextId, int64_t autogradMessageId);
12
+
13
+ // autogradContextId_ is a globally unique integer that identifies a
14
+ // particular distributed autograd pass.
15
+ int64_t autogradContextId;
16
+ // autogradMessageId_ is a globally unique integer that identifies a pair
17
+ // of send/recv autograd functions.
18
+ int64_t autogradMessageId;
19
+ };
20
+
21
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_req.h ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h>
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
+ // Used to request other workers to clean up their autograd context.
10
+ class TORCH_API CleanupAutogradContextReq : public rpc::RpcCommandBase {
11
+ public:
12
+ explicit CleanupAutogradContextReq(int64_t context_id);
13
+ // Serialization and deserialization methods.
14
+ c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
15
+ static std::unique_ptr<CleanupAutogradContextReq> fromMessage(
16
+ const rpc::Message& message);
17
+
18
+ // Retrieve the context id we are cleaning up with this message.
19
+ int64_t getContextId();
20
+
21
+ private:
22
+ int64_t context_id_;
23
+ };
24
+
25
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/cleanup_autograd_context_resp.h ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/rpc/message.h>
4
+ #include <torch/csrc/distributed/rpc/rpc_command_base.h>
5
+
6
+ namespace torch::distributed::autograd {
7
+
8
+ // Empty response for CleanupAutogradContextReq. Send to acknowledge receipt of
9
+ // a CleanupAutogradContextReq.
10
+ class TORCH_API CleanupAutogradContextResp : public rpc::RpcCommandBase {
11
+ public:
12
+ CleanupAutogradContextResp() = default;
13
+ // Serialization and deserialization methods.
14
+ c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
15
+ static std::unique_ptr<CleanupAutogradContextResp> fromMessage(
16
+ const rpc::Message& message);
17
+ };
18
+
19
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/propagate_gradients_req.h ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h>
4
+ #include <torch/csrc/distributed/rpc/message.h>
5
+ #include <torch/csrc/distributed/rpc/rpc_command_base.h>
6
+ #include <vector>
7
+
8
+ namespace torch::distributed::autograd {
9
+
10
+ // Used to propagate gradients from one node to another during a distributed
11
+ // backwards pass. This RPC call is invoked when we hit a `recv` autograd
12
+ // function during backward pass execution.
13
+ class TORCH_API PropagateGradientsReq : public rpc::RpcCommandBase {
14
+ public:
15
+ PropagateGradientsReq(
16
+ const AutogradMetadata& autogradMetadata,
17
+ std::vector<torch::autograd::Variable> grads,
18
+ bool retainGraph = false);
19
+
20
+ const AutogradMetadata& getAutogradMetadata();
21
+
22
+ const std::vector<torch::autograd::Variable>& getGrads();
23
+
24
+ // Serialization and deserialization methods.
25
+ c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
26
+ static std::unique_ptr<PropagateGradientsReq> fromMessage(
27
+ const rpc::Message& message);
28
+
29
+ // Whether or not to retain the autograd graph.
30
+ bool retainGraph();
31
+
32
+ private:
33
+ AutogradMetadata autogradMetadata_;
34
+ std::vector<torch::autograd::Variable> grads_;
35
+ bool retainGraph_;
36
+ };
37
+
38
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/propagate_gradients_resp.h ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/rpc/message.h>
4
+ #include <torch/csrc/distributed/rpc/rpc_command_base.h>
5
+
6
+ namespace torch::distributed::autograd {
7
+
8
+ // Response for the PropagateGradients call. Currently, this class is mostly
9
+ // just a placeholder and sends an empty message over the wire. The purpose of
10
+ // this RPC command is to indicate whether or not the PropagateGradientsReq call
11
+ // was successfully or not.
12
+ class TORCH_API PropagateGradientsResp : public rpc::RpcCommandBase {
13
+ public:
14
+ PropagateGradientsResp() = default;
15
+ c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
16
+ static std::unique_ptr<PropagateGradientsResp> fromMessage(
17
+ const rpc::Message& message);
18
+ };
19
+
20
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_autograd.h ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/autograd/rpc_messages/autograd_metadata.h>
4
+ #include <torch/csrc/distributed/rpc/rpc_agent.h>
5
+ #include <torch/csrc/distributed/rpc/rpc_command_base.h>
6
+
7
+ namespace torch::distributed::autograd {
8
+
9
+ // Represents an RPC that includes autograd information. This class basically
10
+ // wraps another `RpcCommandBase` object which represents the actual RPC and has
11
+ // additional autograd information associated with that RPC.
12
+ class TORCH_API RpcWithAutograd final : public rpc::RpcCommandBase {
13
+ public:
14
+ // Used when we are sending an RPC over the wire.
15
+ RpcWithAutograd(
16
+ rpc::worker_id_t fromWorkerId,
17
+ rpc::MessageType messageType,
18
+ const AutogradMetadata& autogradMetadata,
19
+ c10::intrusive_ptr<rpc::Message> wrappedMessage,
20
+ rpc::DeviceMap deviceMap = {});
21
+
22
+ // Used when receiving an RPC over the wire.
23
+ RpcWithAutograd(
24
+ rpc::worker_id_t fromWorkerId,
25
+ rpc::MessageType messageType,
26
+ const AutogradMetadata& autogradMetadata,
27
+ std::unique_ptr<rpc::RpcCommandBase> wrappedRpc,
28
+ rpc::MessageType wrappedMessageType,
29
+ std::vector<torch::Tensor> tensors,
30
+ rpc::DeviceMap deviceMap = {});
31
+
32
+ c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
33
+
34
+ static std::unique_ptr<RpcWithAutograd> fromMessage(
35
+ const rpc::Message& message);
36
+
37
+ // Retrieves tensors as part of this RPC, which need to be considered for
38
+ // autograd computations.
39
+ std::vector<torch::Tensor>& tensors();
40
+
41
+ const AutogradMetadata& autogradMetadata() const;
42
+
43
+ RpcCommandBase& wrappedRpc();
44
+
45
+ void setWrappedRpc(std::unique_ptr<RpcCommandBase> wrappedRpc);
46
+
47
+ std::unique_ptr<RpcCommandBase> moveWrappedRpc() &&;
48
+
49
+ // Message type of the wrapped RPC.
50
+ rpc::MessageType wrappedMessageType() const;
51
+
52
+ // Retrieve the worker id from which the RPC originated.
53
+ rpc::worker_id_t fromWorkerId() const;
54
+
55
+ // Retrieve the device map.
56
+ const rpc::DeviceMap& deviceMap();
57
+
58
+ private:
59
+ // WorkerId from which this RPC originated. This is necessary for knowing
60
+ // which worker we need to contact during the backward pass.
61
+ rpc::worker_id_t fromWorkerId_;
62
+
63
+ // Message type for this call.
64
+ rpc::MessageType messageType_;
65
+
66
+ AutogradMetadata autogradMetadata_;
67
+
68
+ // Since wrappedMessage_ is destructively constructed from wrappedRpc_,
69
+ // they are valid exclusively. They are used for different purpose.
70
+ // wrappedRpc_ is used while constructing receive rpcWithAutograd;
71
+ // wrappedMessage_ is used while constructing send rpcWithAutograd;
72
+
73
+ // When receive rpcWithAutograd is constructed fromMessage, it is valid;
74
+ // When send rpcWithAutograd is constructed before toMessage, it is nullptr;
75
+ std::unique_ptr<RpcCommandBase> wrappedRpc_;
76
+
77
+ // Serialized message representing wrappedRpc_. Used mostly as a cache to
78
+ // avoid serializing the request twice.
79
+ // When receive rpcWithAutograd is constructed fromMessage, it is nullptr;
80
+ // When send rpcWithAutograd is constructed before toMessage, it is valid;
81
+ c10::intrusive_ptr<rpc::Message> wrappedMessage_;
82
+
83
+ // message type of the wrappedMessage, this is stored separately since
84
+ // wrappedMessage_ is not always guaranteed to be populated.
85
+ rpc::MessageType wrappedMessageType_;
86
+
87
+ // Tensors part of the wrappedRpc that need to be considered for autograd.
88
+ std::vector<torch::Tensor> tensors_;
89
+
90
+ // Device mapping for tensors that are sent across an RPC to another node.
91
+ rpc::DeviceMap deviceMap_;
92
+ };
93
+
94
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_profiling_req.h ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/autograd/profiler.h>
4
+ #include <torch/csrc/distributed/rpc/message.h>
5
+ #include <torch/csrc/distributed/rpc/rpc_agent.h>
6
+ #include <torch/csrc/distributed/rpc/rpc_command_base.h>
7
+ #include <torch/csrc/distributed/rpc/types.h>
8
+
9
+ namespace torch::distributed::autograd {
10
+
11
+ class TORCH_API RpcWithProfilingReq : public rpc::RpcCommandBase {
12
+ public:
13
+ // For sending RPCs, invoked when client is creating this RPC command.
14
+ RpcWithProfilingReq(
15
+ rpc::MessageType messageType,
16
+ c10::intrusive_ptr<rpc::Message> wrappedMessage,
17
+ torch::autograd::profiler::ProfilerConfig&& profilerConfig,
18
+ rpc::ProfilingId profilingKeyId);
19
+
20
+ // For receiving an RPC
21
+ // Used in fromMessage.
22
+ RpcWithProfilingReq(
23
+ rpc::MessageType messageType,
24
+ std::unique_ptr<rpc::RpcCommandBase> wrappedRpc,
25
+ rpc::MessageType wrappedMessageType,
26
+ std::vector<torch::Tensor> tensors,
27
+ torch::autograd::profiler::ProfilerConfig&& profilerConfig,
28
+ rpc::ProfilingId profilingKeyId);
29
+
30
+ // Convert this RPC Command to a Message that can be sent over the wire.
31
+ c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
32
+ static std::unique_ptr<RpcWithProfilingReq> fromMessage(
33
+ const rpc::Message& message);
34
+
35
+ // Retrieve the profiling data that is associated with this command.
36
+ torch::autograd::profiler::ProfilerConfig getProfilingConfig() const;
37
+ // Retrieve the globally unique profiling ID corresponding to this command.
38
+ const rpc::ProfilingId& getProfilingId() const;
39
+ // Retrieve the original RPC which this ProfilingRPC wraps.
40
+ RpcCommandBase& wrappedRpc();
41
+ // Destructively move the wrapped RPC.
42
+ std::unique_ptr<RpcCommandBase> moveWrappedRpc() &&;
43
+ // Message type of the wrapped RPC
44
+ rpc::MessageType wrappedMessageType() const;
45
+ void setWrappedRpc(std::unique_ptr<RpcCommandBase> wrappedRpc);
46
+
47
+ private:
48
+ // message type
49
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
50
+ const rpc::MessageType messageType_;
51
+ // wrapped message
52
+ c10::intrusive_ptr<rpc::Message> wrappedMessage_;
53
+ std::unique_ptr<RpcCommandBase> wrappedRpc_;
54
+ rpc::MessageType wrappedMessageType_;
55
+ std::vector<torch::Tensor> tensors_;
56
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
57
+ const torch::autograd::profiler::ProfilerConfig profilerConfig_;
58
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
59
+ const rpc::ProfilingId profilingKeyId_;
60
+ };
61
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rpc_with_profiling_resp.h ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/autograd/profiler.h>
4
+ #include <torch/csrc/distributed/rpc/message.h>
5
+ #include <torch/csrc/distributed/rpc/rpc_agent.h>
6
+ #include <torch/csrc/distributed/rpc/rpc_command_base.h>
7
+ #include <torch/csrc/distributed/rpc/types.h>
8
+
9
+ namespace torch::distributed::autograd {
10
+ class TORCH_API RpcWithProfilingResp : public rpc::RpcCommandBase {
11
+ public:
12
+ // For sending RPCs over the wire
13
+ RpcWithProfilingResp(
14
+ rpc::MessageType messageType,
15
+ c10::intrusive_ptr<rpc::Message> wrappedMessage,
16
+ std::vector<torch::autograd::profiler::LegacyEvent> profiledEvents,
17
+ rpc::ProfilingId profilingId);
18
+
19
+ // For receiving RPCs. Used in from message when converting a message received
20
+ // over the wire.
21
+ RpcWithProfilingResp(
22
+ rpc::MessageType messageType,
23
+ std::unique_ptr<rpc::RpcCommandBase> wrappedRpc,
24
+ rpc::MessageType wrappedMessageType,
25
+ std::vector<torch::Tensor> tensors,
26
+ std::vector<torch::autograd::profiler::LegacyEvent> profiledEvents,
27
+ rpc::ProfilingId profilingId);
28
+ c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
29
+ static std::unique_ptr<RpcWithProfilingResp> fromMessage(
30
+ const rpc::Message& message);
31
+ // Retrieve remote Events
32
+ std::vector<torch::autograd::profiler::LegacyEvent> getProfiledEvents() const;
33
+ // Retrieve the globally unique profiling ID corresponding to this command.
34
+ const rpc::ProfilingId& getProfilingId() const;
35
+ // Retrieve the original RPC which this ProfilingRPC wraps.
36
+ RpcCommandBase& wrappedRpc();
37
+ // Destructively move the wrapped RPC.
38
+ std::unique_ptr<RpcCommandBase> moveWrappedRpc() &&;
39
+ // Message type of the wrapped RPC
40
+ rpc::MessageType wrappedMessageType() const;
41
+ // Set the wrapped RPC for this RPC.
42
+ void setWrappedRpc(std::unique_ptr<RpcCommandBase> wrappedRpc);
43
+
44
+ private:
45
+ // message type
46
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
47
+ const rpc::MessageType messageType_;
48
+ // wrapped message
49
+ c10::intrusive_ptr<rpc::Message> wrappedMessage_;
50
+ std::unique_ptr<RpcCommandBase> wrappedRpc_;
51
+ rpc::MessageType wrappedMessageType_;
52
+ std::vector<torch::Tensor> tensors_;
53
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
54
+ const std::vector<torch::autograd::profiler::LegacyEvent> profiledEvents_;
55
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
56
+ const rpc::ProfilingId profilingId_;
57
+ };
58
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rref_backward_req.h ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/rpc/message.h>
4
+ #include <torch/csrc/distributed/rpc/rpc_command_base.h>
5
+ #include <torch/csrc/distributed/rpc/types.h>
6
+
7
+ namespace torch::distributed::autograd {
8
+
9
+ // Internal system RPC to invoke distributed backward pass on remote nodes when
10
+ // 'rref.backward()' is invoked.
11
+ class TORCH_API RRefBackwardReq : public rpc::RpcCommandBase {
12
+ public:
13
+ RRefBackwardReq(
14
+ const rpc::RRefId& rrefId,
15
+ int64_t autogradContextId,
16
+ bool retainGraph = false);
17
+
18
+ const rpc::RRefId& getRRefId() const;
19
+
20
+ int64_t getAutogradContextId() const;
21
+
22
+ bool retainGraph() const;
23
+
24
+ // Serialization and deserialization methods.
25
+ c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
26
+ static std::unique_ptr<RRefBackwardReq> fromMessage(
27
+ const rpc::Message& message);
28
+
29
+ private:
30
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
31
+ const rpc::RRefId rrefId_;
32
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
33
+ const int64_t autogradContextId_;
34
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
35
+ const bool retainGraph_;
36
+ };
37
+
38
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/rpc_messages/rref_backward_resp.h ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/rpc/message.h>
4
+ #include <torch/csrc/distributed/rpc/rpc_command_base.h>
5
+
6
+ namespace torch::distributed::autograd {
7
+
8
+ // Response for the RRefBackwardReq.
9
+ class TORCH_API RRefBackwardResp : public rpc::RpcCommandBase {
10
+ public:
11
+ RRefBackwardResp() = default;
12
+ c10::intrusive_ptr<rpc::Message> toMessageImpl() && override;
13
+ static std::unique_ptr<RRefBackwardResp> fromMessage(
14
+ const rpc::Message& message);
15
+ };
16
+
17
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/autograd/utils.h ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/autograd/context/context.h>
4
+ #include <torch/csrc/distributed/autograd/rpc_messages/rpc_with_autograd.h>
5
+ #include <torch/csrc/distributed/autograd/rpc_messages/rpc_with_profiling_req.h>
6
+ #include <torch/csrc/distributed/autograd/rpc_messages/rpc_with_profiling_resp.h>
7
+
8
+ namespace torch::distributed::autograd {
9
+
10
+ // This method is used to attach the 'send' autograd function to the autograd
11
+ // graph when we use RPC. This method creates a new 'send' autograd function
12
+ // and attaches the provided tensors as next_edges to the 'send' function. In
13
+ // addition to this, it also registers the send function in the provided
14
+ // autograd context. Finally, the RPC message is updated with appropriate
15
+ // autograd information for the recipient.
16
+ TORCH_API void addSendRpcBackward(
17
+ const ContextPtr& autogradContext,
18
+ const AutogradMetadata& autogradMetadata,
19
+ std::vector<torch::Tensor>& tensors);
20
+
21
+ // This method is used to attach the 'recv' autograd function to the autograd
22
+ // graph when we use RPC. This method creates a new 'recv' autograd function
23
+ // and attaches the provided tensors as inputs to the 'recv' function. It
24
+ // creates a new autograd context if needed and registers the 'recv' function
25
+ // with this context.
26
+ //
27
+ // Returns a pointer to the autograd context created.
28
+ TORCH_API ContextPtr addRecvRpcBackward(
29
+ const AutogradMetadata& autogradMetadata,
30
+ std::vector<torch::Tensor>& tensors,
31
+ rpc::worker_id_t fromWorkerId,
32
+ const rpc::DeviceMap& deviceMap);
33
+
34
+ // This method is a wrapper utility used internally to wrap autograd info
35
+ // and attach autograd function for each type of rpc call if it has valid
36
+ // context and tensors require grads or forceGradRecording is true, in this
37
+ // case, return RpcWithAutograd message; otherwise return original rpc message.
38
+ // NB: forceGradRecording is useful when the request does not contain any tensor
39
+ // but the corresponding response does.
40
+ TORCH_API c10::intrusive_ptr<rpc::Message> getMessageWithAutograd(
41
+ const rpc::worker_id_t dstId,
42
+ c10::intrusive_ptr<rpc::Message> wrappedRpcMsg,
43
+ rpc::MessageType msgType,
44
+ bool forceGradRecording = false,
45
+ const rpc::DeviceMap& deviceMap = {});
46
+
47
+ // Send message after autograd checking
48
+ TORCH_API c10::intrusive_ptr<c10::ivalue::Future> sendMessageWithAutograd(
49
+ rpc::RpcAgent& agent,
50
+ const rpc::WorkerInfo& dst,
51
+ c10::intrusive_ptr<rpc::Message> wrappedRpcMsg,
52
+ bool forceGradRecording = false,
53
+ const float rpcTimeoutSeconds = torch::distributed::rpc::kUnsetRpcTimeout,
54
+ bool forceDisableProfiling = false);
55
+
56
+ } // namespace torch::distributed::autograd
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/Backend.hpp ADDED
@@ -0,0 +1,471 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <utility>
5
+ #include <vector>
6
+
7
+ #include <ATen/ATen.h>
8
+ #include <c10/core/Allocator.h>
9
+ #include <c10/macros/Macros.h>
10
+
11
+ #include <torch/csrc/distributed/c10d/Types.hpp>
12
+ #include <torch/csrc/distributed/c10d/Utils.hpp>
13
+ #include <torch/csrc/distributed/c10d/Work.hpp>
14
+ #include <torch/csrc/distributed/c10d/debug.h>
15
+
16
+ constexpr auto kBackendDefaultTimeout =
17
+ std::chrono::milliseconds(30 * 60 * 1000);
18
+
19
+ namespace c10d {
20
+
21
+ enum class ErrorType {
22
+ SUCCESS = 0,
23
+ TIMEOUT = 1,
24
+ // e.g., NCCL error, etc
25
+ COMM_ERROR = 2,
26
+ // TODO, do we need to distinguish between remote timeout or remote COMM
27
+ // errors?
28
+ REMOTE_ERROR = 3
29
+ };
30
+
31
+ class TORCH_API Backend : public torch::CustomClassHolder {
32
+ public:
33
+ // Backend Options is a base struct that defines the basic options
34
+ // when constructing a Backend. Each Backend subclass should
35
+ // extend this struct and define its options if it wants to provide more
36
+ // config options (beyond basic ones defined here) to end user.
37
+ struct TORCH_API Options : torch::CustomClassHolder {
38
+ explicit Options(
39
+ std::string backend,
40
+ std::chrono::milliseconds timeout = kBackendDefaultTimeout)
41
+ : timeout(timeout), backend(std::move(backend)) {}
42
+ ~Options() override = default;
43
+
44
+ std::chrono::milliseconds timeout;
45
+
46
+ // backend name
47
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
48
+ const std::string backend;
49
+ };
50
+
51
+ explicit Backend(int rank, int size);
52
+ ~Backend() override = 0;
53
+
54
+ int getRank() const {
55
+ return rank_;
56
+ }
57
+
58
+ int getSize() const {
59
+ return size_;
60
+ }
61
+
62
+ // Returns an unique opaque ID of this backend that can be used to correlate
63
+ // with its collectives.
64
+ int64_t getID() const {
65
+ return reinterpret_cast<std::intptr_t>(this);
66
+ }
67
+
68
+ virtual bool supportsSplitting() const {
69
+ return false;
70
+ }
71
+
72
+ virtual bool supportsCoalescing() const {
73
+ return false;
74
+ }
75
+
76
+ virtual bool supportsTimeEstimation() const {
77
+ return false;
78
+ }
79
+
80
+ virtual void startCoalescing() {
81
+ TORCH_CHECK(
82
+ false,
83
+ c10::str(
84
+ "Backend ",
85
+ getBackendName(),
86
+ " does not implement startCoalescing"));
87
+ }
88
+
89
+ virtual c10::intrusive_ptr<Work> endCoalescing() {
90
+ TORCH_CHECK(
91
+ false,
92
+ c10::str(
93
+ "Backend ", getBackendName(), " does not implement endCoalescing"));
94
+ }
95
+
96
+ // Subclasses must override this method to return the backend name
97
+ virtual const std::string getBackendName() const {
98
+ TORCH_INTERNAL_ASSERT(false, "getBackendName is not implemented.");
99
+ }
100
+
101
+ virtual c10::intrusive_ptr<Work> broadcast(
102
+ std::vector<at::Tensor>& /* tensors */,
103
+ const BroadcastOptions& /* opts */ = BroadcastOptions()) {
104
+ TORCH_CHECK(
105
+ false,
106
+ c10::str("Backend ", getBackendName(), " does not support broadcast"));
107
+ }
108
+
109
+ virtual c10::intrusive_ptr<Work> allreduce(
110
+ std::vector<at::Tensor>& /* tensors */,
111
+ const AllreduceOptions& /* opts */ = AllreduceOptions()) {
112
+ TORCH_CHECK(
113
+ false,
114
+ c10::str("Backend ", getBackendName(), " does not support allreduce"));
115
+ }
116
+
117
+ virtual c10::intrusive_ptr<Work> allreduce_sparse(
118
+ std::vector<at::Tensor>& /* tensors */,
119
+ const AllreduceOptions& /* opts */ = AllreduceOptions()) {
120
+ TORCH_CHECK(
121
+ false,
122
+ c10::str(
123
+ "Backend ",
124
+ getBackendName(),
125
+ " does not support allreduce sparse"));
126
+ }
127
+
128
+ virtual c10::intrusive_ptr<Work> allreduce_coalesced(
129
+ std::vector<at::Tensor>& /* tensors */,
130
+ const AllreduceCoalescedOptions& /* opts */ =
131
+ AllreduceCoalescedOptions()) {
132
+ TORCH_CHECK(
133
+ false,
134
+ c10::str(
135
+ "Backend ",
136
+ getBackendName(),
137
+ " does not support allreduce_coalesced"));
138
+ }
139
+
140
+ virtual c10::intrusive_ptr<Work> reduce(
141
+ std::vector<at::Tensor>& /* tensors */,
142
+ const ReduceOptions& /* opts */ = ReduceOptions()) {
143
+ TORCH_CHECK(
144
+ false,
145
+ c10::str("Backend ", getBackendName(), " does not support reduce"));
146
+ }
147
+
148
+ virtual c10::intrusive_ptr<Work> allgather(
149
+ std::vector<std::vector<at::Tensor>>& /* outputTensors */,
150
+ std::vector<at::Tensor>& /* inputTensors */,
151
+ const AllgatherOptions& /* opts */ = AllgatherOptions()) {
152
+ TORCH_CHECK(
153
+ false,
154
+ c10::str("Backend ", getBackendName(), " does not support allgather"));
155
+ }
156
+
157
+ // Gathers a single tensor inputBuffer into a single buffer outputBuffer that
158
+ // is interpreted as a contiguous collection of size inputBuffer * WORLD_SIZE.
159
+ // For implementers of ProcessGroup API and advanced users only.
160
+ // Note: this function will be deprecated in near future.
161
+ virtual c10::intrusive_ptr<Work> _allgather_base(
162
+ at::Tensor& /* outputBuffer */,
163
+ at::Tensor& /* inputBuffer */,
164
+ const AllgatherOptions& /* opts */ = AllgatherOptions()) {
165
+ TORCH_CHECK(
166
+ false,
167
+ c10::str(
168
+ "Backend ", getBackendName(), " does not support _allgather_base"));
169
+ }
170
+
171
+ // This function is deprecated and will be moved out of Backend to comms:
172
+ // * do not add dependencies on this function,
173
+ // * do not implement it in your Backend, implement _allgather_base
174
+ // instead.
175
+ virtual c10::intrusive_ptr<Work> allgather_coalesced(
176
+ std::vector<std::vector<at::Tensor>>& /* outputTensorLists */,
177
+ std::vector<at::Tensor>& /* inputTensors */,
178
+ const AllgatherOptions& /* opts */ = AllgatherOptions()) {
179
+ TORCH_CHECK(
180
+ false,
181
+ c10::str(
182
+ "Backend ",
183
+ getBackendName(),
184
+ " does not support allgather_coalesced"));
185
+ }
186
+
187
+ // This function is a coalesced version of `allgather_into_tensor` (currently
188
+ // still named as `_allgather_base`). Each tensor in the vector corresponds to
189
+ // an input/output of one `allgather_into_tensor` operation.
190
+ virtual c10::intrusive_ptr<Work> allgather_into_tensor_coalesced(
191
+ std::vector<at::Tensor>& /* outputs */,
192
+ std::vector<at::Tensor>& /* inputs */,
193
+ const AllgatherOptions& /* opts */ = AllgatherOptions()) {
194
+ TORCH_CHECK(
195
+ false,
196
+ c10::str(
197
+ "Backend ",
198
+ getBackendName(),
199
+ " does not support allgather_into_tensor_coalesced"));
200
+ }
201
+
202
+ virtual c10::intrusive_ptr<Work> gather(
203
+ std::vector<std::vector<at::Tensor>>& /* outputTensors */,
204
+ std::vector<at::Tensor>& /* inputTensors */,
205
+ const GatherOptions& /* opts */ = GatherOptions()) {
206
+ TORCH_CHECK(
207
+ false,
208
+ c10::str("Backend ", getBackendName(), " does not support gather"));
209
+ }
210
+
211
+ virtual c10::intrusive_ptr<Work> scatter(
212
+ std::vector<at::Tensor>& /* outputTensors */,
213
+ std::vector<std::vector<at::Tensor>>& /* inputTensors */,
214
+ const ScatterOptions& /* opts */ = ScatterOptions()) {
215
+ TORCH_CHECK(
216
+ false,
217
+ c10::str("Backend ", getBackendName(), " does not support scatter"));
218
+ }
219
+
220
+ virtual c10::intrusive_ptr<Work> reduce_scatter(
221
+ std::vector<at::Tensor>& /* outputTensors */,
222
+ std::vector<std::vector<at::Tensor>>& /* inputTensors */,
223
+ const ReduceScatterOptions& /* opts */ = ReduceScatterOptions()) {
224
+ TORCH_CHECK(
225
+ false,
226
+ c10::str(
227
+ "Backend ", getBackendName(), " does not support reduce_scatter"));
228
+ }
229
+
230
+ virtual c10::intrusive_ptr<Work> _reduce_scatter_base(
231
+ at::Tensor& /* outputBuffer */,
232
+ at::Tensor& /* inputBuffer */,
233
+ const ReduceScatterOptions& /* opts */ = ReduceScatterOptions()) {
234
+ TORCH_CHECK(
235
+ false,
236
+ c10::str(
237
+ "Backend ",
238
+ getBackendName(),
239
+ " does not support _reduce_scatter_base"));
240
+ }
241
+
242
+ // This function is a coalesced version of `reduce_scatter_tensor` (currently
243
+ // still named as `_reduce_scatter_base`). Each tensor in the vector
244
+ // corresponds to an input/output of one `reduce_scatter_tensor` operation.
245
+ virtual c10::intrusive_ptr<Work> reduce_scatter_tensor_coalesced(
246
+ std::vector<at::Tensor>& /* outputs */,
247
+ std::vector<at::Tensor>& /* inputs */,
248
+ const ReduceScatterOptions& /* opts */ = ReduceScatterOptions()) {
249
+ TORCH_CHECK(
250
+ false,
251
+ c10::str(
252
+ "Backend ",
253
+ getBackendName(),
254
+ " does not support reduce_scatter_tensor_coalesced"));
255
+ }
256
+
257
+ virtual c10::intrusive_ptr<Work> alltoall_base(
258
+ at::Tensor& /* outputBuffer */,
259
+ at::Tensor& /* inputBuffer */,
260
+ std::vector<int64_t>& /* outputSplitSizes */,
261
+ std::vector<int64_t>& /* inputSplitSizes */,
262
+ const AllToAllOptions& /* opts */ = AllToAllOptions()) {
263
+ TORCH_CHECK(
264
+ false,
265
+ c10::str(
266
+ "Backend ", getBackendName(), " does not support alltoall_base"));
267
+ }
268
+
269
+ virtual c10::intrusive_ptr<Work> alltoall(
270
+ std::vector<at::Tensor>& /* outputTensors */,
271
+ std::vector<at::Tensor>& /* inputTensors */,
272
+ const AllToAllOptions& opts = AllToAllOptions()) {
273
+ TORCH_CHECK(
274
+ false,
275
+ c10::str("Backend ", getBackendName(), " does not support alltoall"));
276
+ }
277
+
278
+ virtual void monitoredBarrier(
279
+ const BarrierOptions& /* unused */,
280
+ bool /* unused */ = false) {
281
+ auto backendName = getBackendName();
282
+ TORCH_CHECK(
283
+ false,
284
+ c10::str(
285
+ "Backend ",
286
+ backendName,
287
+ " does not support monitoredBarrier, only GLOO supports monitored barrier."));
288
+ }
289
+
290
+ // Agrees on an initial sequence number for the whole group by having rank 0
291
+ // create it and broadcast it to other ranks using the store. Only implemented
292
+ // for GLOO and NCCL backends currently.
293
+ virtual void setSequenceNumberForGroup() {
294
+ auto backendName = getBackendName();
295
+ TORCH_CHECK(
296
+ false,
297
+ c10::str(
298
+ "Backend ",
299
+ backendName,
300
+ " does not yet support sequence numbers."));
301
+ }
302
+
303
+ // Retrieves the current sequence number for the whole group, which should be
304
+ // in sync. If the returned number is not consistent across the group, it
305
+ // may indicate that there is some sort of collective desynchronization.
306
+ virtual uint64_t getSequenceNumberForGroup() {
307
+ auto backendName = getBackendName();
308
+ TORCH_CHECK(
309
+ false,
310
+ c10::str(
311
+ "Backend ",
312
+ backendName,
313
+ " does not yet support sequence numbers."));
314
+ }
315
+
316
+ virtual c10::intrusive_ptr<Work> send(
317
+ std::vector<at::Tensor>& /* tensors */,
318
+ int /* dstRank */,
319
+ int /* tag */) {
320
+ TORCH_CHECK(
321
+ false,
322
+ c10::str("Backend ", getBackendName(), " does not support send"));
323
+ }
324
+
325
+ virtual c10::intrusive_ptr<Work> recv(
326
+ std::vector<at::Tensor>& /* tensors */,
327
+ int /* srcRank */,
328
+ int /* tag */) {
329
+ TORCH_CHECK(
330
+ false,
331
+ c10::str("Backend ", getBackendName(), " does not support recv"));
332
+ }
333
+
334
+ virtual c10::intrusive_ptr<Work> recvAnysource(
335
+ std::vector<at::Tensor>& /* tensors */,
336
+ int /* tag */) {
337
+ TORCH_CHECK(
338
+ false,
339
+ c10::str(
340
+ "Backend ", getBackendName(), " does not support recvAnysource"));
341
+ }
342
+
343
+ virtual c10::intrusive_ptr<Work> barrier(
344
+ const BarrierOptions& /* opts */ = BarrierOptions()) {
345
+ TORCH_CHECK(
346
+ false,
347
+ c10::str("Backend ", getBackendName(), " does not support barrier"));
348
+ }
349
+
350
+ virtual void registerOnCompletionHook(
351
+ std::function<void(std::shared_ptr<WorkInfo>)>&& hook) {
352
+ TORCH_CHECK(
353
+ false,
354
+ "Only ProcessGrouppNCCL supports onCompletion hook, but got ",
355
+ getBackendName(),
356
+ " backend.");
357
+ }
358
+
359
+ virtual void waitForPendingWorks() {
360
+ TORCH_CHECK(
361
+ false,
362
+ "Only ProcessGrouppNCCL supports waitForPendingWorks, but got ",
363
+ getBackendName(),
364
+ " backend.");
365
+ }
366
+
367
+ virtual void enableCollectivesTiming() {
368
+ TORCH_CHECK(
369
+ false,
370
+ "Backend ",
371
+ getBackendName(),
372
+ " is missing implementation of enableCollectivesTiming.");
373
+ }
374
+
375
+ bool hasHooks() const {
376
+ return onCompletionHook_ != nullptr;
377
+ }
378
+
379
+ // Do not call this directly, use ProcessGroup::setGroupName instead.
380
+ void setGroupUid(const std::string& pg_uid) {
381
+ pg_uid_ = pg_uid;
382
+ }
383
+
384
+ const std::string& getGroupUid() const {
385
+ return pg_uid_;
386
+ }
387
+
388
+ void setGroupDesc(const std::string& desc) {
389
+ pg_desc_ = desc;
390
+ }
391
+
392
+ const std::string& getGroupDesc() const {
393
+ return pg_desc_;
394
+ }
395
+
396
+ // See similar functions in ProcessGroup.hpp for context.
397
+ std::optional<at::Device> getBoundDeviceId() const {
398
+ return bound_device_id_;
399
+ }
400
+
401
+ // Perform an eager connect to the specified device if the backend supports
402
+ // it.
403
+ virtual void eagerConnectSingleDevice(at::Device device) {
404
+ // no-op in the default case; this is an optimization some
405
+ // backends may perform
406
+ }
407
+
408
+ void setBoundDeviceId(std::optional<at::Device> device) {
409
+ if (device) {
410
+ TORCH_CHECK(device->has_index(), "setBoundDeviceId must have an index");
411
+ }
412
+ bound_device_id_ = device;
413
+ }
414
+
415
+ virtual ErrorType getError() {
416
+ TORCH_CHECK(
417
+ false,
418
+ c10::str("Backend ", getBackendName(), " does not support getError"));
419
+ }
420
+
421
+ virtual std::shared_ptr<c10::Allocator> getMemAllocator() {
422
+ TORCH_CHECK(
423
+ false,
424
+ c10::str(
425
+ "Backend ", getBackendName(), " does not support getMemAllocator"));
426
+ }
427
+
428
+ // Allocate tensor (aten::empty) from backend's communication-optimized memory
429
+ // pool
430
+ virtual at::Tensor allocateTensor(long size, at::TensorOptions options = {}) {
431
+ TORCH_CHECK(
432
+ false,
433
+ c10::str(
434
+ "Backend ", getBackendName(), " does not support allocateTensor"));
435
+ }
436
+
437
+ // Returns true if backend supports tensor allocation
438
+ virtual bool supportsTensorAlloc(c10::DeviceIndex deviceIdx) {
439
+ // Change to true in concrete backend if supported
440
+ return false;
441
+ }
442
+
443
+ // Aborts all pending operations and connections in the backend if the backend
444
+ // supports it.
445
+ virtual void abort() {}
446
+
447
+ // Shutdown the backend if the backend supports it. This should be used for
448
+ // normal shutdown.
449
+ virtual void shutdown() {}
450
+
451
+ protected:
452
+ // Implementations of this interface need to call this to setup
453
+ // appropriate logging etc.
454
+ void init();
455
+
456
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
457
+ const int rank_;
458
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
459
+ const int size_;
460
+ // Debug level setting. It is parsed once when ProcessGroup is constructed and
461
+ // remains the same across use of this process group.
462
+ DebugLevel dist_debug_level_;
463
+ std::string pg_uid_;
464
+ std::string pg_desc_;
465
+
466
+ std::function<void(std::shared_ptr<WorkInfo>)> onCompletionHook_;
467
+
468
+ std::optional<at::Device> bound_device_id_;
469
+ };
470
+
471
+ } // namespace c10d
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/Backoff.hpp ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <chrono>
4
+ #include <random>
5
+ #include <thread>
6
+
7
+ #include <c10/macros/Macros.h>
8
+
9
+ namespace c10d {
10
+
11
+ class TORCH_API Backoff {
12
+ public:
13
+ virtual ~Backoff() = default;
14
+
15
+ virtual std::chrono::milliseconds nextBackoff() = 0;
16
+ virtual void reset() = 0;
17
+
18
+ void sleepBackoff() {
19
+ std::this_thread::sleep_for(nextBackoff());
20
+ }
21
+ };
22
+
23
+ class TORCH_API ExponentialBackoffWithJitter : public Backoff {
24
+ public:
25
+ ExponentialBackoffWithJitter();
26
+
27
+ std::chrono::milliseconds nextBackoff() override;
28
+ void reset() override;
29
+
30
+ public:
31
+ std::chrono::milliseconds initialInterval{500};
32
+ double randomizationFactor{0.5};
33
+ double multiplier{1.5};
34
+ std::chrono::milliseconds maxInterval{60000};
35
+
36
+ private:
37
+ std::mt19937 gen_;
38
+ std::chrono::milliseconds currentInterval_{0};
39
+ };
40
+
41
+ class TORCH_API FixedBackoff : public Backoff {
42
+ public:
43
+ FixedBackoff(std::chrono::milliseconds interval);
44
+
45
+ std::chrono::milliseconds nextBackoff() override;
46
+ void reset() override;
47
+
48
+ private:
49
+ std::chrono::milliseconds interval_;
50
+ };
51
+
52
+ } // namespace c10d
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/FakeProcessGroup.hpp ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/c10d/Backend.hpp>
4
+
5
+ namespace c10d {
6
+
7
+ class FakeWork : public Work {
8
+ public:
9
+ int seq_id = -1;
10
+ bool wait(std::chrono::milliseconds timeout = kNoTimeout) override {
11
+ return true;
12
+ }
13
+
14
+ c10::intrusive_ptr<c10::ivalue::Future> getFuture() override {
15
+ auto fut = c10::make_intrusive<c10::ivalue::Future>(c10::NoneType::get());
16
+ fut->markCompleted();
17
+ return fut;
18
+ }
19
+ };
20
+
21
+ class FakeProcessGroup : public Backend {
22
+ public:
23
+ FakeProcessGroup(int rank, int size) : Backend(rank, size) {}
24
+
25
+ c10::intrusive_ptr<Work> broadcast(
26
+ std::vector<at::Tensor>& /* tensors */,
27
+ const BroadcastOptions& /* opts */ = BroadcastOptions()) override {
28
+ return c10::make_intrusive<FakeWork>();
29
+ }
30
+
31
+ c10::intrusive_ptr<Work> allreduce(
32
+ std::vector<at::Tensor>& /* tensors */,
33
+ const AllreduceOptions& /* opts */ = AllreduceOptions()) override {
34
+ return c10::make_intrusive<FakeWork>();
35
+ }
36
+
37
+ c10::intrusive_ptr<Work> allreduce_sparse(
38
+ std::vector<at::Tensor>& /* tensors */,
39
+ const AllreduceOptions& /* opts */ = AllreduceOptions()) override {
40
+ return c10::make_intrusive<FakeWork>();
41
+ }
42
+
43
+ c10::intrusive_ptr<Work> allreduce_coalesced(
44
+ std::vector<at::Tensor>& /* tensors */,
45
+ const AllreduceCoalescedOptions& /* opts */ =
46
+ AllreduceCoalescedOptions()) override {
47
+ return c10::make_intrusive<FakeWork>();
48
+ }
49
+
50
+ c10::intrusive_ptr<Work> reduce(
51
+ std::vector<at::Tensor>& /* tensors */,
52
+ const ReduceOptions& /* opts */ = ReduceOptions()) override {
53
+ return c10::make_intrusive<FakeWork>();
54
+ }
55
+
56
+ // NOTE [allgather on FakeProcessGroup]
57
+ // Assume each rank have the same input tensor so we just copy to the results
58
+ // since it's not a real allgather, we simply make this copying logic to let
59
+ // some simple validation works (i.e. calling allgather to see if each rank
60
+ // have the same tensor or not).
61
+ //
62
+ // NOTE: in general it's not good form to try to make FakeProcessGroup work
63
+ // with real data, but the reasoning here is that we want FakeProcessGroup to
64
+ // work with DeviceMesh's init code that have the data validation, which
65
+ // makes it worth the tradeoff.
66
+ c10::intrusive_ptr<Work> allgather(
67
+ std::vector<std::vector<at::Tensor>>& outputTensors,
68
+ std::vector<at::Tensor>& inputTensors,
69
+ const AllgatherOptions& /* opts */ = AllgatherOptions()) override {
70
+ for (auto& tensor : outputTensors[0]) {
71
+ tensor.copy_(inputTensors[0]);
72
+ }
73
+ return c10::make_intrusive<FakeWork>();
74
+ }
75
+
76
+ c10::intrusive_ptr<Work> _allgather_base(
77
+ at::Tensor& outputBuffer,
78
+ at::Tensor& inputBuffer,
79
+ const AllgatherOptions& /* opts */ = AllgatherOptions()) override {
80
+ auto chunks = outputBuffer.chunk(size_);
81
+ for (auto& tensor : chunks) {
82
+ tensor.copy_(inputBuffer);
83
+ }
84
+ return c10::make_intrusive<FakeWork>();
85
+ }
86
+
87
+ c10::intrusive_ptr<Work> allgather_coalesced(
88
+ std::vector<std::vector<at::Tensor>>& /* outputTensorLists */,
89
+ std::vector<at::Tensor>& /* inputTensors */,
90
+ const AllgatherOptions& /* opts */ = AllgatherOptions()) override {
91
+ return c10::make_intrusive<FakeWork>();
92
+ }
93
+
94
+ c10::intrusive_ptr<Work> allgather_into_tensor_coalesced(
95
+ std::vector<at::Tensor>& outputs,
96
+ std::vector<at::Tensor>& inputs,
97
+ const AllgatherOptions& /* opts */ = AllgatherOptions()) override {
98
+ for (size_t i = 0; i < outputs.size(); ++i) {
99
+ auto chunks = outputs[i].chunk(size_);
100
+ for (auto& chunk : chunks) {
101
+ chunk.copy_(inputs[i]);
102
+ }
103
+ }
104
+ return c10::make_intrusive<FakeWork>();
105
+ }
106
+
107
+ c10::intrusive_ptr<Work> gather(
108
+ std::vector<std::vector<at::Tensor>>& /* outputTensors */,
109
+ std::vector<at::Tensor>& /* inputTensors */,
110
+ const GatherOptions& /* opts */ = GatherOptions()) override {
111
+ return c10::make_intrusive<FakeWork>();
112
+ }
113
+
114
+ c10::intrusive_ptr<Work> scatter(
115
+ std::vector<at::Tensor>& /* outputTensors */,
116
+ std::vector<std::vector<at::Tensor>>& /* inputTensors */,
117
+ const ScatterOptions& /* opts */ = ScatterOptions()) override {
118
+ return c10::make_intrusive<FakeWork>();
119
+ }
120
+
121
+ c10::intrusive_ptr<Work> reduce_scatter(
122
+ std::vector<at::Tensor>& /* outputTensors */,
123
+ std::vector<std::vector<at::Tensor>>& /* inputTensors */,
124
+ const ReduceScatterOptions& /* opts */ =
125
+ ReduceScatterOptions()) override {
126
+ return c10::make_intrusive<FakeWork>();
127
+ }
128
+
129
+ c10::intrusive_ptr<Work> _reduce_scatter_base(
130
+ at::Tensor& /* outputBuffer */,
131
+ at::Tensor& /* inputBuffer */,
132
+ const ReduceScatterOptions& /* opts */ =
133
+ ReduceScatterOptions()) override {
134
+ return c10::make_intrusive<FakeWork>();
135
+ }
136
+
137
+ c10::intrusive_ptr<Work> reduce_scatter_tensor_coalesced(
138
+ std::vector<at::Tensor>& /* outputs */,
139
+ std::vector<at::Tensor>& /* inputs */,
140
+ const ReduceScatterOptions& /* opts */ =
141
+ ReduceScatterOptions()) override {
142
+ return c10::make_intrusive<FakeWork>();
143
+ }
144
+
145
+ c10::intrusive_ptr<Work> alltoall_base(
146
+ at::Tensor& /* outputBuffer */,
147
+ at::Tensor& /* inputBuffer */,
148
+ std::vector<int64_t>& /* outputSplitSizes */,
149
+ std::vector<int64_t>& /* inputSplitSizes */,
150
+ const AllToAllOptions& /* opts */ = AllToAllOptions()) override {
151
+ return c10::make_intrusive<FakeWork>();
152
+ }
153
+
154
+ c10::intrusive_ptr<Work> alltoall(
155
+ std::vector<at::Tensor>& /* outputTensors */,
156
+ std::vector<at::Tensor>& /* inputTensors */,
157
+ const AllToAllOptions& opts = AllToAllOptions()) override {
158
+ return c10::make_intrusive<FakeWork>();
159
+ }
160
+
161
+ c10::intrusive_ptr<Work> send(
162
+ std::vector<at::Tensor>& /* tensors */,
163
+ int /* dstRank */,
164
+ int /* tag */) override {
165
+ return c10::make_intrusive<FakeWork>();
166
+ }
167
+
168
+ c10::intrusive_ptr<Work> recv(
169
+ std::vector<at::Tensor>& /* tensors */,
170
+ int /* srcRank */,
171
+ int /* tag */) override {
172
+ return c10::make_intrusive<FakeWork>();
173
+ }
174
+
175
+ c10::intrusive_ptr<Work> recvAnysource(
176
+ std::vector<at::Tensor>& /* tensors */,
177
+ int /* tag */) override {
178
+ return c10::make_intrusive<FakeWork>();
179
+ }
180
+
181
+ void startCoalescing() override {
182
+ // No-op
183
+ }
184
+
185
+ c10::intrusive_ptr<Work> endCoalescing(OpType /* optype */) {
186
+ return c10::make_intrusive<FakeWork>();
187
+ }
188
+
189
+ c10::intrusive_ptr<Work> endCoalescing() override {
190
+ return c10::make_intrusive<FakeWork>();
191
+ }
192
+
193
+ c10::intrusive_ptr<Work> barrier(
194
+ const BarrierOptions& /* opts */ = BarrierOptions()) override {
195
+ return c10::make_intrusive<FakeWork>();
196
+ }
197
+ };
198
+
199
+ } // namespace c10d
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/FileStore.hpp ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <sys/types.h>
4
+
5
+ #include <mutex>
6
+ #include <unordered_map>
7
+
8
+ #include <torch/csrc/distributed/c10d/Store.hpp>
9
+
10
+ namespace c10d {
11
+
12
+ class TORCH_API FileStore : public Store {
13
+ public:
14
+ explicit FileStore(std::string path, int numWorkers);
15
+
16
+ c10::intrusive_ptr<Store> clone() override;
17
+
18
+ ~FileStore() override;
19
+
20
+ void set(const std::string& key, const std::vector<uint8_t>& value) override;
21
+
22
+ std::vector<uint8_t> compareSet(
23
+ const std::string& key,
24
+ const std::vector<uint8_t>& expectedValue,
25
+ const std::vector<uint8_t>& desiredValue) override;
26
+
27
+ std::vector<uint8_t> get(const std::string& key) override;
28
+
29
+ int64_t add(const std::string& key, int64_t value) override;
30
+
31
+ int64_t getNumKeys() override;
32
+
33
+ bool deleteKey(const std::string& key) override;
34
+
35
+ bool check(const std::vector<std::string>& keys) override;
36
+
37
+ void wait(const std::vector<std::string>& keys) override;
38
+
39
+ void wait(
40
+ const std::vector<std::string>& keys,
41
+ const std::chrono::milliseconds& timeout) override;
42
+
43
+ // Returns the path used by the FileStore.
44
+ const std::string& getPath() const noexcept {
45
+ return path_;
46
+ }
47
+
48
+ protected:
49
+ int64_t addHelper(const std::string& key, int64_t i);
50
+
51
+ std::string path_;
52
+ off_t pos_{0};
53
+
54
+ int numWorkers_;
55
+ const std::string cleanupKey_;
56
+ const std::string refCountKey_;
57
+ const std::string regularPrefix_;
58
+ const std::string deletePrefix_;
59
+
60
+ std::unordered_map<std::string, std::vector<uint8_t>> cache_;
61
+
62
+ std::mutex activeFileOpLock_;
63
+ };
64
+
65
+ } // namespace c10d
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/FlightRecorder.hpp ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #include <cstdio>
3
+ #include <cstdlib>
4
+
5
+ #include <memory>
6
+ #include <mutex>
7
+
8
+ #include <ATen/ATen.h>
9
+ #include <c10/util/Exception.h>
10
+ #include <torch/csrc/distributed/c10d/TraceUtils.h>
11
+ #include <torch/csrc/distributed/c10d/logger.hpp>
12
+ #include <optional>
13
+
14
+ namespace c10d {
15
+
16
+ #define DEFINE_CONSTANT(name, value) \
17
+ static c10::IValue name = value; \
18
+ static std::string name##_str = value;
19
+ // Update whenever changing contents or formatting of the dump
20
+ // (minor when adding fields, major when changing existing fields)
21
+ // Also update both JSON and Pickle dumps to make use of the newly defined
22
+ // field(s).
23
+ DEFINE_CONSTANT(version_val, "2.9")
24
+ DEFINE_CONSTANT(entries_key, "entries")
25
+ DEFINE_CONSTANT(nccl_comm_key, "nccl_comm_state")
26
+ DEFINE_CONSTANT(nccl_version_key, "nccl_version")
27
+ DEFINE_CONSTANT(version_key, "version")
28
+ DEFINE_CONSTANT(pg_config_key, "pg_config")
29
+ DEFINE_CONSTANT(pg_status_key, "pg_status")
30
+ DEFINE_CONSTANT(record_id_key, "record_id")
31
+ DEFINE_CONSTANT(pg_id_key, "pg_id")
32
+ DEFINE_CONSTANT(pg_name_key, "process_group")
33
+ DEFINE_CONSTANT(collective_seq_id_key, "collective_seq_id")
34
+ DEFINE_CONSTANT(p2p_seq_id_key, "p2p_seq_id")
35
+ DEFINE_CONSTANT(is_p2p_key, "is_p2p")
36
+ DEFINE_CONSTANT(op_id_key, "op_id")
37
+ DEFINE_CONSTANT(profiling_name_key, "profiling_name")
38
+ DEFINE_CONSTANT(input_sizes_key, "input_sizes")
39
+ DEFINE_CONSTANT(input_dtypes_key, "input_dtypes")
40
+ DEFINE_CONSTANT(output_sizes_key, "output_sizes")
41
+ DEFINE_CONSTANT(output_dtypes_key, "output_dtypes")
42
+ DEFINE_CONSTANT(time_created_key, "time_created_ns")
43
+ DEFINE_CONSTANT(duration_key, "duration_ms")
44
+ DEFINE_CONSTANT(timeout_key, "timeout_ms")
45
+ DEFINE_CONSTANT(frames_key, "frames")
46
+ DEFINE_CONSTANT(state_key, "state")
47
+ DEFINE_CONSTANT(line_key, "line")
48
+ DEFINE_CONSTANT(name_key, "name")
49
+ DEFINE_CONSTANT(filename_key, "filename")
50
+ DEFINE_CONSTANT(retired_key, "retired")
51
+ DEFINE_CONSTANT(time_discovered_started_key, "time_discovered_started_ns")
52
+ DEFINE_CONSTANT(time_discovered_completed_key, "time_discovered_completed_ns")
53
+ DEFINE_CONSTANT(completed_state, "completed")
54
+ DEFINE_CONSTANT(scheduled_state, "scheduled")
55
+ DEFINE_CONSTANT(started_state, "started")
56
+ DEFINE_CONSTANT(thread_id_key, "thread_id")
57
+ DEFINE_CONSTANT(thread_name_key, "thread_name")
58
+ #undef DEFINE_CONSTANT
59
+
60
+ // Write NCCL debug info to local disk or any storage users define.
61
+ // There are some constrains we set for the debug info writer:
62
+ // 1. The writer should only be registered once.
63
+ // 2. Once registered, users cannot change it including un-register.
64
+ // 3. It is recommended to register the customized writer in the trainer setup,
65
+ // If users don't register before calling launchAsyncDebugDump, then users
66
+ // lose the chance to register (and the default writer will be
67
+ // auto-registered).
68
+ class TORCH_API DebugInfoWriter {
69
+ public:
70
+ virtual ~DebugInfoWriter() = default;
71
+ virtual void write(const std::string& trace);
72
+ static DebugInfoWriter& getWriter(int rank);
73
+ static void registerWriter(std::unique_ptr<DebugInfoWriter> writer);
74
+ virtual std::string getWriterTarget() {
75
+ return filename_;
76
+ }
77
+
78
+ protected:
79
+ DebugInfoWriter(const std::string& namePrefix, int rank) {
80
+ filename_ = c10::str(namePrefix, rank);
81
+ }
82
+ std::string filename_;
83
+
84
+ private:
85
+ static std::unique_ptr<DebugInfoWriter> writer_;
86
+ static std::atomic<bool> hasWriterRegistered_;
87
+ };
88
+
89
+ template <typename EventType>
90
+ struct FlightRecorder {
91
+ static FlightRecorder<EventType>* get() {
92
+ // intentionally leak on exit
93
+ // because this will hold python state that may get destructed
94
+ static FlightRecorder<EventType>* instance =
95
+ new FlightRecorder<EventType>();
96
+ return instance;
97
+ }
98
+ FlightRecorder() {
99
+ max_entries_ =
100
+ getCvarInt({"TORCH_FR_BUFFER_SIZE", "TORCH_NCCL_TRACE_BUFFER_SIZE"}, 0);
101
+ capture_cpp_stack_ = getCvarBool(
102
+ {"TORCH_FR_CPP_STACK", "TORCH_NCCL_TRACE_CPP_STACK"}, false);
103
+ enabled_ = max_entries_ > 0;
104
+ }
105
+ struct Entry {
106
+ size_t id_; // incremented id in the trace buffer
107
+ // used to figure out where in the circular entries
108
+ // buffer this entry will be located to
109
+ // update state information
110
+ size_t pg_id_;
111
+ std::tuple<std::string, std::string> pg_name_; // <group_name, group_desc>
112
+
113
+ // collective_seq_id and p2p_seq_id refer to actual kernel launches (e.g. 1
114
+ // per coalesced group).
115
+ // collective_seq_id only increments for true collective operations (over
116
+ // all ranks in the group). p2p_seq_id only increments over non-collective
117
+ // operations in the group. op_id refers to logical operations (e.g. one per
118
+ // op inside coalesced group)
119
+ size_t collective_seq_id_;
120
+ size_t p2p_seq_id_;
121
+ size_t op_id_;
122
+ std::string profiling_name_;
123
+
124
+ std::shared_ptr<torch::CapturedTraceback> traceback_;
125
+ // we borrow pointers to start_ and end_ so we can query the state
126
+ // on reporting. However, once the event is completed, the call
127
+ // to `complete` will clear these.
128
+ EventType *start_, *end_;
129
+
130
+ // timestamp when the entry was created, likely close to the time the work
131
+ // was 'enqueued'- not necessarily started
132
+ c10::time_t time_created_;
133
+
134
+ // configured timeout for this entry
135
+ c10::time_t timeout_ms_;
136
+
137
+ // Is this a P2P event?
138
+ bool isP2P_;
139
+
140
+ std::optional<float> duration_;
141
+
142
+ // timestamp when our CPU threads discovered that the kernel started.
143
+ // will always be _after_ it actually started, and can be very late
144
+ // if the watchdog thread got stuck on CUDA APIs.
145
+ std::optional<c10::time_t> time_discovered_started_;
146
+
147
+ // timestamp when our CPU threads discovered that the kernel completed.
148
+ // will always be _after_ it actually completed, and can be the same time
149
+ // as the discovery of the start if the watchdog thread is stuck on CUDA
150
+ // APIs
151
+ std::optional<c10::time_t> time_discovered_completed_;
152
+
153
+ // size information for input/output tensors
154
+ c10::SmallVector<int64_t, 4> input_dims_;
155
+ std::vector<c10::ScalarType> input_dtypes_;
156
+ c10::SmallVector<int64_t, 4> output_dims_;
157
+ std::vector<c10::ScalarType> output_dtypes_;
158
+ c10::SmallVector<int64_t, 8> sizes_; // flattened from inputs, outputs
159
+ std::thread::id thread_id_;
160
+ std::string thread_name_;
161
+ bool retired_ = false; // is this work entry no longer in the workMetaList_?
162
+ // a retired but not completed event has timed out
163
+
164
+ // Returns the traceback of current entry, in string form.
165
+ // Note: `getTraceback` invokes `torch::symbolize`, which may need to
166
+ // acquire the GIL. If you don't want to block the current thread or take
167
+ // the risk of a GIL deadlock, you can use an asynchronous calling mechanism
168
+ // like std::async.
169
+ TORCH_API std::string getTraceback();
170
+ };
171
+
172
+ bool enabled_ = false;
173
+ bool capture_cpp_stack_ = false;
174
+ std::mutex mutex_;
175
+ std::vector<Entry> entries_;
176
+ size_t max_entries_ = 0;
177
+ size_t next_ = 0;
178
+ size_t id_ = 0;
179
+ std::map<size_t, std::shared_ptr<ProcessGroupStatus>> all_pg_status_ = {};
180
+ std::map<std::tuple<std::string, std::string>, std::vector<uint64_t>>
181
+ pg_name_to_ranks_ = {};
182
+ std::string nccl_version_;
183
+
184
+ std::optional<size_t> record(
185
+ size_t pg_id,
186
+ const std::tuple<std::string, std::string>& pg_name,
187
+ size_t collective_seq_id,
188
+ size_t p2p_seq_id,
189
+ size_t op_id,
190
+ std::string profiling_name,
191
+ const std::vector<at::Tensor>& inputs,
192
+ const std::vector<at::Tensor>& outputs,
193
+ EventType* start,
194
+ EventType* end,
195
+ std::chrono::milliseconds timeout_ms,
196
+ std::shared_ptr<ProcessGroupStatus> pg_status,
197
+ bool isP2P);
198
+
199
+ TORCH_API void record_pg_ranks(
200
+ const std::tuple<std::string, std::string>& pg_name,
201
+ std::vector<uint64_t> ranks);
202
+
203
+ void record_accelerator_version(const std::string nccl_version);
204
+
205
+ void update_state(Entry& r);
206
+
207
+ std::vector<Entry> dump_entries();
208
+
209
+ // Returns the entry with the given id, if it exists. Otherwise, returns
210
+ // std::nullopt.
211
+ TORCH_API std::optional<Entry> getEntry(std::optional<size_t> id);
212
+
213
+ /*
214
+ Mark an Event as completed and free its events.
215
+ This is called by the watchdog thread, and is asynchronous from the
216
+ perspective of the main thread.
217
+ compute_duration defaults to true since retire_id is only called in the
218
+ watchdog thread, which is currently a place we call cuda APIs which may hang,
219
+ but care should be taken to avoid computing duration in any function that must
220
+ never hang. (timing must also be enabled for compute_duration - see
221
+ TORCH_NCCL_ENABLE_TIMING).
222
+ */
223
+ TORCH_API void retire_id(
224
+ std::optional<size_t> id,
225
+ bool compute_duration = true);
226
+
227
+ const c10::List<c10::IValue> getCollectiveTrace(
228
+ bool includeStacktraces,
229
+ bool onlyActive);
230
+
231
+ // dump pg_entries
232
+ const c10::Dict<c10::IValue, c10::IValue> getPgConfig();
233
+
234
+ const std::map<std::string, std::map<std::string, std::string>>
235
+ getPgConfigJson();
236
+
237
+ // dump pg_status
238
+ const c10::Dict<c10::IValue, c10::IValue> getPgStatus();
239
+
240
+ const std::map<std::string, std::map<std::string, std::string>>
241
+ getPgStatusJson();
242
+
243
+ std::string dump_json(
244
+ const std::optional<std::unordered_map<
245
+ std::string,
246
+ std::unordered_map<std::string, std::string>>>& extraDumpMap,
247
+ bool includeCollectives,
248
+ bool onlyActive);
249
+
250
+ std::string dump(
251
+ const std::optional<std::unordered_map<
252
+ std::string,
253
+ std::unordered_map<std::string, std::string>>>& extraDumpMap,
254
+ bool includeCollectives,
255
+ bool includeStackTraces,
256
+ bool onlyActive);
257
+ };
258
+
259
+ // Dumps the fr traces and additional information about the Process
260
+ // Group.
261
+ TORCH_API std::string dump_fr_trace(
262
+ bool includeCollectives,
263
+ bool includeStackTraces,
264
+ bool onlyActive);
265
+
266
+ // Dumps the fr traces and additional information about the Process
267
+ // Group in JSON formatted string.
268
+ // We don't include stack traces in JSON format as it is far too much data.
269
+ TORCH_API std::string dump_fr_trace_json(
270
+ bool includeCollectives,
271
+ bool onlyActive);
272
+ } // namespace c10d
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/FlightRecorderDetail.hpp ADDED
@@ -0,0 +1,550 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <nlohmann/json.hpp>
2
+
3
+ #include <c10/util/WaitCounter.h>
4
+ #include <c10/util/thread_name.h>
5
+
6
+ #include <torch/csrc/distributed/c10d/FlightRecorder.hpp>
7
+
8
+ namespace c10d {
9
+
10
+ template <typename EventType>
11
+ float getDurationFromEvent(EventType& start, EventType& end);
12
+
13
+ // Returns the traceback of current entry, in string form.
14
+ // Note: `getTraceback` invokes `torch::symbolize`, which may need to acquire
15
+ // the GIL. If you don't want to block the current thread or take the risk of a
16
+ // GIL deadlock, you can use an asynchronous calling mechanism like std::async.
17
+ template <typename EventType>
18
+ std::string FlightRecorder<EventType>::Entry::getTraceback() {
19
+ torch::CapturedTraceback* traceback = traceback_.get();
20
+ torch::SymbolizedTracebacks s_tbs = torch::symbolize({traceback});
21
+ // We use 0 because we only have one traceback here.
22
+ const auto& s_tb = s_tbs.tracebacks.at(0);
23
+ std::stringstream oss;
24
+ for (auto idx : c10::irange(s_tb.size())) {
25
+ auto frame_id = s_tb[idx];
26
+ const auto& frame = s_tbs.all_frames.at(frame_id);
27
+ oss << "#" << idx << " " << frame.funcname << " from " << frame.filename
28
+ << ":" << frame.lineno << '\n';
29
+ }
30
+ /* Resulted format is like:
31
+ #0 all_reduce from pytorch/torch/distributed/distributed_c10d.py:2696
32
+ #1 wrapper from pytorch/torch/distributed/c10d_logger.py:83
33
+ #2 bar from /home/user/repro.py:15
34
+ #3 foo from /home/user/repro.py:24
35
+ #4 main from /home/user/repro.py:34
36
+ #5 <module> from /home/user/repro.py:40
37
+ */
38
+ return oss.str();
39
+ }
40
+
41
+ template <typename EventType>
42
+ std::optional<size_t> FlightRecorder<EventType>::record(
43
+ size_t pg_id,
44
+ const std::tuple<std::string, std::string>& pg_name,
45
+ size_t collective_seq_id,
46
+ size_t p2p_seq_id,
47
+ size_t op_id,
48
+ std::string profiling_name,
49
+ const std::vector<at::Tensor>& inputs,
50
+ const std::vector<at::Tensor>& outputs,
51
+ EventType* start,
52
+ EventType* end,
53
+ std::chrono::milliseconds timeout_ms,
54
+ std::shared_ptr<ProcessGroupStatus> pg_status,
55
+ bool isP2P) {
56
+ if (!enabled_) {
57
+ return std::nullopt;
58
+ }
59
+ if (all_pg_status_.find(pg_id) == all_pg_status_.end()) {
60
+ // Current pg_status is not in FR.
61
+ all_pg_status_[pg_id] = std::move(pg_status);
62
+ }
63
+ auto traceback =
64
+ torch::CapturedTraceback::gather(true, true, capture_cpp_stack_);
65
+ std::lock_guard<std::mutex> guard(mutex_);
66
+
67
+ auto te = Entry{
68
+ id_,
69
+ pg_id,
70
+ pg_name,
71
+ collective_seq_id,
72
+ p2p_seq_id,
73
+ op_id,
74
+ std::move(profiling_name),
75
+ std::move(traceback),
76
+ start,
77
+ end,
78
+ c10::getTime(),
79
+ timeout_ms.count(),
80
+ isP2P,
81
+ std::nullopt,
82
+ std::nullopt,
83
+ std::nullopt,
84
+ {},
85
+ {},
86
+ {},
87
+ {},
88
+ {},
89
+ std::this_thread::get_id(),
90
+ c10::getThreadName(),
91
+ false};
92
+
93
+ for (const auto& input : inputs) {
94
+ c10::IntArrayRef sizes = input.sizes();
95
+ te.input_dtypes_.push_back(input.dtype().toScalarType());
96
+ te.input_dims_.push_back(static_cast<int64_t>(sizes.size()));
97
+ te.sizes_.insert(te.sizes_.end(), sizes.begin(), sizes.end());
98
+ }
99
+
100
+ for (const auto& output : outputs) {
101
+ c10::IntArrayRef sizes = output.sizes();
102
+ te.output_dtypes_.push_back(output.dtype().toScalarType());
103
+ te.output_dims_.push_back(static_cast<int64_t>(sizes.size()));
104
+ te.sizes_.insert(te.sizes_.end(), sizes.begin(), sizes.end());
105
+ }
106
+
107
+ if (entries_.size() < max_entries_) {
108
+ entries_.emplace_back(std::move(te));
109
+ } else {
110
+ entries_[next_++] = std::move(te);
111
+ if (next_ == max_entries_) {
112
+ next_ = 0;
113
+ }
114
+ }
115
+ return id_++;
116
+ }
117
+
118
+ template <typename EventType>
119
+ void FlightRecorder<EventType>::record_pg_ranks(
120
+ const std::tuple<std::string, std::string>& pg_name,
121
+ std::vector<uint64_t> ranks) {
122
+ if (!enabled_) {
123
+ return;
124
+ }
125
+ std::lock_guard<std::mutex> guard(mutex_);
126
+ pg_name_to_ranks_[pg_name] = std::move(ranks);
127
+ }
128
+
129
+ template <typename EventType>
130
+ void FlightRecorder<EventType>::record_accelerator_version(
131
+ const std::string nccl_version) {
132
+ if (!enabled_) {
133
+ return;
134
+ }
135
+ std::lock_guard<std::mutex> guard(mutex_);
136
+ nccl_version_ = std::move(nccl_version);
137
+ }
138
+
139
+ template <typename EventType>
140
+ void FlightRecorder<EventType>::update_state(Entry& r) {
141
+ try {
142
+ if (r.start_ != nullptr) {
143
+ bool started = r.start_->query();
144
+ if (started && !r.time_discovered_started_) {
145
+ r.time_discovered_started_ = c10::getTime();
146
+ }
147
+ }
148
+ if (r.end_ != nullptr) {
149
+ bool completed = r.end_->query();
150
+ if (completed && !r.time_discovered_completed_) {
151
+ r.time_discovered_completed_ = c10::getTime();
152
+ }
153
+ }
154
+ } catch (std::exception& e) {
155
+ LOG(ERROR) << "Failed to update state for entry " << r.id_ << ": "
156
+ << r.profiling_name_ << " with error: " << e.what();
157
+ }
158
+ }
159
+
160
+ template <typename EventType>
161
+ std::vector<typename FlightRecorder<EventType>::Entry> FlightRecorder<
162
+ EventType>::dump_entries() {
163
+ std::vector<Entry> result;
164
+ {
165
+ std::lock_guard<std::mutex> guard(mutex_);
166
+ result.reserve(entries_.size());
167
+ result.insert(
168
+ result.end(),
169
+ entries_.begin() + static_cast<std::ptrdiff_t>(next_),
170
+ entries_.end());
171
+ result.insert(
172
+ result.end(),
173
+ entries_.begin(),
174
+ entries_.begin() + static_cast<std::ptrdiff_t>(next_));
175
+ }
176
+ // query any remaining events
177
+ for (auto& r : result) {
178
+ update_state(r);
179
+ r.start_ = r.end_ = nullptr;
180
+ }
181
+ return result;
182
+ }
183
+
184
+ template <typename EventType>
185
+ // Returns the entry with the given id, if it exists. Otherwise, returns
186
+ // std::nullopt.
187
+ std::optional<typename FlightRecorder<EventType>::Entry> FlightRecorder<
188
+ EventType>::getEntry(std::optional<size_t> id) {
189
+ if (!enabled_ || !id) {
190
+ return std::nullopt;
191
+ }
192
+
193
+ std::unique_lock<std::mutex> guard(mutex_);
194
+ Entry entry = entries_.at(*id % max_entries_);
195
+ if (entry.id_ == *id) {
196
+ return entry;
197
+ } else {
198
+ return std::nullopt;
199
+ }
200
+ }
201
+
202
+ template <typename EventType>
203
+ void FlightRecorder<EventType>::retire_id(
204
+ std::optional<size_t> id,
205
+ bool compute_duration) {
206
+ if (!enabled_ || !id) {
207
+ return;
208
+ }
209
+
210
+ bool can_compute_duration = false;
211
+ EventType* startEvent = nullptr;
212
+ EventType* endEvent = nullptr;
213
+ std::optional<float> duration = std::nullopt;
214
+
215
+ std::unique_lock<std::mutex> guard(mutex_);
216
+
217
+ Entry* entry = &entries_.at(*id % max_entries_);
218
+ if (entry->id_ == *id) {
219
+ update_state(*entry);
220
+
221
+ if (compute_duration) {
222
+ can_compute_duration = entry->time_discovered_completed_.has_value() &&
223
+ entry->start_ && entry->end_;
224
+ startEvent = entry->start_;
225
+ endEvent = entry->end_;
226
+ }
227
+ entry->retired_ = true;
228
+ entry->start_ = entry->end_ = nullptr;
229
+ }
230
+
231
+ if (can_compute_duration) {
232
+ // Compute duration without without holding the lock, because
233
+ // cudaEventDuration() can hang, and we need to acquire the lock before we
234
+ // can dump(), which we never want to block.
235
+ guard.unlock();
236
+ duration = getDurationFromEvent<EventType>(*startEvent, *endEvent);
237
+ guard.lock();
238
+
239
+ // Refresh the entry pointer, see if the entry has been overwritten
240
+ entry = &entries_.at(*id % max_entries_);
241
+ if (entry->id_ != *id) {
242
+ LOG(INFO) << "retire_id abandoned for id " << *id
243
+ << ", event was overwritten while waiting to compute duration.";
244
+ return;
245
+ }
246
+ if (duration.has_value()) {
247
+ entry->duration_ = duration;
248
+ }
249
+ }
250
+ }
251
+
252
+ template <typename EventType>
253
+ const c10::List<c10::IValue> FlightRecorder<EventType>::getCollectiveTrace(
254
+ bool includeStacktraces,
255
+ bool onlyActive) {
256
+ auto entries = new_list();
257
+ // Entries are returned in the order they were recorded
258
+ auto result = dump_entries();
259
+ std::vector<torch::CapturedTraceback*> tracebacks;
260
+ torch::SymbolizedTracebacks stracebacks;
261
+ std::vector<c10::IValue> all_frames;
262
+ if (includeStacktraces) {
263
+ for (auto& e : result) {
264
+ tracebacks.push_back(e.traceback_.get());
265
+ }
266
+ stracebacks = torch::symbolize(tracebacks);
267
+ for (const auto& f : stracebacks.all_frames) {
268
+ auto d = new_dict();
269
+ d.insert(name_key, f.funcname);
270
+ d.insert(filename_key, f.filename);
271
+ d.insert(line_key, int64_t(f.lineno));
272
+ all_frames.emplace_back(std::move(d));
273
+ }
274
+ }
275
+ for (auto i : c10::irange(result.size())) {
276
+ auto dict = new_dict();
277
+ auto& e = result.at(i);
278
+ // Skip completed events
279
+ if (onlyActive && e.time_discovered_completed_.has_value()) {
280
+ continue;
281
+ }
282
+ if (includeStacktraces) {
283
+ auto& tb = stracebacks.tracebacks.at(i);
284
+ auto frames = new_list();
285
+ for (auto frame : tb) {
286
+ frames.push_back(all_frames.at(frame));
287
+ }
288
+ dict.insert(frames_key, frames);
289
+ }
290
+
291
+ dict.insert(record_id_key, int64_t(e.id_));
292
+ dict.insert(pg_id_key, int64_t(e.pg_id_));
293
+ dict.insert(pg_name_key, e.pg_name_);
294
+ dict.insert(thread_name_key, e.thread_name_);
295
+ dict.insert(thread_id_key, c10::str(e.thread_id_));
296
+ dict.insert(collective_seq_id_key, int64_t(e.collective_seq_id_));
297
+ dict.insert(p2p_seq_id_key, int64_t(e.p2p_seq_id_));
298
+ dict.insert(op_id_key, int64_t(e.op_id_));
299
+ dict.insert(profiling_name_key, e.profiling_name_);
300
+ dict.insert(time_created_key, int64_t(e.time_created_));
301
+ if (e.duration_) {
302
+ dict.insert(duration_key, *e.duration_);
303
+ }
304
+
305
+ auto it = e.sizes_.begin();
306
+ auto read_sizes = [&](const c10::SmallVector<int64_t, 4>& dims) {
307
+ auto sizes = new_list();
308
+ for (auto dim : dims) {
309
+ auto arg_sizes = new_list();
310
+ for ([[maybe_unused]] auto i : c10::irange(dim)) {
311
+ arg_sizes.push_back(*it++);
312
+ }
313
+ sizes.push_back(arg_sizes);
314
+ }
315
+ return sizes;
316
+ };
317
+
318
+ dict.insert(input_sizes_key, read_sizes(e.input_dims_));
319
+ std::vector<std::string> input_dtypes_strs;
320
+ input_dtypes_strs.reserve(e.input_dtypes_.size());
321
+ for (const auto& input_dtype : e.input_dtypes_) {
322
+ input_dtypes_strs.emplace_back(c10::toString(input_dtype));
323
+ }
324
+ dict.insert(input_dtypes_key, input_dtypes_strs);
325
+ dict.insert(output_sizes_key, read_sizes(e.output_dims_));
326
+ std::vector<std::string> output_dtypes_strs;
327
+ output_dtypes_strs.reserve(e.output_dtypes_.size());
328
+ for (const auto& output_dtype : e.output_dtypes_) {
329
+ output_dtypes_strs.emplace_back(c10::toString(output_dtype));
330
+ }
331
+ dict.insert(output_dtypes_key, output_dtypes_strs);
332
+ if (e.time_discovered_completed_.has_value()) {
333
+ dict.insert(state_key, completed_state);
334
+ } else if (e.time_discovered_started_.has_value()) {
335
+ dict.insert(state_key, started_state);
336
+ } else {
337
+ dict.insert(state_key, scheduled_state);
338
+ }
339
+
340
+ dict.insert(
341
+ time_discovered_started_key,
342
+ e.time_discovered_started_.has_value()
343
+ ? int64_t(*e.time_discovered_started_)
344
+ : c10::IValue());
345
+ dict.insert(
346
+ time_discovered_completed_key,
347
+ e.time_discovered_completed_.has_value()
348
+ ? int64_t(*e.time_discovered_completed_)
349
+ : c10::IValue());
350
+ dict.insert(retired_key, e.retired_);
351
+ dict.insert(timeout_key, e.timeout_ms_);
352
+ dict.insert(is_p2p_key, e.isP2P_);
353
+
354
+ entries.push_back(dict);
355
+ }
356
+ return entries;
357
+ }
358
+
359
+ template <typename EventType>
360
+ const c10::Dict<c10::IValue, c10::IValue> FlightRecorder<
361
+ EventType>::getPgConfig() {
362
+ auto pg_config = new_dict();
363
+ for (const auto& [pg_name, ranks] : pg_name_to_ranks_) {
364
+ auto pg_info = new_dict();
365
+ pg_info.insert("name", std::get<0>(pg_name));
366
+ pg_info.insert("desc", std::get<1>(pg_name));
367
+ pg_info.insert("ranks", ranks_str(ranks));
368
+ pg_config.insert(std::get<0>(pg_name), pg_info);
369
+ }
370
+ return pg_config;
371
+ }
372
+
373
+ template <typename EventType>
374
+ const std::map<std::string, std::map<std::string, std::string>> FlightRecorder<
375
+ EventType>::getPgConfigJson() {
376
+ std::map<std::string, std::map<std::string, std::string>> result;
377
+ for (const auto& [pg_name, ranks] : pg_name_to_ranks_) {
378
+ auto pg_info = std::map<std::string, std::string>();
379
+ pg_info["name"] = std::get<0>(pg_name);
380
+ pg_info["desc"] = std::get<1>(pg_name);
381
+ pg_info["ranks"] = ranks_str(ranks);
382
+ result.emplace(std::get<0>(pg_name), pg_info);
383
+ }
384
+ return result;
385
+ }
386
+
387
+ template <typename EventType>
388
+ const c10::Dict<c10::IValue, c10::IValue> FlightRecorder<
389
+ EventType>::getPgStatus() {
390
+ auto all_pg_status = new_dict();
391
+ for (const auto& [pg_id, status] : all_pg_status_) {
392
+ auto pg_status = new_dict();
393
+ pg_status.insert("last_enqueued_collective", status->lastEnqueuedSeq);
394
+ pg_status.insert("last_started_collective", status->lastStartedSeq);
395
+ pg_status.insert("last_completed_collective", status->lastCompletedSeq);
396
+ all_pg_status.insert(std::to_string(pg_id), pg_status);
397
+ }
398
+ return all_pg_status;
399
+ }
400
+
401
+ template <typename EventType>
402
+ const std::map<std::string, std::map<std::string, std::string>> FlightRecorder<
403
+ EventType>::getPgStatusJson() {
404
+ std::map<std::string, std::map<std::string, std::string>> result;
405
+ for (const auto& [pg_id, status] : all_pg_status_) {
406
+ auto pg_status = std::map<std::string, std::string>();
407
+ pg_status["last_enqueued_collective"] =
408
+ std::to_string(status->lastEnqueuedSeq);
409
+ pg_status["last_started_collective"] =
410
+ std::to_string(status->lastStartedSeq);
411
+ pg_status["last_completed_collective"] =
412
+ std::to_string(status->lastCompletedSeq);
413
+ result[std::to_string(pg_id)] = pg_status;
414
+ }
415
+ return result;
416
+ }
417
+
418
+ using json = nlohmann::json;
419
+ template <typename EventType>
420
+ std::string FlightRecorder<EventType>::dump_json(
421
+ const std::optional<std::unordered_map<
422
+ std::string,
423
+ std::unordered_map<std::string, std::string>>>& extraDumpMap,
424
+ bool includeCollectives,
425
+ bool onlyActive) {
426
+ json result;
427
+ result[version_key_str] = version_val_str;
428
+ result[nccl_version_key_str] = nccl_version_;
429
+ result[pg_config_key_str] = getPgConfigJson();
430
+ result[pg_status_key_str] = getPgStatusJson();
431
+
432
+ // collective trace
433
+ if (includeCollectives) {
434
+ std::list<json> entries;
435
+ for (auto& e : dump_entries()) {
436
+ json j;
437
+ if (onlyActive && e.time_discovered_completed_.has_value()) {
438
+ continue;
439
+ }
440
+ j[record_id_key_str] = int64_t(e.id_);
441
+ j[pg_id_key_str] = int64_t(e.pg_id_);
442
+ j[pg_name_key_str] = e.pg_name_;
443
+ j[thread_name_key_str] = e.thread_name_;
444
+ j[thread_id_key_str] = c10::str(e.thread_id_);
445
+ j[collective_seq_id_key_str] = int64_t(e.collective_seq_id_);
446
+ j[p2p_seq_id_key_str] = int64_t(e.p2p_seq_id_);
447
+ j[op_id_key_str] = int64_t(e.op_id_);
448
+ j[profiling_name_key_str] = e.profiling_name_;
449
+ j[time_created_key_str] = int64_t(e.time_created_);
450
+ if (e.duration_) {
451
+ j[duration_key_str] = *e.duration_;
452
+ }
453
+ auto it = e.sizes_.begin();
454
+ auto read_sizes = [&](const c10::SmallVector<int64_t, 4>& dims) {
455
+ auto sizes = std::list<std::list<int64_t>>();
456
+ for (auto dim : dims) {
457
+ auto arg_sizes = std::list<int64_t>();
458
+ for (auto i : c10::irange(dim)) {
459
+ (void)i;
460
+ arg_sizes.push_back(*it++);
461
+ }
462
+ sizes.push_back(arg_sizes);
463
+ }
464
+ return sizes;
465
+ };
466
+ j[input_sizes_key_str] = read_sizes(e.input_dims_);
467
+ std::vector<std::string> input_dtypes_strs;
468
+ input_dtypes_strs.reserve(e.input_dtypes_.size());
469
+ for (const auto& input_dtype : e.input_dtypes_) {
470
+ input_dtypes_strs.emplace_back(c10::toString(input_dtype));
471
+ }
472
+ j[input_dtypes_key_str] = input_dtypes_strs;
473
+ j[output_sizes_key_str] = read_sizes(e.output_dims_);
474
+ std::vector<std::string> output_dtypes_strs;
475
+ output_dtypes_strs.reserve(e.output_dtypes_.size());
476
+ for (const auto& output_dtype : e.output_dtypes_) {
477
+ output_dtypes_strs.emplace_back(c10::toString(output_dtype));
478
+ }
479
+ j[output_dtypes_key_str] = output_dtypes_strs;
480
+ if (e.time_discovered_completed_.has_value()) {
481
+ j[state_key_str] = completed_state_str;
482
+ } else if (e.time_discovered_started_.has_value()) {
483
+ j[state_key_str] = started_state_str;
484
+ } else {
485
+ j[state_key_str] = scheduled_state_str;
486
+ }
487
+ j[time_discovered_started_key_str] =
488
+ e.time_discovered_started_.has_value()
489
+ ? int64_t(*e.time_discovered_started_)
490
+ : 0;
491
+ j[time_discovered_completed_key_str] =
492
+ e.time_discovered_completed_.has_value()
493
+ ? int64_t(*e.time_discovered_completed_)
494
+ : 0;
495
+ j[retired_key_str] = e.retired_;
496
+ j[timeout_key_str] = e.timeout_ms_;
497
+ j[is_p2p_key_str] = e.isP2P_;
498
+ entries.emplace_back(j);
499
+ }
500
+
501
+ if (!entries.empty()) {
502
+ result[entries_key_str] = entries;
503
+ }
504
+ }
505
+
506
+ if (extraDumpMap.has_value()) {
507
+ result[nccl_comm_key_str] = extraDumpMap.value();
508
+ }
509
+ return result.dump();
510
+ }
511
+
512
+ template <typename EventType>
513
+ std::string FlightRecorder<EventType>::dump(
514
+ const std::optional<std::unordered_map<
515
+ std::string,
516
+ std::unordered_map<std::string, std::string>>>& extraDumpMap,
517
+ bool includeCollectives,
518
+ bool includeStackTraces,
519
+ bool onlyActive) {
520
+ STATIC_SCOPED_WAIT_COUNTER(pytorch.wait_counter.FlightRecorder__dump);
521
+ auto result = new_dict();
522
+ // common values
523
+ result.insert(version_key, version_val);
524
+ result.insert(pg_config_key, getPgConfig());
525
+ result.insert(nccl_version_key_str, nccl_version_);
526
+ result.insert(pg_status_key, getPgStatus());
527
+
528
+ // collective trace
529
+ if (includeCollectives) {
530
+ result.insert(
531
+ entries_key, getCollectiveTrace(includeStackTraces, onlyActive));
532
+ }
533
+
534
+ // convert extraDumpMap into a dictionary
535
+ auto per_comm_dict = new_dict();
536
+ if (extraDumpMap.has_value()) {
537
+ for (const auto& [ncclId, ncclDump] : extraDumpMap.value()) {
538
+ auto inner_dict = new_dict();
539
+ for (const auto& [key, value] : ncclDump) {
540
+ inner_dict.insert(key, value);
541
+ }
542
+ per_comm_dict.insert(ncclId, inner_dict);
543
+ }
544
+ }
545
+ if (!per_comm_dict.empty()) {
546
+ result.insert(nccl_comm_key, per_comm_dict);
547
+ }
548
+ return pickle_str(result);
549
+ }
550
+ } // namespace c10d
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/Functional.hpp ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/c10d/ProcessGroup.hpp>
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/GlooDeviceFactory.hpp ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #ifdef USE_C10D_GLOO
4
+
5
+ #include <string>
6
+
7
+ #include <c10/util/Registry.h>
8
+ #include <gloo/config.h>
9
+ #include <gloo/transport/device.h>
10
+
11
+ namespace c10d {
12
+
13
+ class TORCH_API GlooDeviceFactory {
14
+ public:
15
+ // Create new device instance for specific interface.
16
+ static std::shared_ptr<::gloo::transport::Device> makeDeviceForInterface(
17
+ const std::string& interface,
18
+ bool lazyInit);
19
+
20
+ // Create new device instance for specific hostname or address.
21
+ static std::shared_ptr<::gloo::transport::Device> makeDeviceForHostname(
22
+ const std::string& hostname,
23
+ bool lazyInit);
24
+ };
25
+
26
+ TORCH_DECLARE_SHARED_REGISTRY(
27
+ GlooDeviceRegistry,
28
+ ::gloo::transport::Device,
29
+ const std::string&, /* interface */
30
+ const std::string&, /* hostname */
31
+ bool /* lazyInit */);
32
+
33
+ } // namespace c10d
34
+
35
+ #endif // USE_C10D_GLOO
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/distributed/c10d/GroupRegistry.hpp ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+
3
+ #include <torch/csrc/distributed/c10d/ProcessGroup.hpp>
4
+
5
+ namespace c10d {
6
+
7
+ C10_EXPORT void set_thread_isolation_mode(bool enable);
8
+
9
+ bool get_thread_isolation_mode();
10
+
11
+ C10_EXPORT void register_process_group(
12
+ const std::string& group_name,
13
+ const c10::intrusive_ptr<c10d::ProcessGroup>& group);
14
+
15
+ C10_EXPORT c10::intrusive_ptr<c10d::ProcessGroup> resolve_process_group(
16
+ const std::string& group_name);
17
+
18
+ C10_EXPORT void unregister_process_group(const std::string& group_name);
19
+
20
+ C10_EXPORT void unregister_all_process_groups();
21
+
22
+ } // namespace c10d