Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +8 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/INSTALLER +1 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/METADATA +644 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/RECORD +0 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/REQUESTED +0 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/WHEEL +5 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/entry_points.txt +6 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/licenses/LICENSE +0 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/licenses/NOTICE +456 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/top_level.txt +3 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/conv2d.h +101 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/matmul.h +20 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/misc.h +94 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/norm.h +14 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/operators.h +10 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/pointwise.h +82 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/quantization.h +156 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/reduction.h +32 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/softmax.h +13 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/types.h +158 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/unique_name_manager.h +33 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/var_substitutor.h +61 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/testing/catch_utils.hpp +10 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/testing/file_check.h +79 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/testing/hooks_for_testing.h +19 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/backend/backend_data.h +59 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/backend/backend_device.h +100 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/backend/backend_interface.h +155 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/backend/lowering_context.h +110 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/cache.h +143 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/config.h +26 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/debug_util.h +45 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/dynamic_ir.h +48 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/hash.h +242 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/helpers.h +70 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/internal_ops/ltc_ops.h +49 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ir.h +289 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ir_builder.h +148 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ir_dump_util.h +30 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ir_metadata.h +51 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ir_util.h +45 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/lazy_graph_executor.h +429 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/metrics.h +288 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/multi_wait.h +60 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ops/arithmetic_ir_ops.h +12 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ops/utils.h +39 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/permutation_util.h +41 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/shape.h +78 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/shape_inference.h +122 -0
- code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/tensor.h +265 -0
.gitattributes
CHANGED
|
@@ -163,3 +163,11 @@ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages
|
|
| 163 |
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/pyarrow/libarrow_python_flight.so.2300 filter=lfs diff=lfs merge=lfs -text
|
| 164 |
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/pyarrow/libarrow_python_flight.so.2300.0.0 filter=lfs diff=lfs merge=lfs -text
|
| 165 |
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/pyarrow/libarrow_substrait.so.2300 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/pyarrow/libarrow_python_flight.so.2300 filter=lfs diff=lfs merge=lfs -text
|
| 164 |
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/pyarrow/libarrow_python_flight.so.2300.0.0 filter=lfs diff=lfs merge=lfs -text
|
| 165 |
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/pyarrow/libarrow_substrait.so.2300 filter=lfs diff=lfs merge=lfs -text
|
| 166 |
+
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/lib/libc10.so filter=lfs diff=lfs merge=lfs -text
|
| 167 |
+
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/lib/libc10_cuda.so filter=lfs diff=lfs merge=lfs -text
|
| 168 |
+
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/lib/libgomp.so.1 filter=lfs diff=lfs merge=lfs -text
|
| 169 |
+
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/lib/libtorch.so filter=lfs diff=lfs merge=lfs -text
|
| 170 |
+
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/lib/libtorch_cpu.so filter=lfs diff=lfs merge=lfs -text
|
| 171 |
+
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/lib/libtorch_cuda.so filter=lfs diff=lfs merge=lfs -text
|
| 172 |
+
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/lib/libtorch_cuda_linalg.so filter=lfs diff=lfs merge=lfs -text
|
| 173 |
+
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/lib/libtorch_python.so filter=lfs diff=lfs merge=lfs -text
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,644 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: torch
|
| 3 |
+
Version: 2.8.0
|
| 4 |
+
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
|
| 5 |
+
Home-page: https://pytorch.org/
|
| 6 |
+
Download-URL: https://github.com/pytorch/pytorch/tags
|
| 7 |
+
Author: PyTorch Team
|
| 8 |
+
Author-email: packages@pytorch.org
|
| 9 |
+
License: BSD-3-Clause
|
| 10 |
+
Project-URL: Homepage, https://pytorch.org/
|
| 11 |
+
Project-URL: Documentation, https://pytorch.org/docs/
|
| 12 |
+
Project-URL: Source, https://github.com/pytorch/pytorch
|
| 13 |
+
Project-URL: Forum, https://discuss.pytorch.org/
|
| 14 |
+
Keywords: pytorch,machine learning
|
| 15 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 16 |
+
Classifier: Intended Audience :: Developers
|
| 17 |
+
Classifier: Intended Audience :: Education
|
| 18 |
+
Classifier: Intended Audience :: Science/Research
|
| 19 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 20 |
+
Classifier: Topic :: Scientific/Engineering
|
| 21 |
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
| 22 |
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
| 23 |
+
Classifier: Topic :: Software Development
|
| 24 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 25 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 26 |
+
Classifier: Programming Language :: C++
|
| 27 |
+
Classifier: Programming Language :: Python :: 3
|
| 28 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 29 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 30 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 31 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 32 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 33 |
+
Requires-Python: >=3.9.0
|
| 34 |
+
Description-Content-Type: text/markdown
|
| 35 |
+
License-File: LICENSE
|
| 36 |
+
License-File: NOTICE
|
| 37 |
+
Requires-Dist: filelock
|
| 38 |
+
Requires-Dist: typing-extensions>=4.10.0
|
| 39 |
+
Requires-Dist: setuptools; python_version >= "3.12"
|
| 40 |
+
Requires-Dist: sympy>=1.13.3
|
| 41 |
+
Requires-Dist: networkx
|
| 42 |
+
Requires-Dist: jinja2
|
| 43 |
+
Requires-Dist: fsspec
|
| 44 |
+
Requires-Dist: nvidia-cuda-nvrtc-cu12==12.8.93; platform_system == "Linux" and platform_machine == "x86_64"
|
| 45 |
+
Requires-Dist: nvidia-cuda-runtime-cu12==12.8.90; platform_system == "Linux" and platform_machine == "x86_64"
|
| 46 |
+
Requires-Dist: nvidia-cuda-cupti-cu12==12.8.90; platform_system == "Linux" and platform_machine == "x86_64"
|
| 47 |
+
Requires-Dist: nvidia-cudnn-cu12==9.10.2.21; platform_system == "Linux" and platform_machine == "x86_64"
|
| 48 |
+
Requires-Dist: nvidia-cublas-cu12==12.8.4.1; platform_system == "Linux" and platform_machine == "x86_64"
|
| 49 |
+
Requires-Dist: nvidia-cufft-cu12==11.3.3.83; platform_system == "Linux" and platform_machine == "x86_64"
|
| 50 |
+
Requires-Dist: nvidia-curand-cu12==10.3.9.90; platform_system == "Linux" and platform_machine == "x86_64"
|
| 51 |
+
Requires-Dist: nvidia-cusolver-cu12==11.7.3.90; platform_system == "Linux" and platform_machine == "x86_64"
|
| 52 |
+
Requires-Dist: nvidia-cusparse-cu12==12.5.8.93; platform_system == "Linux" and platform_machine == "x86_64"
|
| 53 |
+
Requires-Dist: nvidia-cusparselt-cu12==0.7.1; platform_system == "Linux" and platform_machine == "x86_64"
|
| 54 |
+
Requires-Dist: nvidia-nccl-cu12==2.27.3; platform_system == "Linux" and platform_machine == "x86_64"
|
| 55 |
+
Requires-Dist: nvidia-nvtx-cu12==12.8.90; platform_system == "Linux" and platform_machine == "x86_64"
|
| 56 |
+
Requires-Dist: nvidia-nvjitlink-cu12==12.8.93; platform_system == "Linux" and platform_machine == "x86_64"
|
| 57 |
+
Requires-Dist: nvidia-cufile-cu12==1.13.1.3; platform_system == "Linux" and platform_machine == "x86_64"
|
| 58 |
+
Requires-Dist: triton==3.4.0; platform_system == "Linux" and platform_machine == "x86_64"
|
| 59 |
+
Provides-Extra: optree
|
| 60 |
+
Requires-Dist: optree>=0.13.0; extra == "optree"
|
| 61 |
+
Provides-Extra: opt-einsum
|
| 62 |
+
Requires-Dist: opt-einsum>=3.3; extra == "opt-einsum"
|
| 63 |
+
Provides-Extra: pyyaml
|
| 64 |
+
Requires-Dist: pyyaml; extra == "pyyaml"
|
| 65 |
+
Dynamic: author
|
| 66 |
+
Dynamic: author-email
|
| 67 |
+
Dynamic: classifier
|
| 68 |
+
Dynamic: description
|
| 69 |
+
Dynamic: description-content-type
|
| 70 |
+
Dynamic: download-url
|
| 71 |
+
Dynamic: home-page
|
| 72 |
+
Dynamic: keywords
|
| 73 |
+
Dynamic: license-file
|
| 74 |
+
Dynamic: provides-extra
|
| 75 |
+
Dynamic: requires-dist
|
| 76 |
+
Dynamic: requires-python
|
| 77 |
+
Dynamic: summary
|
| 78 |
+
|
| 79 |
+

|
| 80 |
+
|
| 81 |
+
--------------------------------------------------------------------------------
|
| 82 |
+
|
| 83 |
+
PyTorch is a Python package that provides two high-level features:
|
| 84 |
+
- Tensor computation (like NumPy) with strong GPU acceleration
|
| 85 |
+
- Deep neural networks built on a tape-based autograd system
|
| 86 |
+
|
| 87 |
+
You can reuse your favorite Python packages such as NumPy, SciPy, and Cython to extend PyTorch when needed.
|
| 88 |
+
|
| 89 |
+
Our trunk health (Continuous Integration signals) can be found at [hud.pytorch.org](https://hud.pytorch.org/ci/pytorch/pytorch/main).
|
| 90 |
+
|
| 91 |
+
<!-- toc -->
|
| 92 |
+
|
| 93 |
+
- [More About PyTorch](#more-about-pytorch)
|
| 94 |
+
- [A GPU-Ready Tensor Library](#a-gpu-ready-tensor-library)
|
| 95 |
+
- [Dynamic Neural Networks: Tape-Based Autograd](#dynamic-neural-networks-tape-based-autograd)
|
| 96 |
+
- [Python First](#python-first)
|
| 97 |
+
- [Imperative Experiences](#imperative-experiences)
|
| 98 |
+
- [Fast and Lean](#fast-and-lean)
|
| 99 |
+
- [Extensions Without Pain](#extensions-without-pain)
|
| 100 |
+
- [Installation](#installation)
|
| 101 |
+
- [Binaries](#binaries)
|
| 102 |
+
- [NVIDIA Jetson Platforms](#nvidia-jetson-platforms)
|
| 103 |
+
- [From Source](#from-source)
|
| 104 |
+
- [Prerequisites](#prerequisites)
|
| 105 |
+
- [NVIDIA CUDA Support](#nvidia-cuda-support)
|
| 106 |
+
- [AMD ROCm Support](#amd-rocm-support)
|
| 107 |
+
- [Intel GPU Support](#intel-gpu-support)
|
| 108 |
+
- [Get the PyTorch Source](#get-the-pytorch-source)
|
| 109 |
+
- [Install Dependencies](#install-dependencies)
|
| 110 |
+
- [Install PyTorch](#install-pytorch)
|
| 111 |
+
- [Adjust Build Options (Optional)](#adjust-build-options-optional)
|
| 112 |
+
- [Docker Image](#docker-image)
|
| 113 |
+
- [Using pre-built images](#using-pre-built-images)
|
| 114 |
+
- [Building the image yourself](#building-the-image-yourself)
|
| 115 |
+
- [Building the Documentation](#building-the-documentation)
|
| 116 |
+
- [Building a PDF](#building-a-pdf)
|
| 117 |
+
- [Previous Versions](#previous-versions)
|
| 118 |
+
- [Getting Started](#getting-started)
|
| 119 |
+
- [Resources](#resources)
|
| 120 |
+
- [Communication](#communication)
|
| 121 |
+
- [Releases and Contributing](#releases-and-contributing)
|
| 122 |
+
- [The Team](#the-team)
|
| 123 |
+
- [License](#license)
|
| 124 |
+
|
| 125 |
+
<!-- tocstop -->
|
| 126 |
+
|
| 127 |
+
## More About PyTorch
|
| 128 |
+
|
| 129 |
+
[Learn the basics of PyTorch](https://pytorch.org/tutorials/beginner/basics/intro.html)
|
| 130 |
+
|
| 131 |
+
At a granular level, PyTorch is a library that consists of the following components:
|
| 132 |
+
|
| 133 |
+
| Component | Description |
|
| 134 |
+
| ---- | --- |
|
| 135 |
+
| [**torch**](https://pytorch.org/docs/stable/torch.html) | A Tensor library like NumPy, with strong GPU support |
|
| 136 |
+
| [**torch.autograd**](https://pytorch.org/docs/stable/autograd.html) | A tape-based automatic differentiation library that supports all differentiable Tensor operations in torch |
|
| 137 |
+
| [**torch.jit**](https://pytorch.org/docs/stable/jit.html) | A compilation stack (TorchScript) to create serializable and optimizable models from PyTorch code |
|
| 138 |
+
| [**torch.nn**](https://pytorch.org/docs/stable/nn.html) | A neural networks library deeply integrated with autograd designed for maximum flexibility |
|
| 139 |
+
| [**torch.multiprocessing**](https://pytorch.org/docs/stable/multiprocessing.html) | Python multiprocessing, but with magical memory sharing of torch Tensors across processes. Useful for data loading and Hogwild training |
|
| 140 |
+
| [**torch.utils**](https://pytorch.org/docs/stable/data.html) | DataLoader and other utility functions for convenience |
|
| 141 |
+
|
| 142 |
+
Usually, PyTorch is used either as:
|
| 143 |
+
|
| 144 |
+
- A replacement for NumPy to use the power of GPUs.
|
| 145 |
+
- A deep learning research platform that provides maximum flexibility and speed.
|
| 146 |
+
|
| 147 |
+
Elaborating Further:
|
| 148 |
+
|
| 149 |
+
### A GPU-Ready Tensor Library
|
| 150 |
+
|
| 151 |
+
If you use NumPy, then you have used Tensors (a.k.a. ndarray).
|
| 152 |
+
|
| 153 |
+

|
| 154 |
+
|
| 155 |
+
PyTorch provides Tensors that can live either on the CPU or the GPU and accelerates the
|
| 156 |
+
computation by a huge amount.
|
| 157 |
+
|
| 158 |
+
We provide a wide variety of tensor routines to accelerate and fit your scientific computation needs
|
| 159 |
+
such as slicing, indexing, mathematical operations, linear algebra, reductions.
|
| 160 |
+
And they are fast!
|
| 161 |
+
|
| 162 |
+
### Dynamic Neural Networks: Tape-Based Autograd
|
| 163 |
+
|
| 164 |
+
PyTorch has a unique way of building neural networks: using and replaying a tape recorder.
|
| 165 |
+
|
| 166 |
+
Most frameworks such as TensorFlow, Theano, Caffe, and CNTK have a static view of the world.
|
| 167 |
+
One has to build a neural network and reuse the same structure again and again.
|
| 168 |
+
Changing the way the network behaves means that one has to start from scratch.
|
| 169 |
+
|
| 170 |
+
With PyTorch, we use a technique called reverse-mode auto-differentiation, which allows you to
|
| 171 |
+
change the way your network behaves arbitrarily with zero lag or overhead. Our inspiration comes
|
| 172 |
+
from several research papers on this topic, as well as current and past work such as
|
| 173 |
+
[torch-autograd](https://github.com/twitter/torch-autograd),
|
| 174 |
+
[autograd](https://github.com/HIPS/autograd),
|
| 175 |
+
[Chainer](https://chainer.org), etc.
|
| 176 |
+
|
| 177 |
+
While this technique is not unique to PyTorch, it's one of the fastest implementations of it to date.
|
| 178 |
+
You get the best of speed and flexibility for your crazy research.
|
| 179 |
+
|
| 180 |
+

|
| 181 |
+
|
| 182 |
+
### Python First
|
| 183 |
+
|
| 184 |
+
PyTorch is not a Python binding into a monolithic C++ framework.
|
| 185 |
+
It is built to be deeply integrated into Python.
|
| 186 |
+
You can use it naturally like you would use [NumPy](https://www.numpy.org/) / [SciPy](https://www.scipy.org/) / [scikit-learn](https://scikit-learn.org) etc.
|
| 187 |
+
You can write your new neural network layers in Python itself, using your favorite libraries
|
| 188 |
+
and use packages such as [Cython](https://cython.org/) and [Numba](http://numba.pydata.org/).
|
| 189 |
+
Our goal is to not reinvent the wheel where appropriate.
|
| 190 |
+
|
| 191 |
+
### Imperative Experiences
|
| 192 |
+
|
| 193 |
+
PyTorch is designed to be intuitive, linear in thought, and easy to use.
|
| 194 |
+
When you execute a line of code, it gets executed. There isn't an asynchronous view of the world.
|
| 195 |
+
When you drop into a debugger or receive error messages and stack traces, understanding them is straightforward.
|
| 196 |
+
The stack trace points to exactly where your code was defined.
|
| 197 |
+
We hope you never spend hours debugging your code because of bad stack traces or asynchronous and opaque execution engines.
|
| 198 |
+
|
| 199 |
+
### Fast and Lean
|
| 200 |
+
|
| 201 |
+
PyTorch has minimal framework overhead. We integrate acceleration libraries
|
| 202 |
+
such as [Intel MKL](https://software.intel.com/mkl) and NVIDIA ([cuDNN](https://developer.nvidia.com/cudnn), [NCCL](https://developer.nvidia.com/nccl)) to maximize speed.
|
| 203 |
+
At the core, its CPU and GPU Tensor and neural network backends
|
| 204 |
+
are mature and have been tested for years.
|
| 205 |
+
|
| 206 |
+
Hence, PyTorch is quite fast — whether you run small or large neural networks.
|
| 207 |
+
|
| 208 |
+
The memory usage in PyTorch is extremely efficient compared to Torch or some of the alternatives.
|
| 209 |
+
We've written custom memory allocators for the GPU to make sure that
|
| 210 |
+
your deep learning models are maximally memory efficient.
|
| 211 |
+
This enables you to train bigger deep learning models than before.
|
| 212 |
+
|
| 213 |
+
### Extensions Without Pain
|
| 214 |
+
|
| 215 |
+
Writing new neural network modules, or interfacing with PyTorch's Tensor API was designed to be straightforward
|
| 216 |
+
and with minimal abstractions.
|
| 217 |
+
|
| 218 |
+
You can write new neural network layers in Python using the torch API
|
| 219 |
+
[or your favorite NumPy-based libraries such as SciPy](https://pytorch.org/tutorials/advanced/numpy_extensions_tutorial.html).
|
| 220 |
+
|
| 221 |
+
If you want to write your layers in C/C++, we provide a convenient extension API that is efficient and with minimal boilerplate.
|
| 222 |
+
No wrapper code needs to be written. You can see [a tutorial here](https://pytorch.org/tutorials/advanced/cpp_extension.html) and [an example here](https://github.com/pytorch/extension-cpp).
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
## Installation
|
| 226 |
+
|
| 227 |
+
### Binaries
|
| 228 |
+
Commands to install binaries via Conda or pip wheels are on our website: [https://pytorch.org/get-started/locally/](https://pytorch.org/get-started/locally/)
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
#### NVIDIA Jetson Platforms
|
| 232 |
+
|
| 233 |
+
Python wheels for NVIDIA's Jetson Nano, Jetson TX1/TX2, Jetson Xavier NX/AGX, and Jetson AGX Orin are provided [here](https://forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-10-now-available/72048) and the L4T container is published [here](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/l4t-pytorch)
|
| 234 |
+
|
| 235 |
+
They require JetPack 4.2 and above, and [@dusty-nv](https://github.com/dusty-nv) and [@ptrblck](https://github.com/ptrblck) are maintaining them.
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
### From Source
|
| 239 |
+
|
| 240 |
+
#### Prerequisites
|
| 241 |
+
If you are installing from source, you will need:
|
| 242 |
+
- Python 3.9 or later
|
| 243 |
+
- A compiler that fully supports C++17, such as clang or gcc (gcc 9.4.0 or newer is required, on Linux)
|
| 244 |
+
- Visual Studio or Visual Studio Build Tool (Windows only)
|
| 245 |
+
|
| 246 |
+
\* PyTorch CI uses Visual C++ BuildTools, which come with Visual Studio Enterprise,
|
| 247 |
+
Professional, or Community Editions. You can also install the build tools from
|
| 248 |
+
https://visualstudio.microsoft.com/visual-cpp-build-tools/. The build tools *do not*
|
| 249 |
+
come with Visual Studio Code by default.
|
| 250 |
+
|
| 251 |
+
An example of environment setup is shown below:
|
| 252 |
+
|
| 253 |
+
* Linux:
|
| 254 |
+
|
| 255 |
+
```bash
|
| 256 |
+
$ source <CONDA_INSTALL_DIR>/bin/activate
|
| 257 |
+
$ conda create -y -n <CONDA_NAME>
|
| 258 |
+
$ conda activate <CONDA_NAME>
|
| 259 |
+
```
|
| 260 |
+
|
| 261 |
+
* Windows:
|
| 262 |
+
|
| 263 |
+
```bash
|
| 264 |
+
$ source <CONDA_INSTALL_DIR>\Scripts\activate.bat
|
| 265 |
+
$ conda create -y -n <CONDA_NAME>
|
| 266 |
+
$ conda activate <CONDA_NAME>
|
| 267 |
+
$ call "C:\Program Files\Microsoft Visual Studio\<VERSION>\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
|
| 268 |
+
```
|
| 269 |
+
|
| 270 |
+
A conda environment is not required. You can also do a PyTorch build in a
|
| 271 |
+
standard virtual environment, e.g., created with tools like `uv`, provided
|
| 272 |
+
your system has installed all the necessary dependencies unavailable as pip
|
| 273 |
+
packages (e.g., CUDA, MKL.)
|
| 274 |
+
|
| 275 |
+
##### NVIDIA CUDA Support
|
| 276 |
+
If you want to compile with CUDA support, [select a supported version of CUDA from our support matrix](https://pytorch.org/get-started/locally/), then install the following:
|
| 277 |
+
- [NVIDIA CUDA](https://developer.nvidia.com/cuda-downloads)
|
| 278 |
+
- [NVIDIA cuDNN](https://developer.nvidia.com/cudnn) v8.5 or above
|
| 279 |
+
- [Compiler](https://gist.github.com/ax3l/9489132) compatible with CUDA
|
| 280 |
+
|
| 281 |
+
Note: You could refer to the [cuDNN Support Matrix](https://docs.nvidia.com/deeplearning/cudnn/backend/latest/reference/support-matrix.html) for cuDNN versions with the various supported CUDA, CUDA driver and NVIDIA hardware
|
| 282 |
+
|
| 283 |
+
If you want to disable CUDA support, export the environment variable `USE_CUDA=0`.
|
| 284 |
+
Other potentially useful environment variables may be found in `setup.py`. If
|
| 285 |
+
CUDA is installed in a non-standard location, set PATH so that the nvcc you
|
| 286 |
+
want to use can be found (e.g., `export PATH=/usr/local/cuda-12.8/bin:$PATH`).
|
| 287 |
+
|
| 288 |
+
If you are building for NVIDIA's Jetson platforms (Jetson Nano, TX1, TX2, AGX Xavier), Instructions to install PyTorch for Jetson Nano are [available here](https://devtalk.nvidia.com/default/topic/1049071/jetson-nano/pytorch-for-jetson-nano/)
|
| 289 |
+
|
| 290 |
+
##### AMD ROCm Support
|
| 291 |
+
If you want to compile with ROCm support, install
|
| 292 |
+
- [AMD ROCm](https://rocm.docs.amd.com/en/latest/deploy/linux/quick_start.html) 4.0 and above installation
|
| 293 |
+
- ROCm is currently supported only for Linux systems.
|
| 294 |
+
|
| 295 |
+
By default the build system expects ROCm to be installed in `/opt/rocm`. If ROCm is installed in a different directory, the `ROCM_PATH` environment variable must be set to the ROCm installation directory. The build system automatically detects the AMD GPU architecture. Optionally, the AMD GPU architecture can be explicitly set with the `PYTORCH_ROCM_ARCH` environment variable [AMD GPU architecture](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/reference/system-requirements.html#supported-gpus)
|
| 296 |
+
|
| 297 |
+
If you want to disable ROCm support, export the environment variable `USE_ROCM=0`.
|
| 298 |
+
Other potentially useful environment variables may be found in `setup.py`.
|
| 299 |
+
|
| 300 |
+
##### Intel GPU Support
|
| 301 |
+
If you want to compile with Intel GPU support, follow these
|
| 302 |
+
- [PyTorch Prerequisites for Intel GPUs](https://www.intel.com/content/www/us/en/developer/articles/tool/pytorch-prerequisites-for-intel-gpus.html) instructions.
|
| 303 |
+
- Intel GPU is supported for Linux and Windows.
|
| 304 |
+
|
| 305 |
+
If you want to disable Intel GPU support, export the environment variable `USE_XPU=0`.
|
| 306 |
+
Other potentially useful environment variables may be found in `setup.py`.
|
| 307 |
+
|
| 308 |
+
#### Get the PyTorch Source
|
| 309 |
+
```bash
|
| 310 |
+
git clone https://github.com/pytorch/pytorch
|
| 311 |
+
cd pytorch
|
| 312 |
+
# if you are updating an existing checkout
|
| 313 |
+
git submodule sync
|
| 314 |
+
git submodule update --init --recursive
|
| 315 |
+
```
|
| 316 |
+
|
| 317 |
+
#### Install Dependencies
|
| 318 |
+
|
| 319 |
+
**Common**
|
| 320 |
+
|
| 321 |
+
```bash
|
| 322 |
+
conda install cmake ninja
|
| 323 |
+
# Run this command from the PyTorch directory after cloning the source code using the “Get the PyTorch Source“ section below
|
| 324 |
+
pip install -r requirements.txt
|
| 325 |
+
```
|
| 326 |
+
|
| 327 |
+
**On Linux**
|
| 328 |
+
|
| 329 |
+
```bash
|
| 330 |
+
pip install mkl-static mkl-include
|
| 331 |
+
# CUDA only: Add LAPACK support for the GPU if needed
|
| 332 |
+
# magma installation: run with active conda environment. specify CUDA version to install
|
| 333 |
+
.ci/docker/common/install_magma_conda.sh 12.4
|
| 334 |
+
|
| 335 |
+
# (optional) If using torch.compile with inductor/triton, install the matching version of triton
|
| 336 |
+
# Run from the pytorch directory after cloning
|
| 337 |
+
# For Intel GPU support, please explicitly `export USE_XPU=1` before running command.
|
| 338 |
+
make triton
|
| 339 |
+
```
|
| 340 |
+
|
| 341 |
+
**On MacOS**
|
| 342 |
+
|
| 343 |
+
```bash
|
| 344 |
+
# Add this package on intel x86 processor machines only
|
| 345 |
+
pip install mkl-static mkl-include
|
| 346 |
+
# Add these packages if torch.distributed is needed
|
| 347 |
+
conda install pkg-config libuv
|
| 348 |
+
```
|
| 349 |
+
|
| 350 |
+
**On Windows**
|
| 351 |
+
|
| 352 |
+
```bash
|
| 353 |
+
pip install mkl-static mkl-include
|
| 354 |
+
# Add these packages if torch.distributed is needed.
|
| 355 |
+
# Distributed package support on Windows is a prototype feature and is subject to changes.
|
| 356 |
+
conda install -c conda-forge libuv=1.39
|
| 357 |
+
```
|
| 358 |
+
|
| 359 |
+
#### Install PyTorch
|
| 360 |
+
**On Linux**
|
| 361 |
+
|
| 362 |
+
If you're compiling for AMD ROCm then first run this command:
|
| 363 |
+
```bash
|
| 364 |
+
# Only run this if you're compiling for ROCm
|
| 365 |
+
python tools/amd_build/build_amd.py
|
| 366 |
+
```
|
| 367 |
+
|
| 368 |
+
Install PyTorch
|
| 369 |
+
```bash
|
| 370 |
+
export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}"
|
| 371 |
+
python setup.py develop
|
| 372 |
+
```
|
| 373 |
+
|
| 374 |
+
**On macOS**
|
| 375 |
+
|
| 376 |
+
```bash
|
| 377 |
+
python3 setup.py develop
|
| 378 |
+
```
|
| 379 |
+
|
| 380 |
+
**On Windows**
|
| 381 |
+
|
| 382 |
+
If you want to build legacy python code, please refer to [Building on legacy code and CUDA](https://github.com/pytorch/pytorch/blob/main/CONTRIBUTING.md#building-on-legacy-code-and-cuda)
|
| 383 |
+
|
| 384 |
+
**CPU-only builds**
|
| 385 |
+
|
| 386 |
+
In this mode PyTorch computations will run on your CPU, not your GPU.
|
| 387 |
+
|
| 388 |
+
```cmd
|
| 389 |
+
python setup.py develop
|
| 390 |
+
```
|
| 391 |
+
|
| 392 |
+
Note on OpenMP: The desired OpenMP implementation is Intel OpenMP (iomp). In order to link against iomp, you'll need to manually download the library and set up the building environment by tweaking `CMAKE_INCLUDE_PATH` and `LIB`. The instruction [here](https://github.com/pytorch/pytorch/blob/main/docs/source/notes/windows.rst#building-from-source) is an example for setting up both MKL and Intel OpenMP. Without these configurations for CMake, Microsoft Visual C OpenMP runtime (vcomp) will be used.
|
| 393 |
+
|
| 394 |
+
**CUDA based build**
|
| 395 |
+
|
| 396 |
+
In this mode PyTorch computations will leverage your GPU via CUDA for faster number crunching
|
| 397 |
+
|
| 398 |
+
[NVTX](https://docs.nvidia.com/gameworks/content/gameworkslibrary/nvtx/nvidia_tools_extension_library_nvtx.htm) is needed to build Pytorch with CUDA.
|
| 399 |
+
NVTX is a part of CUDA distributive, where it is called "Nsight Compute". To install it onto an already installed CUDA run CUDA installation once again and check the corresponding checkbox.
|
| 400 |
+
Make sure that CUDA with Nsight Compute is installed after Visual Studio.
|
| 401 |
+
|
| 402 |
+
Currently, VS 2017 / 2019, and Ninja are supported as the generator of CMake. If `ninja.exe` is detected in `PATH`, then Ninja will be used as the default generator, otherwise, it will use VS 2017 / 2019.
|
| 403 |
+
<br/> If Ninja is selected as the generator, the latest MSVC will get selected as the underlying toolchain.
|
| 404 |
+
|
| 405 |
+
Additional libraries such as
|
| 406 |
+
[Magma](https://developer.nvidia.com/magma), [oneDNN, a.k.a. MKLDNN or DNNL](https://github.com/oneapi-src/oneDNN), and [Sccache](https://github.com/mozilla/sccache) are often needed. Please refer to the [installation-helper](https://github.com/pytorch/pytorch/tree/main/.ci/pytorch/win-test-helpers/installation-helpers) to install them.
|
| 407 |
+
|
| 408 |
+
You can refer to the [build_pytorch.bat](https://github.com/pytorch/pytorch/blob/main/.ci/pytorch/win-test-helpers/build_pytorch.bat) script for some other environment variables configurations
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
```cmd
|
| 412 |
+
cmd
|
| 413 |
+
|
| 414 |
+
:: Set the environment variables after you have downloaded and unzipped the mkl package,
|
| 415 |
+
:: else CMake would throw an error as `Could NOT find OpenMP`.
|
| 416 |
+
set CMAKE_INCLUDE_PATH={Your directory}\mkl\include
|
| 417 |
+
set LIB={Your directory}\mkl\lib;%LIB%
|
| 418 |
+
|
| 419 |
+
:: Read the content in the previous section carefully before you proceed.
|
| 420 |
+
:: [Optional] If you want to override the underlying toolset used by Ninja and Visual Studio with CUDA, please run the following script block.
|
| 421 |
+
:: "Visual Studio 2019 Developer Command Prompt" will be run automatically.
|
| 422 |
+
:: Make sure you have CMake >= 3.12 before you do this when you use the Visual Studio generator.
|
| 423 |
+
set CMAKE_GENERATOR_TOOLSET_VERSION=14.27
|
| 424 |
+
set DISTUTILS_USE_SDK=1
|
| 425 |
+
for /f "usebackq tokens=*" %i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version [15^,17^) -products * -latest -property installationPath`) do call "%i\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=%CMAKE_GENERATOR_TOOLSET_VERSION%
|
| 426 |
+
|
| 427 |
+
:: [Optional] If you want to override the CUDA host compiler
|
| 428 |
+
set CUDAHOSTCXX=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64\cl.exe
|
| 429 |
+
|
| 430 |
+
python setup.py develop
|
| 431 |
+
|
| 432 |
+
```
|
| 433 |
+
|
| 434 |
+
**Intel GPU builds**
|
| 435 |
+
|
| 436 |
+
In this mode PyTorch with Intel GPU support will be built.
|
| 437 |
+
|
| 438 |
+
Please make sure [the common prerequisites](#prerequisites) as well as [the prerequisites for Intel GPU](#intel-gpu-support) are properly installed and the environment variables are configured prior to starting the build. For build tool support, `Visual Studio 2022` is required.
|
| 439 |
+
|
| 440 |
+
Then PyTorch can be built with the command:
|
| 441 |
+
|
| 442 |
+
```cmd
|
| 443 |
+
:: CMD Commands:
|
| 444 |
+
:: Set the CMAKE_PREFIX_PATH to help find corresponding packages
|
| 445 |
+
:: %CONDA_PREFIX% only works after `conda activate custom_env`
|
| 446 |
+
|
| 447 |
+
if defined CMAKE_PREFIX_PATH (
|
| 448 |
+
set "CMAKE_PREFIX_PATH=%CONDA_PREFIX%\Library;%CMAKE_PREFIX_PATH%"
|
| 449 |
+
) else (
|
| 450 |
+
set "CMAKE_PREFIX_PATH=%CONDA_PREFIX%\Library"
|
| 451 |
+
)
|
| 452 |
+
|
| 453 |
+
python setup.py develop
|
| 454 |
+
```
|
| 455 |
+
|
| 456 |
+
##### Adjust Build Options (Optional)
|
| 457 |
+
|
| 458 |
+
You can adjust the configuration of cmake variables optionally (without building first), by doing
|
| 459 |
+
the following. For example, adjusting the pre-detected directories for CuDNN or BLAS can be done
|
| 460 |
+
with such a step.
|
| 461 |
+
|
| 462 |
+
On Linux
|
| 463 |
+
```bash
|
| 464 |
+
export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}"
|
| 465 |
+
CMAKE_ONLY=1 python setup.py build
|
| 466 |
+
ccmake build # or cmake-gui build
|
| 467 |
+
```
|
| 468 |
+
|
| 469 |
+
On macOS
|
| 470 |
+
```bash
|
| 471 |
+
export CMAKE_PREFIX_PATH="${CONDA_PREFIX:-'$(dirname $(which conda))/../'}:${CMAKE_PREFIX_PATH}"
|
| 472 |
+
MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ CMAKE_ONLY=1 python setup.py build
|
| 473 |
+
ccmake build # or cmake-gui build
|
| 474 |
+
```
|
| 475 |
+
|
| 476 |
+
### Docker Image
|
| 477 |
+
|
| 478 |
+
#### Using pre-built images
|
| 479 |
+
|
| 480 |
+
You can also pull a pre-built docker image from Docker Hub and run with docker v19.03+
|
| 481 |
+
|
| 482 |
+
```bash
|
| 483 |
+
docker run --gpus all --rm -ti --ipc=host pytorch/pytorch:latest
|
| 484 |
+
```
|
| 485 |
+
|
| 486 |
+
Please note that PyTorch uses shared memory to share data between processes, so if torch multiprocessing is used (e.g.
|
| 487 |
+
for multithreaded data loaders) the default shared memory segment size that container runs with is not enough, and you
|
| 488 |
+
should increase shared memory size either with `--ipc=host` or `--shm-size` command line options to `nvidia-docker run`.
|
| 489 |
+
|
| 490 |
+
#### Building the image yourself
|
| 491 |
+
|
| 492 |
+
**NOTE:** Must be built with a docker version > 18.06
|
| 493 |
+
|
| 494 |
+
The `Dockerfile` is supplied to build images with CUDA 11.1 support and cuDNN v8.
|
| 495 |
+
You can pass `PYTHON_VERSION=x.y` make variable to specify which Python version is to be used by Miniconda, or leave it
|
| 496 |
+
unset to use the default.
|
| 497 |
+
|
| 498 |
+
```bash
|
| 499 |
+
make -f docker.Makefile
|
| 500 |
+
# images are tagged as docker.io/${your_docker_username}/pytorch
|
| 501 |
+
```
|
| 502 |
+
|
| 503 |
+
You can also pass the `CMAKE_VARS="..."` environment variable to specify additional CMake variables to be passed to CMake during the build.
|
| 504 |
+
See [setup.py](./setup.py) for the list of available variables.
|
| 505 |
+
|
| 506 |
+
```bash
|
| 507 |
+
make -f docker.Makefile
|
| 508 |
+
```
|
| 509 |
+
|
| 510 |
+
### Building the Documentation
|
| 511 |
+
|
| 512 |
+
To build documentation in various formats, you will need [Sphinx](http://www.sphinx-doc.org)
|
| 513 |
+
and the pytorch_sphinx_theme2.
|
| 514 |
+
|
| 515 |
+
Before you build the documentation locally, ensure `torch` is
|
| 516 |
+
installed in your environment. For small fixes, you can install the
|
| 517 |
+
nightly version as described in [Getting Started](https://pytorch.org/get-started/locally/).
|
| 518 |
+
|
| 519 |
+
For more complex fixes, such as adding a new module and docstrings for
|
| 520 |
+
the new module, you might need to install torch [from source](#from-source).
|
| 521 |
+
See [Docstring Guidelines](https://github.com/pytorch/pytorch/wiki/Docstring-Guidelines)
|
| 522 |
+
for docstring conventions.
|
| 523 |
+
|
| 524 |
+
```bash
|
| 525 |
+
cd docs/
|
| 526 |
+
pip install -r requirements.txt
|
| 527 |
+
make html
|
| 528 |
+
make serve
|
| 529 |
+
```
|
| 530 |
+
|
| 531 |
+
Run `make` to get a list of all available output formats.
|
| 532 |
+
|
| 533 |
+
If you get a katex error run `npm install katex`. If it persists, try
|
| 534 |
+
`npm install -g katex`
|
| 535 |
+
|
| 536 |
+
> [!NOTE]
|
| 537 |
+
> If you installed `nodejs` with a different package manager (e.g.,
|
| 538 |
+
> `conda`) then `npm` will probably install a version of `katex` that is not
|
| 539 |
+
> compatible with your version of `nodejs` and doc builds will fail.
|
| 540 |
+
> A combination of versions that is known to work is `node@6.13.1` and
|
| 541 |
+
> `katex@0.13.18`. To install the latter with `npm` you can run
|
| 542 |
+
> ```npm install -g katex@0.13.18```
|
| 543 |
+
|
| 544 |
+
> [!NOTE]
|
| 545 |
+
> If you see a numpy incompatibility error, run:
|
| 546 |
+
> ```
|
| 547 |
+
> pip install 'numpy<2'
|
| 548 |
+
> ```
|
| 549 |
+
|
| 550 |
+
When you make changes to the dependencies run by CI, edit the
|
| 551 |
+
`.ci/docker/requirements-docs.txt` file.
|
| 552 |
+
|
| 553 |
+
#### Building a PDF
|
| 554 |
+
|
| 555 |
+
To compile a PDF of all PyTorch documentation, ensure you have
|
| 556 |
+
`texlive` and LaTeX installed. On macOS, you can install them using:
|
| 557 |
+
|
| 558 |
+
```
|
| 559 |
+
brew install --cask mactex
|
| 560 |
+
```
|
| 561 |
+
|
| 562 |
+
To create the PDF:
|
| 563 |
+
|
| 564 |
+
1. Run:
|
| 565 |
+
|
| 566 |
+
```
|
| 567 |
+
make latexpdf
|
| 568 |
+
```
|
| 569 |
+
|
| 570 |
+
This will generate the necessary files in the `build/latex` directory.
|
| 571 |
+
|
| 572 |
+
2. Navigate to this directory and execute:
|
| 573 |
+
|
| 574 |
+
```
|
| 575 |
+
make LATEXOPTS="-interaction=nonstopmode"
|
| 576 |
+
```
|
| 577 |
+
|
| 578 |
+
This will produce a `pytorch.pdf` with the desired content. Run this
|
| 579 |
+
command one more time so that it generates the correct table
|
| 580 |
+
of contents and index.
|
| 581 |
+
|
| 582 |
+
> [!NOTE]
|
| 583 |
+
> To view the Table of Contents, switch to the **Table of Contents**
|
| 584 |
+
> view in your PDF viewer.
|
| 585 |
+
|
| 586 |
+
|
| 587 |
+
### Previous Versions
|
| 588 |
+
|
| 589 |
+
Installation instructions and binaries for previous PyTorch versions may be found
|
| 590 |
+
on [our website](https://pytorch.org/get-started/previous-versions).
|
| 591 |
+
|
| 592 |
+
|
| 593 |
+
## Getting Started
|
| 594 |
+
|
| 595 |
+
Three-pointers to get you started:
|
| 596 |
+
- [Tutorials: get you started with understanding and using PyTorch](https://pytorch.org/tutorials/)
|
| 597 |
+
- [Examples: easy to understand PyTorch code across all domains](https://github.com/pytorch/examples)
|
| 598 |
+
- [The API Reference](https://pytorch.org/docs/)
|
| 599 |
+
- [Glossary](https://github.com/pytorch/pytorch/blob/main/GLOSSARY.md)
|
| 600 |
+
|
| 601 |
+
## Resources
|
| 602 |
+
|
| 603 |
+
* [PyTorch.org](https://pytorch.org/)
|
| 604 |
+
* [PyTorch Tutorials](https://pytorch.org/tutorials/)
|
| 605 |
+
* [PyTorch Examples](https://github.com/pytorch/examples)
|
| 606 |
+
* [PyTorch Models](https://pytorch.org/hub/)
|
| 607 |
+
* [Intro to Deep Learning with PyTorch from Udacity](https://www.udacity.com/course/deep-learning-pytorch--ud188)
|
| 608 |
+
* [Intro to Machine Learning with PyTorch from Udacity](https://www.udacity.com/course/intro-to-machine-learning-nanodegree--nd229)
|
| 609 |
+
* [Deep Neural Networks with PyTorch from Coursera](https://www.coursera.org/learn/deep-neural-networks-with-pytorch)
|
| 610 |
+
* [PyTorch Twitter](https://twitter.com/PyTorch)
|
| 611 |
+
* [PyTorch Blog](https://pytorch.org/blog/)
|
| 612 |
+
* [PyTorch YouTube](https://www.youtube.com/channel/UCWXI5YeOsh03QvJ59PMaXFw)
|
| 613 |
+
|
| 614 |
+
## Communication
|
| 615 |
+
* Forums: Discuss implementations, research, etc. https://discuss.pytorch.org
|
| 616 |
+
* GitHub Issues: Bug reports, feature requests, install issues, RFCs, thoughts, etc.
|
| 617 |
+
* Slack: The [PyTorch Slack](https://pytorch.slack.com/) hosts a primary audience of moderate to experienced PyTorch users and developers for general chat, online discussions, collaboration, etc. If you are a beginner looking for help, the primary medium is [PyTorch Forums](https://discuss.pytorch.org). If you need a slack invite, please fill this form: https://goo.gl/forms/PP1AGvNHpSaJP8to1
|
| 618 |
+
* Newsletter: No-noise, a one-way email newsletter with important announcements about PyTorch. You can sign-up here: https://eepurl.com/cbG0rv
|
| 619 |
+
* Facebook Page: Important announcements about PyTorch. https://www.facebook.com/pytorch
|
| 620 |
+
* For brand guidelines, please visit our website at [pytorch.org](https://pytorch.org/)
|
| 621 |
+
|
| 622 |
+
## Releases and Contributing
|
| 623 |
+
|
| 624 |
+
Typically, PyTorch has three minor releases a year. Please let us know if you encounter a bug by [filing an issue](https://github.com/pytorch/pytorch/issues).
|
| 625 |
+
|
| 626 |
+
We appreciate all contributions. If you are planning to contribute back bug-fixes, please do so without any further discussion.
|
| 627 |
+
|
| 628 |
+
If you plan to contribute new features, utility functions, or extensions to the core, please first open an issue and discuss the feature with us.
|
| 629 |
+
Sending a PR without discussion might end up resulting in a rejected PR because we might be taking the core in a different direction than you might be aware of.
|
| 630 |
+
|
| 631 |
+
To learn more about making a contribution to Pytorch, please see our [Contribution page](CONTRIBUTING.md). For more information about PyTorch releases, see [Release page](RELEASE.md).
|
| 632 |
+
|
| 633 |
+
## The Team
|
| 634 |
+
|
| 635 |
+
PyTorch is a community-driven project with several skillful engineers and researchers contributing to it.
|
| 636 |
+
|
| 637 |
+
PyTorch is currently maintained by [Soumith Chintala](http://soumith.ch), [Gregory Chanan](https://github.com/gchanan), [Dmytro Dzhulgakov](https://github.com/dzhulgakov), [Edward Yang](https://github.com/ezyang), and [Nikita Shulga](https://github.com/malfet) with major contributions coming from hundreds of talented individuals in various forms and means.
|
| 638 |
+
A non-exhaustive but growing list needs to mention: [Trevor Killeen](https://github.com/killeent), [Sasank Chilamkurthy](https://github.com/chsasank), [Sergey Zagoruyko](https://github.com/szagoruyko), [Adam Lerer](https://github.com/adamlerer), [Francisco Massa](https://github.com/fmassa), [Alykhan Tejani](https://github.com/alykhantejani), [Luca Antiga](https://github.com/lantiga), [Alban Desmaison](https://github.com/albanD), [Andreas Koepf](https://github.com/andreaskoepf), [James Bradbury](https://github.com/jekbradbury), [Zeming Lin](https://github.com/ebetica), [Yuandong Tian](https://github.com/yuandong-tian), [Guillaume Lample](https://github.com/glample), [Marat Dukhan](https://github.com/Maratyszcza), [Natalia Gimelshein](https://github.com/ngimel), [Christian Sarofeen](https://github.com/csarofeen), [Martin Raison](https://github.com/martinraison), [Edward Yang](https://github.com/ezyang), [Zachary Devito](https://github.com/zdevito). <!-- codespell:ignore -->
|
| 639 |
+
|
| 640 |
+
Note: This project is unrelated to [hughperkins/pytorch](https://github.com/hughperkins/pytorch) with the same name. Hugh is a valuable contributor to the Torch community and has helped with many things Torch and PyTorch.
|
| 641 |
+
|
| 642 |
+
## License
|
| 643 |
+
|
| 644 |
+
PyTorch has a BSD-style license, as found in the [LICENSE](LICENSE) file.
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/RECORD
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/REQUESTED
ADDED
|
File without changes
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (79.0.1)
|
| 3 |
+
Root-Is-Purelib: false
|
| 4 |
+
Tag: cp310-cp310-manylinux_2_28_x86_64
|
| 5 |
+
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/entry_points.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[console_scripts]
|
| 2 |
+
torchfrtrace = tools.flight_recorder.fr_trace:main
|
| 3 |
+
torchrun = torch.distributed.run:main
|
| 4 |
+
|
| 5 |
+
[torchrun.logs_specs]
|
| 6 |
+
default = torch.distributed.elastic.multiprocessing:DefaultLogsSpecs
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/licenses/LICENSE
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/licenses/NOTICE
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
=======================================================================
|
| 2 |
+
Software under third_party
|
| 3 |
+
=======================================================================
|
| 4 |
+
Software libraries under third_party are provided as github submodule
|
| 5 |
+
links, and their content is not part of the Caffe2 codebase. Their
|
| 6 |
+
licences can be found under the respective software repositories.
|
| 7 |
+
|
| 8 |
+
=======================================================================
|
| 9 |
+
Earlier BSD License
|
| 10 |
+
=======================================================================
|
| 11 |
+
Early development of Caffe2 in 2015 and early 2016 is licensed under the
|
| 12 |
+
BSD license. The license is attached below:
|
| 13 |
+
|
| 14 |
+
All contributions by Facebook:
|
| 15 |
+
Copyright (c) 2016 Facebook Inc.
|
| 16 |
+
|
| 17 |
+
All contributions by Google:
|
| 18 |
+
Copyright (c) 2015 Google Inc.
|
| 19 |
+
All rights reserved.
|
| 20 |
+
|
| 21 |
+
All contributions by Yangqing Jia:
|
| 22 |
+
Copyright (c) 2015 Yangqing Jia
|
| 23 |
+
All rights reserved.
|
| 24 |
+
|
| 25 |
+
All contributions by Kakao Brain:
|
| 26 |
+
Copyright 2019-2020 Kakao Brain
|
| 27 |
+
|
| 28 |
+
All other contributions:
|
| 29 |
+
Copyright(c) 2015, 2016 the respective contributors
|
| 30 |
+
All rights reserved.
|
| 31 |
+
|
| 32 |
+
Redistribution and use in source and binary forms, with or without
|
| 33 |
+
modification, are permitted provided that the following conditions are met:
|
| 34 |
+
|
| 35 |
+
1. Redistributions of source code must retain the above copyright notice, this
|
| 36 |
+
list of conditions and the following disclaimer.
|
| 37 |
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
| 38 |
+
this list of conditions and the following disclaimer in the documentation
|
| 39 |
+
and/or other materials provided with the distribution.
|
| 40 |
+
|
| 41 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 42 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 43 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 44 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
| 45 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 46 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 47 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 48 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 49 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 50 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
=======================================================================
|
| 54 |
+
Caffe's BSD License
|
| 55 |
+
=======================================================================
|
| 56 |
+
Some parts of the caffe2 code is derived from the original Caffe code, which is
|
| 57 |
+
created by Yangqing Jia and is now a BSD-licensed open-source project. The Caffe
|
| 58 |
+
license is as follows:
|
| 59 |
+
|
| 60 |
+
COPYRIGHT
|
| 61 |
+
|
| 62 |
+
All contributions by the University of California:
|
| 63 |
+
Copyright (c) 2014, The Regents of the University of California (Regents)
|
| 64 |
+
All rights reserved.
|
| 65 |
+
|
| 66 |
+
All other contributions:
|
| 67 |
+
Copyright (c) 2014, the respective contributors
|
| 68 |
+
All rights reserved.
|
| 69 |
+
|
| 70 |
+
Caffe uses a shared copyright model: each contributor holds copyright over
|
| 71 |
+
their contributions to Caffe. The project versioning records all such
|
| 72 |
+
contribution and copyright details. If a contributor wants to further mark
|
| 73 |
+
their specific copyright on a particular contribution, they should indicate
|
| 74 |
+
their copyright solely in the commit message of the change when it is
|
| 75 |
+
committed.
|
| 76 |
+
|
| 77 |
+
LICENSE
|
| 78 |
+
|
| 79 |
+
Redistribution and use in source and binary forms, with or without
|
| 80 |
+
modification, are permitted provided that the following conditions are met:
|
| 81 |
+
|
| 82 |
+
1. Redistributions of source code must retain the above copyright notice, this
|
| 83 |
+
list of conditions and the following disclaimer.
|
| 84 |
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
| 85 |
+
this list of conditions and the following disclaimer in the documentation
|
| 86 |
+
and/or other materials provided with the distribution.
|
| 87 |
+
|
| 88 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 89 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 90 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 91 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
| 92 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 93 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 94 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 95 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 96 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 97 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 98 |
+
|
| 99 |
+
CONTRIBUTION AGREEMENT
|
| 100 |
+
|
| 101 |
+
By contributing to the BVLC/caffe repository through pull-request, comment,
|
| 102 |
+
or otherwise, the contributor releases their content to the
|
| 103 |
+
license and copyright terms herein.
|
| 104 |
+
|
| 105 |
+
=======================================================================
|
| 106 |
+
Caffe2's Apache License
|
| 107 |
+
=======================================================================
|
| 108 |
+
|
| 109 |
+
This repo contains Caffe2 code, which was previously licensed under
|
| 110 |
+
Apache License Version 2.0:
|
| 111 |
+
|
| 112 |
+
Apache License
|
| 113 |
+
Version 2.0, January 2004
|
| 114 |
+
http://www.apache.org/licenses/
|
| 115 |
+
|
| 116 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 117 |
+
|
| 118 |
+
1. Definitions.
|
| 119 |
+
|
| 120 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 121 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 122 |
+
|
| 123 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 124 |
+
the copyright owner that is granting the License.
|
| 125 |
+
|
| 126 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 127 |
+
other entities that control, are controlled by, or are under common
|
| 128 |
+
control with that entity. For the purposes of this definition,
|
| 129 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 130 |
+
direction or management of such entity, whether by contract or
|
| 131 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 132 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 133 |
+
|
| 134 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 135 |
+
exercising permissions granted by this License.
|
| 136 |
+
|
| 137 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 138 |
+
including but not limited to software source code, documentation
|
| 139 |
+
source, and configuration files.
|
| 140 |
+
|
| 141 |
+
"Object" form shall mean any form resulting from mechanical
|
| 142 |
+
transformation or translation of a Source form, including but
|
| 143 |
+
not limited to compiled object code, generated documentation,
|
| 144 |
+
and conversions to other media types.
|
| 145 |
+
|
| 146 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 147 |
+
Object form, made available under the License, as indicated by a
|
| 148 |
+
copyright notice that is included in or attached to the work
|
| 149 |
+
(an example is provided in the Appendix below).
|
| 150 |
+
|
| 151 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 152 |
+
form, that is based on (or derived from) the Work and for which the
|
| 153 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 154 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 155 |
+
of this License, Derivative Works shall not include works that remain
|
| 156 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 157 |
+
the Work and Derivative Works thereof.
|
| 158 |
+
|
| 159 |
+
"Contribution" shall mean any work of authorship, including
|
| 160 |
+
the original version of the Work and any modifications or additions
|
| 161 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 162 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 163 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 164 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 165 |
+
means any form of electronic, verbal, or written communication sent
|
| 166 |
+
to the Licensor or its representatives, including but not limited to
|
| 167 |
+
communication on electronic mailing lists, source code control systems,
|
| 168 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 169 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 170 |
+
excluding communication that is conspicuously marked or otherwise
|
| 171 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 172 |
+
|
| 173 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 174 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 175 |
+
subsequently incorporated within the Work.
|
| 176 |
+
|
| 177 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 178 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 179 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 180 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 181 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 182 |
+
Work and such Derivative Works in Source or Object form.
|
| 183 |
+
|
| 184 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 185 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 186 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 187 |
+
(except as stated in this section) patent license to make, have made,
|
| 188 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 189 |
+
where such license applies only to those patent claims licensable
|
| 190 |
+
by such Contributor that are necessarily infringed by their
|
| 191 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 192 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 193 |
+
institute patent litigation against any entity (including a
|
| 194 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 195 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 196 |
+
or contributory patent infringement, then any patent licenses
|
| 197 |
+
granted to You under this License for that Work shall terminate
|
| 198 |
+
as of the date such litigation is filed.
|
| 199 |
+
|
| 200 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 201 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 202 |
+
modifications, and in Source or Object form, provided that You
|
| 203 |
+
meet the following conditions:
|
| 204 |
+
|
| 205 |
+
(a) You must give any other recipients of the Work or
|
| 206 |
+
Derivative Works a copy of this License; and
|
| 207 |
+
|
| 208 |
+
(b) You must cause any modified files to carry prominent notices
|
| 209 |
+
stating that You changed the files; and
|
| 210 |
+
|
| 211 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 212 |
+
that You distribute, all copyright, patent, trademark, and
|
| 213 |
+
attribution notices from the Source form of the Work,
|
| 214 |
+
excluding those notices that do not pertain to any part of
|
| 215 |
+
the Derivative Works; and
|
| 216 |
+
|
| 217 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 218 |
+
distribution, then any Derivative Works that You distribute must
|
| 219 |
+
include a readable copy of the attribution notices contained
|
| 220 |
+
within such NOTICE file, excluding those notices that do not
|
| 221 |
+
pertain to any part of the Derivative Works, in at least one
|
| 222 |
+
of the following places: within a NOTICE text file distributed
|
| 223 |
+
as part of the Derivative Works; within the Source form or
|
| 224 |
+
documentation, if provided along with the Derivative Works; or,
|
| 225 |
+
within a display generated by the Derivative Works, if and
|
| 226 |
+
wherever such third-party notices normally appear. The contents
|
| 227 |
+
of the NOTICE file are for informational purposes only and
|
| 228 |
+
do not modify the License. You may add Your own attribution
|
| 229 |
+
notices within Derivative Works that You distribute, alongside
|
| 230 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 231 |
+
that such additional attribution notices cannot be construed
|
| 232 |
+
as modifying the License.
|
| 233 |
+
|
| 234 |
+
You may add Your own copyright statement to Your modifications and
|
| 235 |
+
may provide additional or different license terms and conditions
|
| 236 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 237 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 238 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 239 |
+
the conditions stated in this License.
|
| 240 |
+
|
| 241 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 242 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 243 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 244 |
+
this License, without any additional terms or conditions.
|
| 245 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 246 |
+
the terms of any separate license agreement you may have executed
|
| 247 |
+
with Licensor regarding such Contributions.
|
| 248 |
+
|
| 249 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 250 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 251 |
+
except as required for reasonable and customary use in describing the
|
| 252 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 253 |
+
|
| 254 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 255 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 256 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 257 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 258 |
+
implied, including, without limitation, any warranties or conditions
|
| 259 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 260 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 261 |
+
appropriateness of using or redistributing the Work and assume any
|
| 262 |
+
risks associated with Your exercise of permissions under this License.
|
| 263 |
+
|
| 264 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 265 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 266 |
+
unless required by applicable law (such as deliberate and grossly
|
| 267 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 268 |
+
liable to You for damages, including any direct, indirect, special,
|
| 269 |
+
incidental, or consequential damages of any character arising as a
|
| 270 |
+
result of this License or out of the use or inability to use the
|
| 271 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 272 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 273 |
+
other commercial damages or losses), even if such Contributor
|
| 274 |
+
has been advised of the possibility of such damages.
|
| 275 |
+
|
| 276 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 277 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 278 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 279 |
+
or other liability obligations and/or rights consistent with this
|
| 280 |
+
License. However, in accepting such obligations, You may act only
|
| 281 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 282 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 283 |
+
defend, and hold each Contributor harmless for any liability
|
| 284 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 285 |
+
of your accepting any such warranty or additional liability.
|
| 286 |
+
|
| 287 |
+
=======================================================================
|
| 288 |
+
Cephes's 3-Clause BSD License
|
| 289 |
+
=======================================================================
|
| 290 |
+
|
| 291 |
+
Code derived from implementations in the Cephes Math Library should mention
|
| 292 |
+
its derivation and reference the following license:
|
| 293 |
+
|
| 294 |
+
3-Clause BSD License for the Cephes Math Library
|
| 295 |
+
Copyright (c) 2018, Steven Moshier
|
| 296 |
+
All rights reserved.
|
| 297 |
+
|
| 298 |
+
Redistribution and use in source and binary forms, with or without
|
| 299 |
+
modification, are permitted provided that the following conditions are met:
|
| 300 |
+
|
| 301 |
+
* Redistributions of source code must retain the above copyright
|
| 302 |
+
notice, this list of conditions and the following disclaimer.
|
| 303 |
+
|
| 304 |
+
* Redistributions in binary form must reproduce the above copyright
|
| 305 |
+
notice, this list of conditions and the following disclaimer in the
|
| 306 |
+
documentation and/or other materials provided with the distribution.
|
| 307 |
+
|
| 308 |
+
* Neither the name of the nor the
|
| 309 |
+
names of its contributors may be used to endorse or promote products
|
| 310 |
+
derived from this software without specific prior written permission.
|
| 311 |
+
|
| 312 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 313 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 314 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 315 |
+
DISCLAIMED. IN NO EVENT SHALL Steven Moshier BE LIABLE FOR ANY
|
| 316 |
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
| 317 |
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
| 318 |
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
| 319 |
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 320 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 321 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
=======================================================================
|
| 325 |
+
SciPy's 3-Clause BSD License
|
| 326 |
+
=======================================================================
|
| 327 |
+
|
| 328 |
+
Code derived from implementations in SciPy should mention its derivation
|
| 329 |
+
and reference the following license:
|
| 330 |
+
|
| 331 |
+
Copyright (c) 2001-2002 Enthought, Inc. 2003-2019, SciPy Developers.
|
| 332 |
+
All rights reserved.
|
| 333 |
+
|
| 334 |
+
Redistribution and use in source and binary forms, with or without
|
| 335 |
+
modification, are permitted provided that the following conditions
|
| 336 |
+
are met:
|
| 337 |
+
|
| 338 |
+
1. Redistributions of source code must retain the above copyright
|
| 339 |
+
notice, this list of conditions and the following disclaimer.
|
| 340 |
+
|
| 341 |
+
2. Redistributions in binary form must reproduce the above
|
| 342 |
+
copyright notice, this list of conditions and the following
|
| 343 |
+
disclaimer in the documentation and/or other materials provided
|
| 344 |
+
with the distribution.
|
| 345 |
+
|
| 346 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 347 |
+
contributors may be used to endorse or promote products derived
|
| 348 |
+
from this software without specific prior written permission.
|
| 349 |
+
|
| 350 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 351 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 352 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 353 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 354 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 355 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 356 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 357 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 358 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 359 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 360 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 361 |
+
|
| 362 |
+
=======================================================================
|
| 363 |
+
Boost's 1.0 Software License
|
| 364 |
+
=======================================================================
|
| 365 |
+
|
| 366 |
+
Code derived from implementations in Boost 1.0 should mention its
|
| 367 |
+
derivation and reference the following license:
|
| 368 |
+
|
| 369 |
+
Boost Software License - Version 1.0 - August 17th, 2003
|
| 370 |
+
|
| 371 |
+
Permission is hereby granted, free of charge, to any person or organization
|
| 372 |
+
obtaining a copy of the software and accompanying documentation covered by
|
| 373 |
+
this license (the "Software") to use, reproduce, display, distribute,
|
| 374 |
+
execute, and transmit the Software, and to prepare derivative works of the
|
| 375 |
+
Software, and to permit third-parties to whom the Software is furnished to
|
| 376 |
+
do so, all subject to the following:
|
| 377 |
+
|
| 378 |
+
The copyright notices in the Software and this entire statement, including
|
| 379 |
+
the above license grant, this restriction and the following disclaimer,
|
| 380 |
+
must be included in all copies of the Software, in whole or in part, and
|
| 381 |
+
all derivative works of the Software, unless such copies or derivative
|
| 382 |
+
works are solely in the form of machine-executable object code generated by
|
| 383 |
+
a source language processor.
|
| 384 |
+
|
| 385 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 386 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 387 |
+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
| 388 |
+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
| 389 |
+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
| 390 |
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
| 391 |
+
DEALINGS IN THE SOFTWARE.
|
| 392 |
+
|
| 393 |
+
END OF TERMS AND CONDITIONS
|
| 394 |
+
|
| 395 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 396 |
+
|
| 397 |
+
To apply the Apache License to your work, attach the following
|
| 398 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 399 |
+
replaced with your own identifying information. (Don't include
|
| 400 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 401 |
+
comment syntax for the file format. We also recommend that a
|
| 402 |
+
file or class name and description of purpose be included on the
|
| 403 |
+
same "printed page" as the copyright notice for easier
|
| 404 |
+
identification within third-party archives.
|
| 405 |
+
|
| 406 |
+
Copyright [yyyy] [name of copyright owner]
|
| 407 |
+
|
| 408 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 409 |
+
you may not use this file except in compliance with the License.
|
| 410 |
+
You may obtain a copy of the License at
|
| 411 |
+
|
| 412 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 413 |
+
|
| 414 |
+
Unless required by applicable law or agreed to in writing, software
|
| 415 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 416 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 417 |
+
See the License for the specific language governing permissions and
|
| 418 |
+
limitations under the License.
|
| 419 |
+
|
| 420 |
+
=======================================================================
|
| 421 |
+
PILLOW-SIMD Software License
|
| 422 |
+
=======================================================================
|
| 423 |
+
|
| 424 |
+
Code derived from implementations in PILLOW-SIMD should mention its derivation
|
| 425 |
+
and reference the following license:
|
| 426 |
+
|
| 427 |
+
The Python Imaging Library (PIL) is
|
| 428 |
+
|
| 429 |
+
Copyright © 1997-2011 by Secret Labs AB
|
| 430 |
+
Copyright © 1995-2011 by Fredrik Lundh
|
| 431 |
+
|
| 432 |
+
Pillow is the friendly PIL fork. It is
|
| 433 |
+
|
| 434 |
+
Copyright © 2010-2022 by Alex Clark and contributors
|
| 435 |
+
|
| 436 |
+
Like PIL, Pillow is licensed under the open source HPND License:
|
| 437 |
+
|
| 438 |
+
By obtaining, using, and/or copying this software and/or its associated
|
| 439 |
+
documentation, you agree that you have read, understood, and will comply
|
| 440 |
+
with the following terms and conditions:
|
| 441 |
+
|
| 442 |
+
Permission to use, copy, modify, and distribute this software and its
|
| 443 |
+
associated documentation for any purpose and without fee is hereby granted,
|
| 444 |
+
provided that the above copyright notice appears in all copies, and that
|
| 445 |
+
both that copyright notice and this permission notice appear in supporting
|
| 446 |
+
documentation, and that the name of Secret Labs AB or the author not be
|
| 447 |
+
used in advertising or publicity pertaining to distribution of the software
|
| 448 |
+
without specific, written prior permission.
|
| 449 |
+
|
| 450 |
+
SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
| 451 |
+
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
| 452 |
+
IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR ANY SPECIAL,
|
| 453 |
+
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
| 454 |
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
| 455 |
+
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
| 456 |
+
PERFORMANCE OF THIS SOFTWARE.
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch-2.8.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
functorch
|
| 2 |
+
torch
|
| 3 |
+
torchgen
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/conv2d.h
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/tensorexpr/operators/misc.h>
|
| 4 |
+
#include <torch/csrc/jit/tensorexpr/tensor.h>
|
| 5 |
+
|
| 6 |
+
namespace torch::jit::tensorexpr {
|
| 7 |
+
|
| 8 |
+
// An API to compute 2D depthwise convolutions with bias.
|
| 9 |
+
TORCH_API Tensor conv2d_depthwise(
|
| 10 |
+
BufHandle input,
|
| 11 |
+
BufHandle weight,
|
| 12 |
+
BufHandle bias,
|
| 13 |
+
int stride,
|
| 14 |
+
int pad,
|
| 15 |
+
int groups);
|
| 16 |
+
|
| 17 |
+
// An API to compute 2D depthwise convolutions without bias.
|
| 18 |
+
TORCH_API Tensor conv2d_depthwise(
|
| 19 |
+
BufHandle input,
|
| 20 |
+
BufHandle weight,
|
| 21 |
+
int stride,
|
| 22 |
+
int pad,
|
| 23 |
+
int groups);
|
| 24 |
+
|
| 25 |
+
TORCH_API Tensor conv2d_depthwise(
|
| 26 |
+
BufHandle input,
|
| 27 |
+
BufHandle weight,
|
| 28 |
+
BufHandle bias,
|
| 29 |
+
ExprHandle N,
|
| 30 |
+
ExprHandle C,
|
| 31 |
+
ExprHandle H,
|
| 32 |
+
ExprHandle W,
|
| 33 |
+
ExprHandle K,
|
| 34 |
+
ExprHandle CperG,
|
| 35 |
+
ExprHandle R,
|
| 36 |
+
ExprHandle S,
|
| 37 |
+
ExprHandle stride,
|
| 38 |
+
ExprHandle pad,
|
| 39 |
+
ExprHandle groups);
|
| 40 |
+
|
| 41 |
+
TORCH_API Tensor conv2d_depthwise(
|
| 42 |
+
BufHandle input,
|
| 43 |
+
BufHandle weight,
|
| 44 |
+
ExprHandle N,
|
| 45 |
+
ExprHandle C,
|
| 46 |
+
ExprHandle H,
|
| 47 |
+
ExprHandle W,
|
| 48 |
+
ExprHandle K,
|
| 49 |
+
ExprHandle CperG,
|
| 50 |
+
ExprHandle R,
|
| 51 |
+
ExprHandle S,
|
| 52 |
+
ExprHandle stride,
|
| 53 |
+
ExprHandle pad,
|
| 54 |
+
ExprHandle groups);
|
| 55 |
+
|
| 56 |
+
bool conv2dIsSupported(
|
| 57 |
+
const TensorInfo& input,
|
| 58 |
+
const TensorInfo& weight,
|
| 59 |
+
const TensorInfo& bias,
|
| 60 |
+
const std::vector<int64_t>& stride,
|
| 61 |
+
const std::vector<int64_t>& pad,
|
| 62 |
+
const std::vector<int64_t>& dilation,
|
| 63 |
+
int64_t groups);
|
| 64 |
+
bool mkldnnPrepackedConvIsSupported(
|
| 65 |
+
const TensorInfo& input,
|
| 66 |
+
const TensorInfo& weight,
|
| 67 |
+
const std::vector<int64_t>& stride,
|
| 68 |
+
const std::vector<int64_t>& pad,
|
| 69 |
+
const std::vector<int64_t>& dilation,
|
| 70 |
+
int64_t groups);
|
| 71 |
+
Tensor computeConv2d(
|
| 72 |
+
const std::vector<ArgValue>& inputs,
|
| 73 |
+
const std::vector<ExprHandle>& outputShape,
|
| 74 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 75 |
+
const std::optional<ScalarType>& outputType,
|
| 76 |
+
at::Device device);
|
| 77 |
+
Tensor computeConv1d(
|
| 78 |
+
const std::vector<ArgValue>& inputs,
|
| 79 |
+
const std::vector<ExprHandle>& outputShape,
|
| 80 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 81 |
+
const std::optional<ScalarType>& outputType,
|
| 82 |
+
at::Device device);
|
| 83 |
+
Tensor computePrepackedConv2dClampRun(
|
| 84 |
+
const std::vector<ArgValue>& inputs,
|
| 85 |
+
const std::vector<ExprHandle>& outputShape,
|
| 86 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 87 |
+
const std::optional<ScalarType>& outputType,
|
| 88 |
+
at::Device device);
|
| 89 |
+
Tensor computePrepackedLinearClampRun(
|
| 90 |
+
const std::vector<ArgValue>& inputs,
|
| 91 |
+
const std::vector<ExprHandle>& outputShape,
|
| 92 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 93 |
+
const std::optional<ScalarType>& outputType,
|
| 94 |
+
at::Device device);
|
| 95 |
+
Tensor computeMkldnnPrepackedConvRun(
|
| 96 |
+
const std::vector<ArgValue>& inputs,
|
| 97 |
+
const std::vector<ExprHandle>& outputShape,
|
| 98 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 99 |
+
const std::optional<ScalarType>& outputType,
|
| 100 |
+
at::Device device);
|
| 101 |
+
} // namespace torch::jit::tensorexpr
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/matmul.h
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/tensorexpr/kernel.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit::tensorexpr {
|
| 6 |
+
|
| 7 |
+
Tensor computeMatmul(
|
| 8 |
+
const std::vector<ArgValue>& inputs,
|
| 9 |
+
const std::vector<ExprHandle>& outputShape,
|
| 10 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 11 |
+
const std::optional<ScalarType>& outputType,
|
| 12 |
+
at::Device device);
|
| 13 |
+
Tensor computeAddMM(
|
| 14 |
+
const std::vector<ArgValue>& inputs,
|
| 15 |
+
const std::vector<ExprHandle>& outputShape,
|
| 16 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 17 |
+
const std::optional<ScalarType>& outputType,
|
| 18 |
+
at::Device device);
|
| 19 |
+
|
| 20 |
+
} // namespace torch::jit::tensorexpr
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/misc.h
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/tensorexpr/fwd_decls.h>
|
| 4 |
+
#include <torch/csrc/jit/tensorexpr/lowerings.h>
|
| 5 |
+
#include <torch/csrc/jit/tensorexpr/tensor.h>
|
| 6 |
+
|
| 7 |
+
namespace torch::jit::tensorexpr {
|
| 8 |
+
|
| 9 |
+
struct TensorInfo {
|
| 10 |
+
std::vector<int64_t> dims;
|
| 11 |
+
c10::ScalarType dtype;
|
| 12 |
+
};
|
| 13 |
+
std::optional<TensorInfo> getTensorInfo(const BufHandle& b);
|
| 14 |
+
|
| 15 |
+
int64_t normalizeAndCheckIndex(int64_t idx, int64_t list_size);
|
| 16 |
+
|
| 17 |
+
// Convert boolean to integer, if needed.
|
| 18 |
+
ExprHandle boolToInteger(const ExprHandle& x);
|
| 19 |
+
ExprHandle promoteToDtype(ExprHandle e, ScalarType dt);
|
| 20 |
+
void promoteInputs(
|
| 21 |
+
std::vector<ExprHandle>& inputs,
|
| 22 |
+
const int typeConstraints = kAllTypes);
|
| 23 |
+
ExprHandle promoteIntegerToDefaultType(const ExprHandle& e);
|
| 24 |
+
ExprHandle promoteHalfToFloat(const ExprHandle& e);
|
| 25 |
+
ExprHandle demoteOutput(
|
| 26 |
+
const ExprHandle& e,
|
| 27 |
+
const std::optional<ScalarType> type);
|
| 28 |
+
|
| 29 |
+
std::vector<ExprHandle> broadcastShapes(
|
| 30 |
+
std::vector<std::vector<ExprHandle>> shapes);
|
| 31 |
+
std::vector<ExprHandle> broadcastShapes(
|
| 32 |
+
const std::vector<ExprHandle>& a,
|
| 33 |
+
const std::vector<ExprHandle>& b);
|
| 34 |
+
|
| 35 |
+
std::vector<ExprHandle> valueShape(const ArgValue& v);
|
| 36 |
+
ExprHandle tensorOrConstant(
|
| 37 |
+
const ArgValue& v,
|
| 38 |
+
const std::vector<ExprHandle>& axes);
|
| 39 |
+
ExprHandle scalarOrConstant(const ArgValue& v);
|
| 40 |
+
ExprHandle broadcast(const BufHandle& b, const std::vector<ExprHandle>& axes);
|
| 41 |
+
ExprHandle constant(const ArgValue& v);
|
| 42 |
+
|
| 43 |
+
ExprHandle clamp(
|
| 44 |
+
const ExprHandle& cmin,
|
| 45 |
+
const ExprHandle& cmax,
|
| 46 |
+
const ExprHandle& input);
|
| 47 |
+
|
| 48 |
+
Tensor computeChunk(
|
| 49 |
+
const std::vector<ArgValue>& inputs,
|
| 50 |
+
const std::vector<ExprHandle>& outputShape,
|
| 51 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 52 |
+
const std::optional<ScalarType>& outputType,
|
| 53 |
+
at::Device device);
|
| 54 |
+
Tensor computeTranspose(
|
| 55 |
+
const std::vector<ArgValue>& inputs,
|
| 56 |
+
const std::vector<ExprHandle>& outputShape,
|
| 57 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 58 |
+
const std::optional<ScalarType>& outputType,
|
| 59 |
+
at::Device device);
|
| 60 |
+
Tensor computeExpand(
|
| 61 |
+
const std::vector<ArgValue>& inputs,
|
| 62 |
+
const std::vector<ExprHandle>& outputShape,
|
| 63 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 64 |
+
const std::optional<ScalarType>& outputType,
|
| 65 |
+
at::Device device);
|
| 66 |
+
Tensor computeReshape(
|
| 67 |
+
const std::vector<ArgValue>& inputs,
|
| 68 |
+
const std::vector<ExprHandle>& outputShape,
|
| 69 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 70 |
+
const std::optional<ScalarType>& outputType,
|
| 71 |
+
at::Device device);
|
| 72 |
+
Tensor computeFlatten(
|
| 73 |
+
const std::vector<ArgValue>& inputs,
|
| 74 |
+
const std::vector<ExprHandle>& outputShape,
|
| 75 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 76 |
+
const std::optional<ScalarType>& outputType,
|
| 77 |
+
at::Device device);
|
| 78 |
+
Tensor computeCatWoConditionals(
|
| 79 |
+
const std::vector<ArgValue>& inputs,
|
| 80 |
+
const std::vector<ExprHandle>& outputShape);
|
| 81 |
+
Tensor computeCat(
|
| 82 |
+
const std::vector<ArgValue>& inputs,
|
| 83 |
+
const std::vector<ExprHandle>& outputShape,
|
| 84 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 85 |
+
const std::optional<ScalarType>& outputType,
|
| 86 |
+
at::Device device);
|
| 87 |
+
Tensor computeEmbedding(
|
| 88 |
+
const std::vector<ArgValue>& inputs,
|
| 89 |
+
const std::vector<ExprHandle>& outputShape,
|
| 90 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 91 |
+
const std::optional<ScalarType>& outputType,
|
| 92 |
+
at::Device device);
|
| 93 |
+
|
| 94 |
+
} // namespace torch::jit::tensorexpr
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/norm.h
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/tensorexpr/kernel.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit::tensorexpr {
|
| 6 |
+
|
| 7 |
+
Tensor computeBatchNorm(
|
| 8 |
+
const std::vector<ArgValue>& inputs,
|
| 9 |
+
const std::vector<ExprHandle>& outputShape,
|
| 10 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 11 |
+
const std::optional<ScalarType>& outputType,
|
| 12 |
+
at::Device device);
|
| 13 |
+
|
| 14 |
+
} // namespace torch::jit::tensorexpr
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/operators.h
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/tensorexpr/operators/conv2d.h>
|
| 4 |
+
#include <torch/csrc/jit/tensorexpr/operators/matmul.h>
|
| 5 |
+
#include <torch/csrc/jit/tensorexpr/operators/misc.h>
|
| 6 |
+
#include <torch/csrc/jit/tensorexpr/operators/norm.h>
|
| 7 |
+
#include <torch/csrc/jit/tensorexpr/operators/pointwise.h>
|
| 8 |
+
#include <torch/csrc/jit/tensorexpr/operators/quantization.h>
|
| 9 |
+
#include <torch/csrc/jit/tensorexpr/operators/reduction.h>
|
| 10 |
+
#include <torch/csrc/jit/tensorexpr/operators/softmax.h>
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/pointwise.h
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/tensorexpr/kernel.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit::tensorexpr {
|
| 6 |
+
|
| 7 |
+
TORCH_API Tensor computeSign(
|
| 8 |
+
const std::vector<ArgValue>& inputs,
|
| 9 |
+
const std::vector<ExprHandle>& outputShape,
|
| 10 |
+
const std::optional<std::vector<ExprHandle>>& outputStrides = std::nullopt);
|
| 11 |
+
|
| 12 |
+
Tensor computeOneOperand(
|
| 13 |
+
const std::string& name,
|
| 14 |
+
const std::vector<ArgValue>& inputValues,
|
| 15 |
+
const std::vector<ExprHandle>& outputShape,
|
| 16 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 17 |
+
const std::optional<ScalarType>& outputType,
|
| 18 |
+
const std::function<ExprHandle(const ExprHandle&)>& innerExpr,
|
| 19 |
+
const int checkParamTypes = kAllTypes);
|
| 20 |
+
Tensor computeTwoOperand(
|
| 21 |
+
const std::string& name,
|
| 22 |
+
const std::vector<ArgValue>& inputValues,
|
| 23 |
+
const std::vector<ExprHandle>& outputShape,
|
| 24 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 25 |
+
const std::optional<ScalarType>& outputType,
|
| 26 |
+
const std::function<ExprHandle(const ExprHandle&, const ExprHandle&)>&
|
| 27 |
+
innerExpr);
|
| 28 |
+
Tensor computeTwoOperandWithAlpha(
|
| 29 |
+
const std::string& name,
|
| 30 |
+
const std::vector<ArgValue>& inputValues,
|
| 31 |
+
const std::vector<ExprHandle>& outputShape,
|
| 32 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 33 |
+
const std::optional<ScalarType>& outputType,
|
| 34 |
+
const std::function<ExprHandle(const ExprHandle&, const ExprHandle&)>&
|
| 35 |
+
innerExpr);
|
| 36 |
+
Tensor computeConditionWithTwoOperand(
|
| 37 |
+
const std::string& name,
|
| 38 |
+
const std::vector<ArgValue>& inputValues,
|
| 39 |
+
const std::vector<ExprHandle>& outputShape,
|
| 40 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 41 |
+
const std::optional<ScalarType>& outputType,
|
| 42 |
+
const std::function<
|
| 43 |
+
ExprHandle(const ExprHandle&, const ExprHandle&, const ExprHandle&)>&
|
| 44 |
+
innerExpr);
|
| 45 |
+
Tensor computeThreeOperand(
|
| 46 |
+
const std::string& name,
|
| 47 |
+
const std::vector<ArgValue>& inputValues,
|
| 48 |
+
const std::vector<ExprHandle>& outputShape,
|
| 49 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 50 |
+
const std::optional<ScalarType>& outputType,
|
| 51 |
+
const std::function<
|
| 52 |
+
ExprHandle(const ExprHandle&, const ExprHandle&, const ExprHandle&)>&
|
| 53 |
+
innerExpr,
|
| 54 |
+
bool promote_inputs = true);
|
| 55 |
+
Tensor computeFourOperand(
|
| 56 |
+
const std::string& name,
|
| 57 |
+
const std::vector<ArgValue>& inputValues,
|
| 58 |
+
const std::vector<ExprHandle>& outputShape,
|
| 59 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 60 |
+
const std::optional<ScalarType>& outputType,
|
| 61 |
+
const std::function<ExprHandle(
|
| 62 |
+
const ExprHandle&,
|
| 63 |
+
const ExprHandle&,
|
| 64 |
+
const ExprHandle&,
|
| 65 |
+
const ExprHandle&)>& innerExpr);
|
| 66 |
+
Tensor computeNoop(
|
| 67 |
+
const std::vector<ArgValue>& inputs,
|
| 68 |
+
const std::vector<ExprHandle>& outputShape,
|
| 69 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 70 |
+
const std::optional<ScalarType>& outputType,
|
| 71 |
+
at::Device device);
|
| 72 |
+
|
| 73 |
+
Tensor computeScalar(
|
| 74 |
+
const std::string& name,
|
| 75 |
+
const std::vector<ArgValue>& inputValues,
|
| 76 |
+
const std::vector<ExprHandle>& outputShape,
|
| 77 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 78 |
+
const std::optional<ScalarType>& outputType,
|
| 79 |
+
const std::function<ExprHandle(const ExprHandle&, const ExprHandle&)>&
|
| 80 |
+
innerExpr);
|
| 81 |
+
|
| 82 |
+
} // namespace torch::jit::tensorexpr
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/quantization.h
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/tensorexpr/kernel.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit::tensorexpr {
|
| 6 |
+
|
| 7 |
+
TORCH_API ExprHandle quantizePerTensorQParamFromArg(ArgValue arg);
|
| 8 |
+
|
| 9 |
+
TORCH_API double immQScale(const BufHandle& qx);
|
| 10 |
+
|
| 11 |
+
TORCH_API int64_t immQZero(const BufHandle& qx);
|
| 12 |
+
|
| 13 |
+
TORCH_API ScalarType immQDType(const BufHandle& qx);
|
| 14 |
+
|
| 15 |
+
TORCH_API bool isQuantized(const BufHandle& qx);
|
| 16 |
+
|
| 17 |
+
TORCH_API Tensor computeQuantizePerTensor(
|
| 18 |
+
const std::vector<ArgValue>& inputs,
|
| 19 |
+
const std::vector<ExprHandle>& outputShape,
|
| 20 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 21 |
+
const std::optional<ScalarType>& outputType,
|
| 22 |
+
at::Device device);
|
| 23 |
+
|
| 24 |
+
TORCH_API Tensor computeQuantizePerTensorExternalCall(
|
| 25 |
+
const std::vector<ArgValue>& inputs,
|
| 26 |
+
const std::vector<ExprHandle>& outputShape,
|
| 27 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 28 |
+
const std::optional<ScalarType>& outputType,
|
| 29 |
+
at::Device device);
|
| 30 |
+
|
| 31 |
+
TORCH_API Tensor computeQuantizedConv1d(
|
| 32 |
+
const std::vector<ArgValue>& inputs,
|
| 33 |
+
const std::vector<ExprHandle>& outputShape,
|
| 34 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 35 |
+
const std::optional<ScalarType>& outputType,
|
| 36 |
+
at::Device device);
|
| 37 |
+
|
| 38 |
+
TORCH_API Tensor computeQuantizedConv2dPrepack(
|
| 39 |
+
const std::vector<ArgValue>& inputs,
|
| 40 |
+
const std::vector<ExprHandle>& outputShape,
|
| 41 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 42 |
+
const std::optional<ScalarType>& outputType,
|
| 43 |
+
at::Device device);
|
| 44 |
+
|
| 45 |
+
TORCH_API Tensor computeQuantizedConv1d(
|
| 46 |
+
const std::vector<ArgValue>& inputs,
|
| 47 |
+
const std::vector<ExprHandle>& outputShape,
|
| 48 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 49 |
+
const std::optional<ScalarType>& outputType,
|
| 50 |
+
at::Device device);
|
| 51 |
+
|
| 52 |
+
TORCH_API Tensor computeQuantizedConv2d(
|
| 53 |
+
const std::vector<ArgValue>& inputs,
|
| 54 |
+
const std::vector<ExprHandle>& outputShape,
|
| 55 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 56 |
+
const std::optional<ScalarType>& outputType,
|
| 57 |
+
at::Device device);
|
| 58 |
+
|
| 59 |
+
TORCH_API Tensor computeQuantizedConv2dRelu(
|
| 60 |
+
const std::vector<ArgValue>& inputs,
|
| 61 |
+
const std::vector<ExprHandle>& outputShape,
|
| 62 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 63 |
+
const std::optional<ScalarType>& outputType,
|
| 64 |
+
at::Device device);
|
| 65 |
+
|
| 66 |
+
TORCH_API Tensor computeQuantizedLinear(
|
| 67 |
+
const std::vector<ArgValue>& inputs,
|
| 68 |
+
const std::vector<ExprHandle>& outputShape,
|
| 69 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 70 |
+
const std::optional<ScalarType>& outputType,
|
| 71 |
+
at::Device device);
|
| 72 |
+
|
| 73 |
+
TORCH_API Tensor computeQuantizedLinearRelu(
|
| 74 |
+
const std::vector<ArgValue>& inputs,
|
| 75 |
+
const std::vector<ExprHandle>& outputShape,
|
| 76 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 77 |
+
const std::optional<ScalarType>& outputType,
|
| 78 |
+
at::Device device);
|
| 79 |
+
|
| 80 |
+
TORCH_API Tensor computeQuantizedAdd(
|
| 81 |
+
const std::vector<ArgValue>& inputs,
|
| 82 |
+
const std::vector<ExprHandle>& outputShape,
|
| 83 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 84 |
+
const std::optional<ScalarType>& outputType,
|
| 85 |
+
at::Device device);
|
| 86 |
+
|
| 87 |
+
Tensor computeQuantizedAddExternalCall(
|
| 88 |
+
const std::vector<ArgValue>& inputs,
|
| 89 |
+
const std::vector<ExprHandle>& outputShape,
|
| 90 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 91 |
+
const std::optional<ScalarType>& outputType,
|
| 92 |
+
at::Device device);
|
| 93 |
+
|
| 94 |
+
TORCH_API Tensor computeQuantizedMul(
|
| 95 |
+
const std::vector<ArgValue>& inputs,
|
| 96 |
+
const std::vector<ExprHandle>& outputShape,
|
| 97 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 98 |
+
const std::optional<ScalarType>& outputType,
|
| 99 |
+
at::Device device);
|
| 100 |
+
|
| 101 |
+
TORCH_API Tensor computeQuantizedMulScalar(
|
| 102 |
+
const std::vector<ArgValue>& inputs,
|
| 103 |
+
const std::vector<ExprHandle>& outputShape,
|
| 104 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 105 |
+
const std::optional<ScalarType>& outputType,
|
| 106 |
+
at::Device device);
|
| 107 |
+
|
| 108 |
+
TORCH_API Tensor computeQuantizedCat(
|
| 109 |
+
const std::vector<ArgValue>& inputs,
|
| 110 |
+
const std::vector<ExprHandle>& outputShape,
|
| 111 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 112 |
+
const std::optional<ScalarType>& outputType,
|
| 113 |
+
at::Device device);
|
| 114 |
+
|
| 115 |
+
TORCH_API Tensor computeQuantizedRelu(
|
| 116 |
+
const std::vector<ArgValue>& inputs,
|
| 117 |
+
const std::vector<ExprHandle>& outputShape,
|
| 118 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 119 |
+
const std::optional<ScalarType>& outputType,
|
| 120 |
+
at::Device device);
|
| 121 |
+
|
| 122 |
+
TORCH_API Tensor computeDequantize(
|
| 123 |
+
const std::vector<ArgValue>& inputs,
|
| 124 |
+
const std::vector<ExprHandle>& outputShape,
|
| 125 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 126 |
+
const std::optional<ScalarType>& outputType,
|
| 127 |
+
at::Device device);
|
| 128 |
+
|
| 129 |
+
TORCH_API Tensor computeDequantizeExternalCall(
|
| 130 |
+
const std::vector<ArgValue>& inputs,
|
| 131 |
+
const std::vector<ExprHandle>& outputShape,
|
| 132 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 133 |
+
const std::optional<ScalarType>& outputType,
|
| 134 |
+
at::Device device);
|
| 135 |
+
|
| 136 |
+
TORCH_API Tensor computeUpsampleNearest2d(
|
| 137 |
+
const std::vector<ArgValue>& inputs,
|
| 138 |
+
const std::vector<ExprHandle>& outputShape,
|
| 139 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 140 |
+
const std::optional<ScalarType>& outputType,
|
| 141 |
+
at::Device device);
|
| 142 |
+
|
| 143 |
+
TORCH_API Tensor computeUpsampleNearest2dExternalCall(
|
| 144 |
+
const std::vector<ArgValue>& inputs,
|
| 145 |
+
const std::vector<ExprHandle>& outputShape,
|
| 146 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 147 |
+
const std::optional<ScalarType>& outputType,
|
| 148 |
+
at::Device device);
|
| 149 |
+
|
| 150 |
+
TORCH_API Tensor computeQuantizedSigmoidExternalCall(
|
| 151 |
+
const std::vector<ArgValue>& inputs,
|
| 152 |
+
const std::vector<ExprHandle>& outputShape,
|
| 153 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 154 |
+
const std::optional<ScalarType>& outputType,
|
| 155 |
+
at::Device);
|
| 156 |
+
} // namespace torch::jit::tensorexpr
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/reduction.h
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/tensorexpr/kernel.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit::tensorexpr {
|
| 6 |
+
|
| 7 |
+
TORCH_API Tensor computeSum(
|
| 8 |
+
const std::vector<ArgValue>& inputs,
|
| 9 |
+
const std::vector<ExprHandle>& outputShape,
|
| 10 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 11 |
+
const std::optional<ScalarType>& outputType,
|
| 12 |
+
at::Device device);
|
| 13 |
+
TORCH_API Tensor computeMean(
|
| 14 |
+
const std::vector<ArgValue>& inputs,
|
| 15 |
+
const std::vector<ExprHandle>& outputShape,
|
| 16 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 17 |
+
const std::optional<ScalarType>& outputType,
|
| 18 |
+
at::Device device);
|
| 19 |
+
TORCH_API Tensor computeAdaptiveAvgPool2d(
|
| 20 |
+
const std::vector<ArgValue>& inputs,
|
| 21 |
+
const std::vector<ExprHandle>& outputShape,
|
| 22 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 23 |
+
const std::optional<ScalarType>& outputType,
|
| 24 |
+
at::Device device);
|
| 25 |
+
Tensor computeMax(
|
| 26 |
+
const std::vector<ArgValue>& inputs,
|
| 27 |
+
const std::vector<ExprHandle>& outputShape,
|
| 28 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 29 |
+
const std::optional<ScalarType>& outputType,
|
| 30 |
+
at::Device device);
|
| 31 |
+
|
| 32 |
+
} // namespace torch::jit::tensorexpr
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/operators/softmax.h
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/jit/tensorexpr/kernel.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::jit::tensorexpr {
|
| 6 |
+
|
| 7 |
+
Tensor computeSoftmax(
|
| 8 |
+
const std::vector<ArgValue>& inputs,
|
| 9 |
+
const std::vector<ExprHandle>& outputShape,
|
| 10 |
+
const std::vector<ExprHandle>& outputStrides,
|
| 11 |
+
bool log_softmax);
|
| 12 |
+
|
| 13 |
+
} // namespace torch::jit::tensorexpr
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/types.h
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <cstdint>
|
| 4 |
+
#include <iosfwd>
|
| 5 |
+
|
| 6 |
+
#include <c10/core/ScalarType.h>
|
| 7 |
+
#include <c10/util/Logging.h>
|
| 8 |
+
#include <torch/csrc/Export.h>
|
| 9 |
+
|
| 10 |
+
#include <torch/csrc/jit/tensorexpr/exceptions.h>
|
| 11 |
+
|
| 12 |
+
namespace torch::jit::tensorexpr {
|
| 13 |
+
|
| 14 |
+
using int32 = std::int32_t;
|
| 15 |
+
|
| 16 |
+
class Dtype;
|
| 17 |
+
TORCH_API std::ostream& operator<<(std::ostream& stream, const Dtype& dtype);
|
| 18 |
+
|
| 19 |
+
using ScalarType = c10::ScalarType;
|
| 20 |
+
|
| 21 |
+
enum ElementType {
|
| 22 |
+
kAllTypes = 0,
|
| 23 |
+
kIntegralTypes = 1 << 0,
|
| 24 |
+
kFloatingPointTypes = 1 << 1,
|
| 25 |
+
kBoolType = 1 << 2,
|
| 26 |
+
kComplexTypes = 1 << 3,
|
| 27 |
+
kQintTypes = 1 << 4,
|
| 28 |
+
kNonComplexOrQintTypes = kIntegralTypes | kBoolType | kFloatingPointTypes,
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
// Data types for scalar and vector elements.
|
| 32 |
+
class TORCH_API Dtype {
|
| 33 |
+
public:
|
| 34 |
+
explicit Dtype(int8_t type)
|
| 35 |
+
: scalar_type_(static_cast<ScalarType>(type)), lanes_(1) {}
|
| 36 |
+
explicit Dtype(ScalarType type) : scalar_type_(type), lanes_(1) {}
|
| 37 |
+
Dtype(int8_t type, int64_t lanes)
|
| 38 |
+
: scalar_type_(static_cast<ScalarType>(type)), lanes_(lanes) {}
|
| 39 |
+
Dtype(ScalarType type, int64_t lanes) : scalar_type_(type), lanes_(lanes) {}
|
| 40 |
+
Dtype(Dtype type, int64_t lanes)
|
| 41 |
+
: scalar_type_(type.scalar_type_), lanes_(lanes) {
|
| 42 |
+
if (type.lanes() != 1) {
|
| 43 |
+
throw malformed_input("dtype lanes dont match");
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
int64_t lanes() const {
|
| 47 |
+
return lanes_;
|
| 48 |
+
}
|
| 49 |
+
ScalarType scalar_type() const {
|
| 50 |
+
return scalar_type_;
|
| 51 |
+
}
|
| 52 |
+
Dtype scalar_dtype() const;
|
| 53 |
+
bool operator==(const Dtype& other) const {
|
| 54 |
+
return scalar_type_ == other.scalar_type_ && lanes_ == other.lanes_;
|
| 55 |
+
}
|
| 56 |
+
bool operator!=(const Dtype& other) const {
|
| 57 |
+
return !(*this == other);
|
| 58 |
+
}
|
| 59 |
+
int byte_size() const;
|
| 60 |
+
std::string ToCppString() const;
|
| 61 |
+
|
| 62 |
+
bool is_integral() const {
|
| 63 |
+
return c10::isIntegralType(scalar_type_, true);
|
| 64 |
+
}
|
| 65 |
+
bool is_floating_point() const {
|
| 66 |
+
return c10::isFloatingType(scalar_type_);
|
| 67 |
+
}
|
| 68 |
+
bool is_signed() const {
|
| 69 |
+
return c10::isSignedType(scalar_type_);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
Dtype cloneWithScalarType(ScalarType nt) const {
|
| 73 |
+
return Dtype(nt, lanes_);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
private:
|
| 77 |
+
friend TORCH_API std::ostream& operator<<(
|
| 78 |
+
std::ostream& stream,
|
| 79 |
+
const Dtype& dtype);
|
| 80 |
+
ScalarType scalar_type_;
|
| 81 |
+
int64_t lanes_; // the width of the element for a vector time
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
extern TORCH_API Dtype kHandle;
|
| 85 |
+
|
| 86 |
+
#define NNC_DTYPE_DECLARATION(ctype, name) extern TORCH_API Dtype k##name;
|
| 87 |
+
|
| 88 |
+
AT_FORALL_SCALAR_TYPES_AND3(Bool, Half, BFloat16, NNC_DTYPE_DECLARATION)
|
| 89 |
+
NNC_DTYPE_DECLARATION(c10::quint8, QUInt8)
|
| 90 |
+
NNC_DTYPE_DECLARATION(c10::qint8, QInt8)
|
| 91 |
+
#undef NNC_DTYPE_DECLARATION
|
| 92 |
+
|
| 93 |
+
template <typename T>
|
| 94 |
+
TORCH_API Dtype ToDtype();
|
| 95 |
+
|
| 96 |
+
#define NNC_TODTYPE_DECLARATION(ctype, name) \
|
| 97 |
+
template <> \
|
| 98 |
+
inline Dtype ToDtype<ctype>() { \
|
| 99 |
+
return k##name; \
|
| 100 |
+
}
|
| 101 |
+
AT_FORALL_SCALAR_TYPES_AND3(Bool, Half, BFloat16, NNC_TODTYPE_DECLARATION)
|
| 102 |
+
NNC_TODTYPE_DECLARATION(c10::quint8, QUInt8)
|
| 103 |
+
NNC_TODTYPE_DECLARATION(c10::qint8, QInt8)
|
| 104 |
+
#undef NNC_TODTYPE_DECLARATION
|
| 105 |
+
|
| 106 |
+
TORCH_API Dtype ToDtype(ScalarType type);
|
| 107 |
+
|
| 108 |
+
inline Dtype promoteTypes(Dtype a, Dtype b) {
|
| 109 |
+
if (a.lanes() != b.lanes()) {
|
| 110 |
+
throw malformed_input("promoting types with different lanes");
|
| 111 |
+
}
|
| 112 |
+
return Dtype(
|
| 113 |
+
static_cast<ScalarType>(c10::promoteTypes(
|
| 114 |
+
static_cast<c10::ScalarType>(a.scalar_type()),
|
| 115 |
+
static_cast<c10::ScalarType>(b.scalar_type()))),
|
| 116 |
+
a.lanes());
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
inline Dtype BinaryOpDtype(
|
| 120 |
+
Dtype op1_dtype,
|
| 121 |
+
Dtype op2_dtype,
|
| 122 |
+
ScalarType ret_type = ScalarType::Undefined) {
|
| 123 |
+
if (op1_dtype == op2_dtype) {
|
| 124 |
+
if (ret_type == ScalarType::Undefined) {
|
| 125 |
+
return op1_dtype;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
return ToDtype(ret_type);
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
if (op1_dtype.lanes() != op2_dtype.lanes()) {
|
| 132 |
+
throw malformed_input("lanes dont match");
|
| 133 |
+
}
|
| 134 |
+
int64_t lanes = op1_dtype.lanes();
|
| 135 |
+
|
| 136 |
+
Dtype resultType = promoteTypes(op1_dtype, op2_dtype);
|
| 137 |
+
if (resultType.scalar_type() == ScalarType::Undefined) {
|
| 138 |
+
throw malformed_input("scalar type doesn't match");
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
if (lanes == 1) {
|
| 142 |
+
// Use the fixed scalar Dtypes.
|
| 143 |
+
return ToDtype(resultType.scalar_type());
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
return resultType;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
} // namespace torch::jit::tensorexpr
|
| 150 |
+
|
| 151 |
+
namespace std {
|
| 152 |
+
|
| 153 |
+
using torch::jit::tensorexpr::Dtype;
|
| 154 |
+
std::string to_string(const Dtype& dtype);
|
| 155 |
+
using torch::jit::tensorexpr::ScalarType;
|
| 156 |
+
std::string to_string(const ScalarType& dtype);
|
| 157 |
+
|
| 158 |
+
} // namespace std
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/unique_name_manager.h
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <string>
|
| 4 |
+
#include <unordered_map>
|
| 5 |
+
#include <unordered_set>
|
| 6 |
+
|
| 7 |
+
#include <torch/csrc/Export.h>
|
| 8 |
+
#include <torch/csrc/jit/tensorexpr/fwd_decls.h>
|
| 9 |
+
|
| 10 |
+
namespace torch::jit::tensorexpr {
|
| 11 |
+
|
| 12 |
+
class VarHandle;
|
| 13 |
+
class Var;
|
| 14 |
+
|
| 15 |
+
using VarNameMap = std::unordered_map<VarPtr, std::string>;
|
| 16 |
+
|
| 17 |
+
// A manager to get unique names from vars.
|
| 18 |
+
// It starts with the name hints of the var and append "_" + $counter until it
|
| 19 |
+
// hits a unique name.
|
| 20 |
+
class TORCH_API UniqueNameManager {
|
| 21 |
+
public:
|
| 22 |
+
const std::string& get_unique_name(const VarHandle& v);
|
| 23 |
+
|
| 24 |
+
const std::string& get_unique_name(const VarPtr& v);
|
| 25 |
+
|
| 26 |
+
private:
|
| 27 |
+
friend class ScopedVarName;
|
| 28 |
+
VarNameMap unique_name_mapping_;
|
| 29 |
+
std::unordered_map<std::string, int> unique_name_count_;
|
| 30 |
+
std::unordered_set<std::string> all_unique_names_;
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
} // namespace torch::jit::tensorexpr
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/tensorexpr/var_substitutor.h
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <unordered_map>
|
| 4 |
+
#include <utility>
|
| 5 |
+
#include <vector>
|
| 6 |
+
|
| 7 |
+
#include <torch/csrc/jit/tensorexpr/analysis.h>
|
| 8 |
+
#include <torch/csrc/jit/tensorexpr/ir.h>
|
| 9 |
+
#include <torch/csrc/jit/tensorexpr/ir_mutator.h>
|
| 10 |
+
#include <torch/csrc/jit/tensorexpr/ir_visitor.h>
|
| 11 |
+
#include <torch/csrc/jit/tensorexpr/reduction.h>
|
| 12 |
+
|
| 13 |
+
namespace torch::jit::tensorexpr {
|
| 14 |
+
|
| 15 |
+
using VarMapping = std::vector<std::pair<VarPtr, ExprPtr>>;
|
| 16 |
+
|
| 17 |
+
class VarSubMutator : public IRMutator {
|
| 18 |
+
public:
|
| 19 |
+
VarSubMutator(const VarMapping& var_mapping) {
|
| 20 |
+
for (auto& entry : var_mapping) {
|
| 21 |
+
VarPtr key_var = entry.first;
|
| 22 |
+
ExprPtr value = entry.second;
|
| 23 |
+
if (!key_var) {
|
| 24 |
+
throw malformed_input("missing key in VarSubMutator");
|
| 25 |
+
}
|
| 26 |
+
var_mapping_[std::move(key_var)] = std::move(value);
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
ExprPtr mutate(const VarPtr& var) override {
|
| 31 |
+
auto iter = var_mapping_.find(var);
|
| 32 |
+
if (iter == var_mapping_.end()) {
|
| 33 |
+
return var;
|
| 34 |
+
}
|
| 35 |
+
return iter->second;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
ExprPtr mutate(const ReduceOpPtr& var) override {
|
| 39 |
+
auto body = var->body()->accept_mutator(this);
|
| 40 |
+
std::vector<VarPtr> new_inner;
|
| 41 |
+
|
| 42 |
+
for (const auto& v : var->reduce_args()) {
|
| 43 |
+
ExprPtr e = v->accept_mutator(this);
|
| 44 |
+
if (VarPtr new_var = to<Var>(e)) {
|
| 45 |
+
new_inner.push_back(std::move(new_var));
|
| 46 |
+
} else {
|
| 47 |
+
VarFinder varFinder;
|
| 48 |
+
e->accept(&varFinder);
|
| 49 |
+
auto varlist = varFinder.vars();
|
| 50 |
+
new_inner.insert(new_inner.end(), varlist.begin(), varlist.end());
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
return alloc<ReduceOp>(body, new_inner, var->reducer());
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
private:
|
| 58 |
+
std::unordered_map<VarPtr, ExprPtr> var_mapping_;
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
} // namespace torch::jit::tensorexpr
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/testing/catch_utils.hpp
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#define CATCH_CONFIG_PREFIX_ALL
|
| 4 |
+
#include <catch.hpp>
|
| 5 |
+
|
| 6 |
+
// CATCH_REQUIRE_THROWS is not defined identically to REQUIRE_THROWS and causes
|
| 7 |
+
// warning; define our own version that doesn't warn.
|
| 8 |
+
#define _CATCH_REQUIRE_THROWS(...) \
|
| 9 |
+
INTERNAL_CATCH_THROWS( \
|
| 10 |
+
"CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__)
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/testing/file_check.h
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/Export.h>
|
| 4 |
+
#include <memory>
|
| 5 |
+
#include <string>
|
| 6 |
+
|
| 7 |
+
namespace torch::jit {
|
| 8 |
+
|
| 9 |
+
struct Graph;
|
| 10 |
+
|
| 11 |
+
namespace testing {
|
| 12 |
+
|
| 13 |
+
struct FileCheckImpl;
|
| 14 |
+
|
| 15 |
+
struct FileCheck {
|
| 16 |
+
public:
|
| 17 |
+
TORCH_API explicit FileCheck();
|
| 18 |
+
TORCH_API ~FileCheck();
|
| 19 |
+
|
| 20 |
+
// Run FileCheck against test string
|
| 21 |
+
TORCH_API void run(const std::string& test_string);
|
| 22 |
+
|
| 23 |
+
// Run FileCheck against dump of graph IR
|
| 24 |
+
TORCH_API void run(const Graph& graph);
|
| 25 |
+
|
| 26 |
+
// Parsing input checks string and run against test string / dump of graph IR
|
| 27 |
+
TORCH_API void run(
|
| 28 |
+
const std::string& input_checks_string,
|
| 29 |
+
const std::string& test_string);
|
| 30 |
+
TORCH_API void run(
|
| 31 |
+
const std::string& input_checks_string,
|
| 32 |
+
const Graph& graph);
|
| 33 |
+
|
| 34 |
+
// Checks that the string occurs, starting at the end of the most recent match
|
| 35 |
+
TORCH_API FileCheck* check(const std::string& str);
|
| 36 |
+
|
| 37 |
+
// Checks that the string does not occur between the previous match and next
|
| 38 |
+
// match. Consecutive check_nots test against the same previous match and next
|
| 39 |
+
// match
|
| 40 |
+
TORCH_API FileCheck* check_not(const std::string& str);
|
| 41 |
+
|
| 42 |
+
// Checks that the string occurs on the same line as the previous match
|
| 43 |
+
TORCH_API FileCheck* check_same(const std::string& str);
|
| 44 |
+
|
| 45 |
+
// Checks that the string occurs on the line immediately following the
|
| 46 |
+
// previous match
|
| 47 |
+
TORCH_API FileCheck* check_next(const std::string& str);
|
| 48 |
+
|
| 49 |
+
// Checks that the string occurs count number of times, starting at the end
|
| 50 |
+
// of the previous match. If exactly is true, checks that there are exactly
|
| 51 |
+
// count many matches
|
| 52 |
+
TORCH_API FileCheck* check_count(
|
| 53 |
+
const std::string& str,
|
| 54 |
+
size_t count,
|
| 55 |
+
bool exactly = false);
|
| 56 |
+
|
| 57 |
+
// A series of consecutive check_dags get turned into a group of checks
|
| 58 |
+
// which can appear in any order relative to each other. The checks begin
|
| 59 |
+
// at the end of the previous match, and the match for the check_dag group
|
| 60 |
+
// is the minimum match of all individual checks to the maximum match of all
|
| 61 |
+
// individual checks.
|
| 62 |
+
TORCH_API FileCheck* check_dag(const std::string& str);
|
| 63 |
+
|
| 64 |
+
// Checks that source token is highlighted in str (usually an error message).
|
| 65 |
+
TORCH_API FileCheck* check_source_highlighted(const std::string& str);
|
| 66 |
+
|
| 67 |
+
// Checks that the regex matched string occurs, starting at the end of the
|
| 68 |
+
// most recent match
|
| 69 |
+
TORCH_API FileCheck* check_regex(const std::string& str);
|
| 70 |
+
|
| 71 |
+
// reset checks
|
| 72 |
+
TORCH_API void reset();
|
| 73 |
+
|
| 74 |
+
private:
|
| 75 |
+
bool has_run = false;
|
| 76 |
+
std::unique_ptr<FileCheckImpl> fcImpl;
|
| 77 |
+
};
|
| 78 |
+
} // namespace testing
|
| 79 |
+
} // namespace torch::jit
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/jit/testing/hooks_for_testing.h
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
#include <torch/csrc/Export.h>
|
| 3 |
+
#include <torch/csrc/jit/api/compilation_unit.h>
|
| 4 |
+
#include <functional>
|
| 5 |
+
#include <memory>
|
| 6 |
+
|
| 7 |
+
namespace torch::jit {
|
| 8 |
+
struct Module;
|
| 9 |
+
|
| 10 |
+
using ModuleHook = std::function<void(Module module)>;
|
| 11 |
+
using FunctionHook = std::function<void(StrongFunctionPtr function)>;
|
| 12 |
+
|
| 13 |
+
TORCH_API void didFinishEmitModule(Module module);
|
| 14 |
+
TORCH_API void didFinishEmitFunction(StrongFunctionPtr defined);
|
| 15 |
+
TORCH_API void setEmitHooks(ModuleHook for_module, FunctionHook for_fn);
|
| 16 |
+
|
| 17 |
+
TORCH_API std::pair<ModuleHook, FunctionHook> getEmitHooks();
|
| 18 |
+
|
| 19 |
+
} // namespace torch::jit
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/backend/backend_data.h
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/lazy/backend/backend_device.h>
|
| 4 |
+
#include <torch/csrc/lazy/core/shape.h>
|
| 5 |
+
#include <cstring>
|
| 6 |
+
|
| 7 |
+
namespace torch::lazy {
|
| 8 |
+
|
| 9 |
+
class TORCH_API BackendData {
|
| 10 |
+
public:
|
| 11 |
+
struct Info {
|
| 12 |
+
/**
|
| 13 |
+
* Used by Lazy Graph Executor to tag info on BackendData objs
|
| 14 |
+
* */
|
| 15 |
+
virtual ~Info() = default;
|
| 16 |
+
};
|
| 17 |
+
/**
|
| 18 |
+
* Represents (Tensor) data stored on a backend device
|
| 19 |
+
* in its native format.
|
| 20 |
+
* */
|
| 21 |
+
using Handle = int64_t;
|
| 22 |
+
|
| 23 |
+
BackendData(BackendDevice device, Shape shape)
|
| 24 |
+
: device_(std::move(device)), shape_(std::move(shape)) {}
|
| 25 |
+
|
| 26 |
+
virtual ~BackendData() = default;
|
| 27 |
+
|
| 28 |
+
const BackendDevice& device() const {
|
| 29 |
+
return device_;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
const Shape& shape() const {
|
| 33 |
+
return shape_;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
Info* info() const {
|
| 37 |
+
return info_.get();
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
std::shared_ptr<Info> SetInfo(std::shared_ptr<Info> info) {
|
| 41 |
+
std::swap(info, info_);
|
| 42 |
+
return info;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
virtual Handle GetHandle() = 0;
|
| 46 |
+
|
| 47 |
+
virtual void Assign(const BackendData& data) = 0;
|
| 48 |
+
|
| 49 |
+
virtual bool HasValue() const = 0;
|
| 50 |
+
|
| 51 |
+
private:
|
| 52 |
+
BackendDevice device_;
|
| 53 |
+
Shape shape_;
|
| 54 |
+
std::shared_ptr<Info> info_;
|
| 55 |
+
};
|
| 56 |
+
|
| 57 |
+
using BackendDataPtr = std::shared_ptr<BackendData>;
|
| 58 |
+
|
| 59 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/backend/backend_device.h
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <memory>
|
| 4 |
+
#include <ostream>
|
| 5 |
+
#include <string>
|
| 6 |
+
|
| 7 |
+
#include <ATen/Tensor.h>
|
| 8 |
+
#include <c10/macros/Export.h>
|
| 9 |
+
#include <c10/util/Deprecated.h>
|
| 10 |
+
#include <optional>
|
| 11 |
+
|
| 12 |
+
namespace c10 {
|
| 13 |
+
struct Device;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
namespace torch::lazy {
|
| 17 |
+
|
| 18 |
+
// Backend should extend it and define their own supported hardware types.
|
| 19 |
+
struct TORCH_API BackendDeviceType {
|
| 20 |
+
int8_t type{(int8_t)at::kCPU};
|
| 21 |
+
// Note: previous default value was '0', which actually maps to at::kCPU, at
|
| 22 |
+
// least now it is explicit, we may want to make default/undefined semantics
|
| 23 |
+
// more clear though
|
| 24 |
+
BackendDeviceType() : type((int8_t)at::kCPU) {}
|
| 25 |
+
BackendDeviceType(int8_t type) : type(type) {}
|
| 26 |
+
|
| 27 |
+
virtual ~BackendDeviceType() = default;
|
| 28 |
+
virtual std::string toString() const {
|
| 29 |
+
return "Unknown";
|
| 30 |
+
}
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
class TORCH_API BackendDevice {
|
| 34 |
+
public:
|
| 35 |
+
// The default constructor will set both the device type and ordinal
|
| 36 |
+
// to backend specific defaults.
|
| 37 |
+
BackendDevice();
|
| 38 |
+
BackendDevice(std::shared_ptr<BackendDeviceType>&& type, int64_t ordinal);
|
| 39 |
+
|
| 40 |
+
int8_t type() const;
|
| 41 |
+
int64_t ordinal() const {
|
| 42 |
+
return ordinal_;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
bool operator==(const BackendDevice& other) const {
|
| 46 |
+
return compare(other) == 0;
|
| 47 |
+
}
|
| 48 |
+
bool operator!=(const BackendDevice& other) const {
|
| 49 |
+
return compare(other) != 0;
|
| 50 |
+
}
|
| 51 |
+
bool operator<(const BackendDevice& rhs) const {
|
| 52 |
+
return compare(rhs) < 0;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
std::string toString() const;
|
| 56 |
+
|
| 57 |
+
private:
|
| 58 |
+
int compare(const BackendDevice& rhs) const;
|
| 59 |
+
|
| 60 |
+
// Use shared_ptr instead of unique_ptr so that BackendDevice can be copied.
|
| 61 |
+
std::shared_ptr<BackendDeviceType> type_;
|
| 62 |
+
int64_t ordinal_;
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
TORCH_API std::ostream& operator<<(
|
| 66 |
+
std::ostream& os,
|
| 67 |
+
const BackendDevice& device);
|
| 68 |
+
|
| 69 |
+
// Helpers for converting a c10::Device to BackendDevice and vice versa.
|
| 70 |
+
TORCH_API BackendDevice atenDeviceToBackendDevice(const c10::Device& device);
|
| 71 |
+
TORCH_API c10::Device backendDeviceToAtenDevice(const BackendDevice& device);
|
| 72 |
+
|
| 73 |
+
// Tries to extract the backend device out of the lazy tensor. Returns nullopt
|
| 74 |
+
// if the input is not a lazy tensor.
|
| 75 |
+
TORCH_API std::optional<BackendDevice> GetBackendDevice(
|
| 76 |
+
const at::ITensorListRef tensors);
|
| 77 |
+
TORCH_API std::optional<BackendDevice> GetBackendDevice(
|
| 78 |
+
const at::TensorList tensors);
|
| 79 |
+
TORCH_API std::optional<BackendDevice> GetBackendDevice(
|
| 80 |
+
const at::Tensor& tensor);
|
| 81 |
+
TORCH_API std::optional<BackendDevice> GetBackendDevice(
|
| 82 |
+
const std::optional<c10::Device>& device);
|
| 83 |
+
|
| 84 |
+
// For variadic template.
|
| 85 |
+
TORCH_API std::optional<BackendDevice> GetBackendDevice();
|
| 86 |
+
|
| 87 |
+
C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Winfinite-recursion")
|
| 88 |
+
template <typename T, typename... Args>
|
| 89 |
+
std::optional<BackendDevice> GetBackendDevice(
|
| 90 |
+
const T& tensor,
|
| 91 |
+
const Args&... forward_tensors) {
|
| 92 |
+
auto optional_device = GetBackendDevice(tensor);
|
| 93 |
+
if (optional_device) {
|
| 94 |
+
return optional_device;
|
| 95 |
+
}
|
| 96 |
+
return GetBackendDevice(forward_tensors...);
|
| 97 |
+
}
|
| 98 |
+
C10_DIAGNOSTIC_POP()
|
| 99 |
+
|
| 100 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/backend/backend_interface.h
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/Tensor.h>
|
| 4 |
+
#include <torch/csrc/lazy/backend/backend_data.h>
|
| 5 |
+
#include <torch/csrc/lazy/backend/backend_device.h>
|
| 6 |
+
#include <torch/csrc/lazy/backend/lowering_context.h>
|
| 7 |
+
#include <torch/csrc/lazy/core/lazy_graph_executor.h>
|
| 8 |
+
#include <torch/csrc/lazy/core/shape.h>
|
| 9 |
+
#include <torch/csrc/lazy/core/tensor.h>
|
| 10 |
+
|
| 11 |
+
namespace torch::lazy {
|
| 12 |
+
|
| 13 |
+
struct IrBuilder;
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* Work in progress- don't treat this as a stable interface yet!
|
| 17 |
+
*/
|
| 18 |
+
class TORCH_API BackendImplInterface {
|
| 19 |
+
public:
|
| 20 |
+
virtual ~BackendImplInterface() = default;
|
| 21 |
+
|
| 22 |
+
/**
|
| 23 |
+
* Initialization/Teardown
|
| 24 |
+
* */
|
| 25 |
+
// No-op by default. Allows custom functionality to be exposed through
|
| 26 |
+
// extension bindings.
|
| 27 |
+
virtual void InitializeAtenBindings() const {}
|
| 28 |
+
|
| 29 |
+
virtual void PrepareToExit() const = 0;
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* Configuration
|
| 33 |
+
* */
|
| 34 |
+
|
| 35 |
+
virtual void SetRngSeed(size_t seed) const = 0;
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* IR Tracing
|
| 39 |
+
* */
|
| 40 |
+
|
| 41 |
+
virtual const IrBuilder* GetIrBuilder() const = 0;
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* Data Transfer
|
| 45 |
+
* */
|
| 46 |
+
|
| 47 |
+
virtual BackendDataPtr MakeComputationDataFromTensor(
|
| 48 |
+
const at::Tensor& tensor,
|
| 49 |
+
const Shape& shape,
|
| 50 |
+
const BackendDevice& device) const = 0;
|
| 51 |
+
virtual BackendDataPtr MakeComputationDataFromScalar(
|
| 52 |
+
const at::Scalar& scalar,
|
| 53 |
+
const torch::lazy::BackendDevice& device) const = 0;
|
| 54 |
+
virtual BackendDataPtr CreateDataPlaceholder(
|
| 55 |
+
const BackendDevice& device,
|
| 56 |
+
const Shape& shape) const = 0;
|
| 57 |
+
|
| 58 |
+
// Gets backend data if the node is a device data node. Otherwise returns
|
| 59 |
+
// nullptr
|
| 60 |
+
virtual BackendDataPtr GetComputationDataFromNode(const Node*) const = 0;
|
| 61 |
+
|
| 62 |
+
virtual at::Tensor MakeTensorFromComputationData(
|
| 63 |
+
const BackendDataPtr data,
|
| 64 |
+
std::optional<at::ScalarType> logical_scalar_type) const = 0;
|
| 65 |
+
|
| 66 |
+
/**
|
| 67 |
+
* Lowering, Compilation, Execution
|
| 68 |
+
* */
|
| 69 |
+
|
| 70 |
+
virtual std::unique_ptr<LoweringContext> CreateLoweringContext(
|
| 71 |
+
const std::string& name,
|
| 72 |
+
BackendDevice device,
|
| 73 |
+
c10::ArrayRef<const torch::lazy::Node*> post_order,
|
| 74 |
+
Util::EmissionMap emit_status) const = 0;
|
| 75 |
+
|
| 76 |
+
virtual std::unique_ptr<LoweringContext> CreateLoweringContext(
|
| 77 |
+
const std::string& name,
|
| 78 |
+
BackendDevice device) const = 0;
|
| 79 |
+
|
| 80 |
+
// TODO(whc) need to keep this?
|
| 81 |
+
virtual std::vector<std::string> GetCompilationDevices(
|
| 82 |
+
const std::string& device,
|
| 83 |
+
c10::ArrayRef<std::string> devices) const = 0;
|
| 84 |
+
|
| 85 |
+
virtual std::vector<ComputationPtr> Compile(
|
| 86 |
+
std::vector<ComputationPtr> instances) const = 0;
|
| 87 |
+
|
| 88 |
+
virtual std::vector<BackendDataPtr> ExecuteComputation(
|
| 89 |
+
torch::lazy::ComputationPtr computation,
|
| 90 |
+
c10::ArrayRef<BackendDataPtr> arguments,
|
| 91 |
+
const BackendDevice& device) const = 0;
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* Device Configuration
|
| 95 |
+
* */
|
| 96 |
+
|
| 97 |
+
// Set or get the default device type.
|
| 98 |
+
// For backends used with virtual c10::Devices, this configures what real
|
| 99 |
+
// device type the backend should use, and matters if the backend supports
|
| 100 |
+
// more than one type of real device.
|
| 101 |
+
virtual std::shared_ptr<BackendDeviceType> GetDefaultDeviceType() const = 0;
|
| 102 |
+
virtual void SetDefaultDeviceType(int8_t type) = 0;
|
| 103 |
+
|
| 104 |
+
// Set or get the default device ordinal.
|
| 105 |
+
// For backends that supports multi-device, this configures what the
|
| 106 |
+
// default device the backend should use.
|
| 107 |
+
virtual int64_t GetDefaultDeviceOrdinal() const = 0;
|
| 108 |
+
virtual void SetDefaultDeviceOrdinal(int64_t) = 0;
|
| 109 |
+
|
| 110 |
+
// Specify which aten device should be used for eager fallback
|
| 111 |
+
// may change depending on current 'Default' DeviceType
|
| 112 |
+
virtual at::DeviceType EagerFallbackDeviceType() const = 0;
|
| 113 |
+
|
| 114 |
+
// Query all available backend devices
|
| 115 |
+
virtual std::vector<BackendDevice> GetBackendDevices() const = 0;
|
| 116 |
+
|
| 117 |
+
virtual std::string CreateMetricReport() const {
|
| 118 |
+
return "";
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
// Map a particular c10:: device to a concrete backend device
|
| 122 |
+
// Note:: c10:: devices may be virtual or concrete. xla:: and lazy:: are
|
| 123 |
+
// virtual devices, meaning they may map to a gpu, tpu, etc. behind the
|
| 124 |
+
// scenes. In the future, non-virtual c10:: devices may also use lazy tensors
|
| 125 |
+
// through a mode, in which case these APIs should still work, but should be
|
| 126 |
+
// identity mappings.
|
| 127 |
+
virtual BackendDevice GetBackendDevice(c10::Device device) const = 0;
|
| 128 |
+
|
| 129 |
+
// TODO(whc)
|
| 130 |
+
// Additional APIs expected for supporting distributed training, to be
|
| 131 |
+
// designed
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
* Debug/Metrics
|
| 135 |
+
* */
|
| 136 |
+
|
| 137 |
+
// virtual std::map<std::string, Metric> GetMetrics() const = 0;
|
| 138 |
+
|
| 139 |
+
// virtual MemoryInfo GetMemoryInfo(const std::string& device) = 0;
|
| 140 |
+
|
| 141 |
+
virtual std::string GetComputationBackendText(
|
| 142 |
+
const ComputationPtr computation) const = 0;
|
| 143 |
+
};
|
| 144 |
+
|
| 145 |
+
class TORCH_API BackendRegistrar {
|
| 146 |
+
public:
|
| 147 |
+
BackendRegistrar(const BackendImplInterface* backend_impl_interface);
|
| 148 |
+
};
|
| 149 |
+
|
| 150 |
+
TORCH_API bool hasBackend();
|
| 151 |
+
TORCH_API const BackendImplInterface* getBackend();
|
| 152 |
+
|
| 153 |
+
TORCH_API const IrBuilder* getIrBuilder();
|
| 154 |
+
|
| 155 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/backend/lowering_context.h
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <memory>
|
| 4 |
+
#include <string>
|
| 5 |
+
#include <vector>
|
| 6 |
+
|
| 7 |
+
#include <torch/csrc/lazy/backend/backend_data.h>
|
| 8 |
+
#include <torch/csrc/lazy/backend/backend_device.h>
|
| 9 |
+
#include <torch/csrc/lazy/core/ir.h>
|
| 10 |
+
#include <torch/csrc/lazy/core/ir_util.h>
|
| 11 |
+
|
| 12 |
+
namespace torch::lazy {
|
| 13 |
+
|
| 14 |
+
class TORCH_API Computation {
|
| 15 |
+
public:
|
| 16 |
+
virtual int parameters_size() const = 0;
|
| 17 |
+
|
| 18 |
+
virtual const std::vector<Shape>& parameter_shapes() const = 0;
|
| 19 |
+
|
| 20 |
+
virtual const std::vector<std::string>& parameter_names() const = 0;
|
| 21 |
+
|
| 22 |
+
virtual const Shape& result_shape() const = 0;
|
| 23 |
+
|
| 24 |
+
virtual const std::string to_string() const = 0;
|
| 25 |
+
|
| 26 |
+
virtual ~Computation() = default;
|
| 27 |
+
|
| 28 |
+
// Indicates whether this computation is being executed inside a mark step
|
| 29 |
+
// Assume false unless set otherwise
|
| 30 |
+
bool in_mark_step = false;
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
using ComputationPtr = std::shared_ptr<Computation>;
|
| 34 |
+
|
| 35 |
+
// Keeps track of the code generation state.
|
| 36 |
+
class TORCH_API LoweringContext {
|
| 37 |
+
public:
|
| 38 |
+
LoweringContext(const std::string& name, BackendDevice device);
|
| 39 |
+
LoweringContext(
|
| 40 |
+
const std::string& name,
|
| 41 |
+
BackendDevice device,
|
| 42 |
+
c10::ArrayRef<const torch::lazy::Node*> post_order,
|
| 43 |
+
Util::EmissionMap emit_status);
|
| 44 |
+
|
| 45 |
+
virtual ~LoweringContext() = default;
|
| 46 |
+
|
| 47 |
+
static std::unique_ptr<LoweringContext> Create(
|
| 48 |
+
const std::string& name,
|
| 49 |
+
BackendDevice device,
|
| 50 |
+
c10::ArrayRef<const torch::lazy::Node*> post_order,
|
| 51 |
+
Util::EmissionMap emit_status);
|
| 52 |
+
|
| 53 |
+
static std::unique_ptr<LoweringContext> Create(
|
| 54 |
+
const std::string& name,
|
| 55 |
+
BackendDevice device);
|
| 56 |
+
|
| 57 |
+
const BackendDevice& device() const {
|
| 58 |
+
return device_;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
// Retrieves the vector holding all the tensors associated with the parameter
|
| 62 |
+
// instructions which have been created.
|
| 63 |
+
const std::vector<BackendDataPtr>& GetParametersData() const;
|
| 64 |
+
|
| 65 |
+
// Adds a new input/output alias.
|
| 66 |
+
virtual void SetUpAlias(
|
| 67 |
+
const std::vector<int64_t>& output_index,
|
| 68 |
+
int64_t param_number,
|
| 69 |
+
const std::vector<int64_t>& param_index,
|
| 70 |
+
bool must_alias = false) {
|
| 71 |
+
// Dummy default implementation to do nothing.
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// Check if parameter shape matches result at index.
|
| 75 |
+
virtual bool CheckResultShape(
|
| 76 |
+
const BackendDataPtr& parameter_data,
|
| 77 |
+
size_t result_idx) {
|
| 78 |
+
// Dummy default implementation to do nothing.
|
| 79 |
+
return false;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
// Adds the given output as a component of the result tuple and returns its
|
| 83 |
+
// assigned position within the tuple.
|
| 84 |
+
virtual size_t AddResult(const torch::lazy::Output& output) = 0;
|
| 85 |
+
|
| 86 |
+
// Associates the given output with the input parameter of the given index and
|
| 87 |
+
// shape. Only used for the operator-by-operator execution, mostly for
|
| 88 |
+
// debugging purposes.
|
| 89 |
+
virtual void AddParameter(
|
| 90 |
+
const torch::lazy::Output& output,
|
| 91 |
+
size_t index,
|
| 92 |
+
const Shape& shape,
|
| 93 |
+
const std::string& name) = 0;
|
| 94 |
+
|
| 95 |
+
// Build the computation capturing all the operations created with the
|
| 96 |
+
// embedded builder (returned by the builder() API).
|
| 97 |
+
virtual ComputationPtr Build() = 0;
|
| 98 |
+
|
| 99 |
+
size_t GetEmittedNodeCount() const {
|
| 100 |
+
return emit_status_.size();
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
protected:
|
| 104 |
+
BackendDevice device_;
|
| 105 |
+
std::vector<BackendDataPtr> parameters_;
|
| 106 |
+
std::vector<size_t> parameter_sequence_;
|
| 107 |
+
Util::EmissionMap emit_status_;
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/cache.h
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Cache utils in this file is adapted from PyTorch/XLA
|
| 3 |
+
* https://github.com/pytorch/xla/blob/e0e5f937a0ba8d904f9608137dc8c51ba439df2d/third_party/xla_client/cache.h
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
#pragma once
|
| 7 |
+
|
| 8 |
+
#include <functional>
|
| 9 |
+
#include <list>
|
| 10 |
+
#include <memory>
|
| 11 |
+
#include <mutex>
|
| 12 |
+
#include <unordered_map>
|
| 13 |
+
#include <utility>
|
| 14 |
+
|
| 15 |
+
namespace torch::lazy {
|
| 16 |
+
|
| 17 |
+
// Generic key and object cache with LRU expiration policy. The objects of type
|
| 18 |
+
// T will be stored as std::shared_ptr<T> and taken and returned as such, by the
|
| 19 |
+
// cache API.
|
| 20 |
+
template <
|
| 21 |
+
typename K,
|
| 22 |
+
typename T,
|
| 23 |
+
typename H = std::hash<K>,
|
| 24 |
+
typename E = std::equal_to<K>>
|
| 25 |
+
class Cache {
|
| 26 |
+
public:
|
| 27 |
+
using TypePtr = std::shared_ptr<T>;
|
| 28 |
+
using Element = std::pair<K, TypePtr>;
|
| 29 |
+
|
| 30 |
+
explicit Cache(size_t max_size) : max_size_(max_size) {}
|
| 31 |
+
|
| 32 |
+
// Adds an object to the cache, unless it already exists. If the cache grows
|
| 33 |
+
// beyond the limit set during construction, the oldest used object will be
|
| 34 |
+
// removed from the cache.
|
| 35 |
+
TypePtr Add(K key, TypePtr object) {
|
| 36 |
+
if (!max_size_) {
|
| 37 |
+
return object;
|
| 38 |
+
}
|
| 39 |
+
std::lock_guard<std::mutex> slock(lock_);
|
| 40 |
+
element_list_.emplace_front(Element(std::move(key), std::move(object)));
|
| 41 |
+
auto it = element_list_.begin();
|
| 42 |
+
auto emplace_result = element_map_.emplace(&it->first, it);
|
| 43 |
+
if (!emplace_result.second) {
|
| 44 |
+
element_list_.erase(it);
|
| 45 |
+
DoLRU(emplace_result.first->second);
|
| 46 |
+
} else if (element_list_.size() > max_size_) {
|
| 47 |
+
Element* last = &element_list_.back();
|
| 48 |
+
element_map_.erase(&last->first);
|
| 49 |
+
element_list_.pop_back();
|
| 50 |
+
}
|
| 51 |
+
return emplace_result.first->second->second;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Retrieves the existing object if it exists. If it does, its position in
|
| 55 |
+
// the LRU list gets moved to the head of the list.
|
| 56 |
+
// Returns nullptr if no object with the specified key is found within the
|
| 57 |
+
// cache.
|
| 58 |
+
TypePtr Get(const K& key) {
|
| 59 |
+
if (!max_size_) {
|
| 60 |
+
return nullptr;
|
| 61 |
+
}
|
| 62 |
+
std::lock_guard<std::mutex> slock(lock_);
|
| 63 |
+
auto it = element_map_.find(&key);
|
| 64 |
+
if (it == element_map_.end()) {
|
| 65 |
+
return nullptr;
|
| 66 |
+
}
|
| 67 |
+
DoLRU(it->second);
|
| 68 |
+
return it->second->second;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
TypePtr GetLatest() {
|
| 72 |
+
std::lock_guard<std::mutex> g(lock_);
|
| 73 |
+
TORCH_CHECK(!element_list_.empty());
|
| 74 |
+
return element_list_.front().second;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
bool Erase(const K& key) {
|
| 78 |
+
if (!max_size_) {
|
| 79 |
+
return false;
|
| 80 |
+
}
|
| 81 |
+
std::lock_guard<std::mutex> slock(lock_);
|
| 82 |
+
auto it = element_map_.find(&key);
|
| 83 |
+
if (it == element_map_.end()) {
|
| 84 |
+
return false;
|
| 85 |
+
}
|
| 86 |
+
auto lit = it->second;
|
| 87 |
+
element_map_.erase(it);
|
| 88 |
+
element_list_.erase(lit);
|
| 89 |
+
return true;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
void Clear() {
|
| 93 |
+
if (!max_size_) {
|
| 94 |
+
return;
|
| 95 |
+
}
|
| 96 |
+
std::lock_guard<std::mutex> slock(lock_);
|
| 97 |
+
element_map_.clear();
|
| 98 |
+
element_list_.clear();
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
int Numel() const {
|
| 102 |
+
if (!max_size_) {
|
| 103 |
+
return 0;
|
| 104 |
+
}
|
| 105 |
+
std::lock_guard<std::mutex> g(lock_);
|
| 106 |
+
TORCH_CHECK(element_map_.size() == element_list_.size());
|
| 107 |
+
return element_map_.size();
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
private:
|
| 111 |
+
using ElementList = std::list<Element>;
|
| 112 |
+
|
| 113 |
+
struct Hasher {
|
| 114 |
+
size_t operator()(const K* key) const {
|
| 115 |
+
return hasher(*key);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
H hasher;
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
+
struct Equaler {
|
| 122 |
+
bool operator()(const K* k1, const K* k2) const {
|
| 123 |
+
return equaler(*k1, *k2);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
E equaler;
|
| 127 |
+
};
|
| 128 |
+
|
| 129 |
+
using ElementMap = std::
|
| 130 |
+
unordered_map<const K*, typename ElementList::iterator, Hasher, Equaler>;
|
| 131 |
+
|
| 132 |
+
void DoLRU(typename ElementList::iterator it) {
|
| 133 |
+
element_list_.splice(element_list_.begin(), element_list_, it);
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
mutable std::mutex lock_;
|
| 137 |
+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
|
| 138 |
+
const size_t max_size_ = 0;
|
| 139 |
+
ElementList element_list_;
|
| 140 |
+
ElementMap element_map_;
|
| 141 |
+
};
|
| 142 |
+
|
| 143 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/config.h
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
#include <c10/macros/Export.h>
|
| 3 |
+
#include <c10/util/Flags.h>
|
| 4 |
+
|
| 5 |
+
TORCH_DECLARE_bool(torch_lazy_ir_debug);
|
| 6 |
+
TORCH_DECLARE_bool(torch_lazy_handle_special_scalars);
|
| 7 |
+
TORCH_DECLARE_bool(torch_lazy_all_numbers_special_scalars);
|
| 8 |
+
TORCH_DECLARE_bool(torch_lazy_param_aliasing);
|
| 9 |
+
TORCH_DECLARE_bool(torch_lazy_reuse_ir);
|
| 10 |
+
TORCH_DECLARE_bool(torch_lazy_use_thread_pool);
|
| 11 |
+
TORCH_DECLARE_bool(torch_lazy_enable_device_data_cache);
|
| 12 |
+
|
| 13 |
+
TORCH_DECLARE_int(torch_lazy_compilation_cache_size);
|
| 14 |
+
TORCH_DECLARE_int(torch_lazy_device_data_cache_size);
|
| 15 |
+
TORCH_DECLARE_int(torch_lazy_io_thread_pool_size);
|
| 16 |
+
TORCH_DECLARE_int(torch_lazy_metrics_samples);
|
| 17 |
+
TORCH_DECLARE_int(torch_lazy_trim_graph_check_frequency);
|
| 18 |
+
TORCH_DECLARE_int(torch_lazy_trim_graph_size);
|
| 19 |
+
|
| 20 |
+
TORCH_DECLARE_string(torch_lazy_metrics_percentiles);
|
| 21 |
+
|
| 22 |
+
TORCH_DECLARE_int(torch_lazy_shape_cache_size);
|
| 23 |
+
|
| 24 |
+
namespace torch::lazy {
|
| 25 |
+
TORCH_API std::string& getLTCForceFallback();
|
| 26 |
+
}
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/debug_util.h
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <string>
|
| 4 |
+
#include <vector>
|
| 5 |
+
|
| 6 |
+
#include <torch/csrc/lazy/core/tensor.h>
|
| 7 |
+
|
| 8 |
+
namespace torch::lazy {
|
| 9 |
+
|
| 10 |
+
TORCH_API std::function<std::vector<SourceLocation>()>&
|
| 11 |
+
GetPythonFramesFunction();
|
| 12 |
+
|
| 13 |
+
TORCH_API std::string GetFirstUserFrameInPython();
|
| 14 |
+
|
| 15 |
+
class TORCH_API DebugUtil {
|
| 16 |
+
public:
|
| 17 |
+
enum GraphFormat {
|
| 18 |
+
kText,
|
| 19 |
+
kDot,
|
| 20 |
+
kBackend,
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
static GraphFormat GetDefaultGraphFormat();
|
| 24 |
+
|
| 25 |
+
// Dumps the current Python frame and the IR Graph whose roots are the IR
|
| 26 |
+
// values held at the tensors. If indices is not nullptr, it selects the
|
| 27 |
+
// indices of the tensors whose graph will be emitted.
|
| 28 |
+
static std::string GetTensorsGraphInfo(
|
| 29 |
+
c10::ArrayRef<torch::lazy::LazyTensorPtr> tensors,
|
| 30 |
+
const std::vector<size_t>* indices,
|
| 31 |
+
GraphFormat format = GetDefaultGraphFormat());
|
| 32 |
+
|
| 33 |
+
// If the environment variable LTC_SAVE_TENSORS_FILE is set to the proper
|
| 34 |
+
// output path, an instance of the report returned by GetTensorsGraphInfo() is
|
| 35 |
+
// saved.
|
| 36 |
+
static void SaveTensorsGraphInfo(
|
| 37 |
+
const char* name,
|
| 38 |
+
c10::ArrayRef<torch::lazy::LazyTensorPtr> tensors,
|
| 39 |
+
const std::vector<size_t>* indices,
|
| 40 |
+
GraphFormat format = GetDefaultGraphFormat());
|
| 41 |
+
|
| 42 |
+
static bool ExperimentEnabled(const std::string& name);
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/dynamic_ir.h
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/core/symbol.h>
|
| 4 |
+
|
| 5 |
+
#include <c10/core/ScalarType.h>
|
| 6 |
+
#include <c10/util/Flags.h>
|
| 7 |
+
#include <torch/csrc/lazy/core/hash.h>
|
| 8 |
+
#include <torch/csrc/lazy/core/ir.h>
|
| 9 |
+
#include <torch/csrc/lazy/core/ir_metadata.h>
|
| 10 |
+
#include <torch/csrc/lazy/ts_backend/ts_node.h>
|
| 11 |
+
|
| 12 |
+
namespace torch::lazy {
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* The goal of "dynamic" Nodes is to patch a hole in our tracing.
|
| 16 |
+
* Previously, if a user called `sizes` on a Tensor, it would leak out
|
| 17 |
+
* of our tracing system, as `sizes` returns a torch.Size or an int. To
|
| 18 |
+
* prevent this from happening, we introduce DimensionNode, a new type
|
| 19 |
+
* of Node that abstracts the operation of getting the dimensions of a
|
| 20 |
+
* Tensor.
|
| 21 |
+
*
|
| 22 |
+
* Consider the following example:
|
| 23 |
+
* ```
|
| 24 |
+
* numel = x.shape()[0] * x.shape()[1]
|
| 25 |
+
* ```
|
| 26 |
+
*
|
| 27 |
+
* Here, `x.shape()[i]` will be a SizeNode (subclass of DimensionNode),
|
| 28 |
+
* and the multiplication of the two SizeNodes will be represented by
|
| 29 |
+
* a SizeMul (also a subclass of DimensionNode). Through this, we can
|
| 30 |
+
* prevent `numel` from being represented as a Python int and thus
|
| 31 |
+
* burned into the Graph.
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
class TORCH_API DimensionNode {
|
| 35 |
+
public:
|
| 36 |
+
virtual bool isSymbolic() const {
|
| 37 |
+
return false;
|
| 38 |
+
}
|
| 39 |
+
virtual int64_t getDynamicValue() const {
|
| 40 |
+
TORCH_CHECK(false, "NYI");
|
| 41 |
+
}
|
| 42 |
+
virtual int64_t getStaticValue() const {
|
| 43 |
+
TORCH_CHECK(false, "NYI");
|
| 44 |
+
}
|
| 45 |
+
virtual ~DimensionNode() = default;
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/hash.h
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Hash utils in this file is adapted from PyTorch/XLA
|
| 3 |
+
* https://github.com/pytorch/xla/blob/e0e5f937a0ba8d904f9608137dc8c51ba439df2d/third_party/xla_client/util.h
|
| 4 |
+
*/
|
| 5 |
+
#pragma once
|
| 6 |
+
|
| 7 |
+
#include <ATen/Tensor.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <c10/util/int128.h>
|
| 10 |
+
#include <torch/csrc/Export.h>
|
| 11 |
+
#include <cstring>
|
| 12 |
+
#include <set>
|
| 13 |
+
#include <string>
|
| 14 |
+
#include <string_view>
|
| 15 |
+
#include <vector>
|
| 16 |
+
|
| 17 |
+
namespace torch::lazy {
|
| 18 |
+
|
| 19 |
+
using size_t = std::size_t;
|
| 20 |
+
|
| 21 |
+
class TORCH_API hash_t : public c10::uint128 {
|
| 22 |
+
public:
|
| 23 |
+
// Switch from typedef hash_t = uint128 to provide explicit casters
|
| 24 |
+
hash_t(int8_t val) : uint128(static_cast<uint32_t>(val)) {}
|
| 25 |
+
hash_t(int16_t val) : uint128(static_cast<uint32_t>(val)) {}
|
| 26 |
+
hash_t(int32_t val) : uint128(static_cast<uint32_t>(val)) {}
|
| 27 |
+
hash_t(int64_t val) : uint128(static_cast<uint64_t>(val)) {}
|
| 28 |
+
hash_t(uint32_t val) : uint128(val) {}
|
| 29 |
+
hash_t(uint64_t val) : uint128(val) {}
|
| 30 |
+
hash_t(uint128 val) : uint128(val) {}
|
| 31 |
+
hash_t(uint64_t top, uint64_t bottom) : uint128(top, bottom) {}
|
| 32 |
+
hash_t() = default;
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
// Std* functions use 64-bit hash
|
| 36 |
+
size_t TORCH_API StdDataHash(const void* data, size_t size);
|
| 37 |
+
|
| 38 |
+
size_t TORCH_API StdHashCombine(uintmax_t a, uintmax_t b);
|
| 39 |
+
|
| 40 |
+
// Other functions are all 128-bit
|
| 41 |
+
hash_t TORCH_API HashBlock(const void* data, size_t n, const hash_t& seed);
|
| 42 |
+
|
| 43 |
+
hash_t TORCH_API DataHash(const void* data, size_t size);
|
| 44 |
+
|
| 45 |
+
hash_t TORCH_API HashCombine(const hash_t& a, const hash_t& b);
|
| 46 |
+
|
| 47 |
+
size_t TORCH_API HashReduce(const hash_t& a);
|
| 48 |
+
|
| 49 |
+
// Returns a string representation of a hash
|
| 50 |
+
std::string TORCH_API HashToString(const hash_t& a);
|
| 51 |
+
|
| 52 |
+
struct HashReducer {
|
| 53 |
+
size_t operator()(const hash_t& value) const {
|
| 54 |
+
return HashReduce(value);
|
| 55 |
+
}
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
static inline hash_t StringHash(const char* data) {
|
| 59 |
+
return DataHash(data, std::strlen(data));
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// Automatic templated implementation for 'arithmetic' types
|
| 63 |
+
template <typename T, std::enable_if_t<std::is_arithmetic_v<T>>* = nullptr>
|
| 64 |
+
hash_t Hash(const T& value) {
|
| 65 |
+
return DataHash(&value, sizeof(value));
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
// added because on macos builds the vector<bool> specialization
|
| 69 |
+
// breaks falling through to the templated arithmetic types above
|
| 70 |
+
hash_t TORCH_API Hash(const std::vector<bool>& value);
|
| 71 |
+
|
| 72 |
+
// Specialized implementations for proprietary types
|
| 73 |
+
static inline hash_t Hash(const c10::ScalarType& value) {
|
| 74 |
+
return DataHash(&value, sizeof(value));
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
static inline hash_t Hash(const c10::MemoryFormat& value) {
|
| 78 |
+
return DataHash(&value, sizeof(value));
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
static inline hash_t Hash(const c10::DeviceType& value) {
|
| 82 |
+
return DataHash(&value, sizeof(value));
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
static inline hash_t Hash(const c10::Device& value) {
|
| 86 |
+
return HashCombine(Hash(value.type()), Hash(value.index()));
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
static inline hash_t Hash(const c10::Layout& value) {
|
| 90 |
+
return DataHash(&value, sizeof(value));
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
static inline hash_t Hash(const c10::Scalar& value) {
|
| 94 |
+
switch (value.type()) {
|
| 95 |
+
case c10::ScalarType::ComplexDouble:
|
| 96 |
+
return Hash(value.toComplexDouble());
|
| 97 |
+
case c10::ScalarType::Double:
|
| 98 |
+
return Hash(value.toDouble());
|
| 99 |
+
case c10::ScalarType::Long:
|
| 100 |
+
return Hash(value.toLong());
|
| 101 |
+
case c10::ScalarType::Bool:
|
| 102 |
+
return Hash(value.toBool());
|
| 103 |
+
default:
|
| 104 |
+
TORCH_INTERNAL_ASSERT(false, "Unknown scalar type.", value.type());
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
static inline hash_t TensorHash(const at::Tensor& tensor) {
|
| 109 |
+
at::Tensor ctensor = tensor.contiguous();
|
| 110 |
+
int64_t size = ctensor.numel() * ctensor.element_size();
|
| 111 |
+
switch (ctensor.scalar_type()) {
|
| 112 |
+
case at::ScalarType::Bool:
|
| 113 |
+
return DataHash(ctensor.const_data_ptr<bool>(), size);
|
| 114 |
+
case at::ScalarType::Byte:
|
| 115 |
+
return DataHash(ctensor.const_data_ptr<uint8_t>(), size);
|
| 116 |
+
case at::ScalarType::Char:
|
| 117 |
+
return DataHash(ctensor.const_data_ptr<int8_t>(), size);
|
| 118 |
+
case at::ScalarType::Short:
|
| 119 |
+
return DataHash(ctensor.const_data_ptr<int16_t>(), size);
|
| 120 |
+
case at::ScalarType::Int:
|
| 121 |
+
return DataHash(ctensor.const_data_ptr<int32_t>(), size);
|
| 122 |
+
case at::ScalarType::Long:
|
| 123 |
+
return DataHash(ctensor.const_data_ptr<int64_t>(), size);
|
| 124 |
+
case at::ScalarType::Float:
|
| 125 |
+
return DataHash(ctensor.const_data_ptr<float>(), size);
|
| 126 |
+
case at::ScalarType::Double:
|
| 127 |
+
return DataHash(ctensor.const_data_ptr<double>(), size);
|
| 128 |
+
case at::ScalarType::BFloat16:
|
| 129 |
+
return DataHash(ctensor.const_data_ptr<at::BFloat16>(), size);
|
| 130 |
+
case at::ScalarType::Half:
|
| 131 |
+
return DataHash(ctensor.const_data_ptr<at::Half>(), size);
|
| 132 |
+
case at::ScalarType::ComplexFloat:
|
| 133 |
+
return DataHash(ctensor.const_data_ptr<c10::complex<float>>(), size);
|
| 134 |
+
case at::ScalarType::ComplexDouble:
|
| 135 |
+
return DataHash(ctensor.const_data_ptr<c10::complex<double>>(), size);
|
| 136 |
+
case at::ScalarType::UInt16:
|
| 137 |
+
return DataHash(ctensor.const_data_ptr<uint16_t>(), size);
|
| 138 |
+
case at::ScalarType::UInt32:
|
| 139 |
+
return DataHash(ctensor.const_data_ptr<uint32_t>(), size);
|
| 140 |
+
case at::ScalarType::UInt64:
|
| 141 |
+
return DataHash(ctensor.const_data_ptr<uint64_t>(), size);
|
| 142 |
+
default:
|
| 143 |
+
TORCH_INTERNAL_ASSERT(
|
| 144 |
+
false, "Unsupported scalar type:", ctensor.scalar_type());
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
static inline hash_t Hash(const std::string& value) {
|
| 149 |
+
return DataHash(value.data(), value.size());
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
static inline hash_t Hash(const std::string_view& value) {
|
| 153 |
+
return DataHash(value.data(), value.size());
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
static inline hash_t Hash(const at::Generator& value) {
|
| 157 |
+
return TensorHash(value.get_state());
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
// Taken from glibc's implementation of hashing optionals,
|
| 161 |
+
// we want to include a contribution to the hash to distinguish
|
| 162 |
+
// cases where one or another option was null, but we hope it doesn't
|
| 163 |
+
// collide with an actually scalar value.
|
| 164 |
+
//
|
| 165 |
+
// Use an arbitrary randomly-selected 64-bit integer rather than a
|
| 166 |
+
// small constant that we then hash at runtime so we don't have to
|
| 167 |
+
// repeatedly hash a constant at runtime.
|
| 168 |
+
// NOLINTNEXTLINE(*-narrowing-conversions)
|
| 169 |
+
static const int64_t kNullOpt = 0x8655d738f3678dda;
|
| 170 |
+
|
| 171 |
+
// Hashing for std::optional types contributes to hash
|
| 172 |
+
// for optionals with null value, important to distinguish
|
| 173 |
+
// between <nullopt, non-nullopt> and <non-nullopt, nullopt> cases
|
| 174 |
+
template <typename T>
|
| 175 |
+
hash_t Hash(const std::optional<T>& value) {
|
| 176 |
+
if (value.has_value()) {
|
| 177 |
+
return Hash(value.value());
|
| 178 |
+
} else {
|
| 179 |
+
return kNullOpt;
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
// Hashing of containers
|
| 184 |
+
// Forward declare to allow hashes of vectors of vectors to work.
|
| 185 |
+
template <typename T>
|
| 186 |
+
hash_t ContainerHash(const T& values);
|
| 187 |
+
|
| 188 |
+
template <typename T>
|
| 189 |
+
hash_t Hash(const std::vector<T>& values) {
|
| 190 |
+
return ContainerHash(values);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// Need a special case for std::optional<container>?
|
| 194 |
+
template <typename T>
|
| 195 |
+
hash_t Hash(const std::optional<std::vector<T>>& value) {
|
| 196 |
+
if (value.has_value()) {
|
| 197 |
+
return ContainerHash(value.value());
|
| 198 |
+
} else {
|
| 199 |
+
return kNullOpt;
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
template <typename T>
|
| 204 |
+
hash_t Hash(const std::set<T>& values) {
|
| 205 |
+
return ContainerHash(values);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
template <typename T, typename S>
|
| 209 |
+
hash_t Hash(const std::pair<T, S>& values) {
|
| 210 |
+
return HashCombine(Hash(values.first), Hash(values.second));
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
static inline hash_t Hash(const hash_t& value) {
|
| 214 |
+
return value;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
template <typename T>
|
| 218 |
+
hash_t Hash(c10::ArrayRef<T> values) {
|
| 219 |
+
return ContainerHash(values);
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
template <typename T>
|
| 223 |
+
hash_t ContainerHash(const T& values) {
|
| 224 |
+
hash_t h(static_cast<uint64_t>(0x85ebca77c2b2ae63));
|
| 225 |
+
for (const auto& value : values) {
|
| 226 |
+
h = HashCombine(h, Hash(value));
|
| 227 |
+
}
|
| 228 |
+
return h;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
// Varargs hashing
|
| 232 |
+
template <typename T = void>
|
| 233 |
+
hash_t MHash() {
|
| 234 |
+
return hash_t(static_cast<uint64_t>(0x165667b19e3779f9));
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
template <typename T, typename... Targs>
|
| 238 |
+
hash_t MHash(T value, Targs... Fargs) {
|
| 239 |
+
return HashCombine(Hash(value), MHash(Fargs...));
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/helpers.h
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/core/Scalar.h>
|
| 4 |
+
#include <c10/util/BFloat16.h>
|
| 5 |
+
#include <c10/util/Half.h>
|
| 6 |
+
#include <torch/csrc/lazy/core/permutation_util.h>
|
| 7 |
+
#include <torch/csrc/lazy/core/shape.h>
|
| 8 |
+
#include <torch/csrc/lazy/core/util.h>
|
| 9 |
+
|
| 10 |
+
#include <complex>
|
| 11 |
+
#include <functional>
|
| 12 |
+
#include <optional>
|
| 13 |
+
#include <tuple>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
// TODO: Consolidate this file with util.h
|
| 17 |
+
|
| 18 |
+
namespace torch::lazy {
|
| 19 |
+
|
| 20 |
+
// Converts an iterable container to a vector of int64's.
|
| 21 |
+
template <typename S>
|
| 22 |
+
static std::vector<int64_t> ToI64Vector(const S& input) {
|
| 23 |
+
return ToVector<int64_t>(input);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
// Creates a set of dimension by dropping the drop_dims ones.
|
| 27 |
+
TORCH_API std::vector<int64_t> DropDimensions(
|
| 28 |
+
c10::ArrayRef<int64_t> sizes,
|
| 29 |
+
c10::ArrayRef<int64_t> drop_dims);
|
| 30 |
+
|
| 31 |
+
// Get the canonical dimension index in the [0, rank) interval. Negative
|
| 32 |
+
// indices are interpreted as follows: -1 is rank-1, -2 is rank-2 etc.
|
| 33 |
+
TORCH_API int64_t GetCanonicalDimensionIndex(int64_t dim, int64_t rank);
|
| 34 |
+
|
| 35 |
+
// Same as above, for multiple dimensions.
|
| 36 |
+
TORCH_API std::vector<int64_t> GetCanonicalDimensionIndices(
|
| 37 |
+
c10::ArrayRef<int64_t> dimensions,
|
| 38 |
+
int64_t rank);
|
| 39 |
+
|
| 40 |
+
// Returns the canonical position in the dim dimension, handling negative
|
| 41 |
+
// values for the position.
|
| 42 |
+
TORCH_API int64_t GetCanonicalPosition(
|
| 43 |
+
c10::ArrayRef<int64_t> dimensions,
|
| 44 |
+
int64_t dim,
|
| 45 |
+
int64_t pos);
|
| 46 |
+
|
| 47 |
+
// Creates a transposition from the given input and dimensions.
|
| 48 |
+
TORCH_API std::vector<int64_t> MakeTransposePermutation(
|
| 49 |
+
int64_t dim0,
|
| 50 |
+
int64_t dim1,
|
| 51 |
+
int64_t rank);
|
| 52 |
+
|
| 53 |
+
// Calculates the protomoted shape to which the input shapes should be
|
| 54 |
+
// broadcasted for an elementwise operation. The size of the common dimensions
|
| 55 |
+
// (2,3,4 for shape1, and 0,1,2 for shape2) must either match, or either one
|
| 56 |
+
// of the two be 1.
|
| 57 |
+
// Example:
|
| 58 |
+
// shape1 = [9, 7, 6, 1, 2]
|
| 59 |
+
// shape2 = [6, 5, 2]
|
| 60 |
+
// result_shape = [9, 7, 6, 5, 2]
|
| 61 |
+
TORCH_API std::vector<int64_t> GetPromotedShape(
|
| 62 |
+
c10::ArrayRef<int64_t> shape1_dims,
|
| 63 |
+
c10::ArrayRef<int64_t> shape2_dims);
|
| 64 |
+
|
| 65 |
+
TORCH_API Shape
|
| 66 |
+
GetPromotedBinaryOpShape(const Shape& shape1, const Shape& shape2);
|
| 67 |
+
|
| 68 |
+
TORCH_API std::vector<std::string> StrSplit(std::string_view text, char delim);
|
| 69 |
+
|
| 70 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/internal_ops/ltc_ops.h
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/lazy/core/ir.h>
|
| 4 |
+
|
| 5 |
+
#include <c10/util/CallOnce.h>
|
| 6 |
+
|
| 7 |
+
#include <string>
|
| 8 |
+
|
| 9 |
+
namespace torch::lazy {
|
| 10 |
+
|
| 11 |
+
class TORCH_API OpKindWrapper {
|
| 12 |
+
public:
|
| 13 |
+
explicit OpKindWrapper(const char* name) : name_(name) {}
|
| 14 |
+
|
| 15 |
+
const OpKind& operator*() const {
|
| 16 |
+
return get();
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
operator OpKind() const {
|
| 20 |
+
return get();
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
private:
|
| 24 |
+
const OpKind& get() const {
|
| 25 |
+
c10::call_once(once_, [this]() { op_kind_ = OpKind::Get(name_); });
|
| 26 |
+
return op_kind_;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
const char* name_;
|
| 30 |
+
mutable OpKind op_kind_;
|
| 31 |
+
mutable c10::once_flag once_;
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
const OpKindWrapper ltc_all_to_all("lazy_tensors::all_to_all");
|
| 35 |
+
const OpKindWrapper ltc_cast("lazy_tensors::cast");
|
| 36 |
+
const OpKindWrapper ltc_collective_permute("lazy_tensors::collective_permute");
|
| 37 |
+
const OpKindWrapper ltc_cross_replica_sum("lazy_tensors::cross_replica_sum");
|
| 38 |
+
const OpKindWrapper ltc_device_data("lazy_tensors::device_data");
|
| 39 |
+
const OpKindWrapper ltc_get_dimensions_size(
|
| 40 |
+
"lazy_tensors::ltc_get_dimensions_size");
|
| 41 |
+
const OpKindWrapper ltc_moving_average("lazy_tensors::moving_average");
|
| 42 |
+
const OpKindWrapper ltc_nms("lazy_tensors::nms");
|
| 43 |
+
const OpKindWrapper ltc_not_supported("lazy_tensors::not_supported");
|
| 44 |
+
const OpKindWrapper ltc_replication_pad("lazy_tensors::replication_pad");
|
| 45 |
+
const OpKindWrapper ltc_replication_pad_backward(
|
| 46 |
+
"lazy_tensors::replication_pad_backward");
|
| 47 |
+
const OpKindWrapper ltc_tensor_data("lazy_tensors::tensor_data");
|
| 48 |
+
|
| 49 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ir.h
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/core/symbol.h>
|
| 4 |
+
|
| 5 |
+
#include <functional>
|
| 6 |
+
#include <memory>
|
| 7 |
+
#include <set>
|
| 8 |
+
#include <string>
|
| 9 |
+
#include <unordered_map>
|
| 10 |
+
#include <unordered_set>
|
| 11 |
+
#include <utility>
|
| 12 |
+
#include <vector>
|
| 13 |
+
|
| 14 |
+
#include <c10/core/ScalarType.h>
|
| 15 |
+
#include <c10/util/ArrayRef.h>
|
| 16 |
+
#include <c10/util/Flags.h>
|
| 17 |
+
#include <torch/csrc/lazy/core/hash.h>
|
| 18 |
+
#include <torch/csrc/lazy/core/ir_metadata.h>
|
| 19 |
+
#include <torch/csrc/lazy/core/shape.h>
|
| 20 |
+
|
| 21 |
+
TORCH_DECLARE_bool(ltc_enable_dynamic_shapes);
|
| 22 |
+
|
| 23 |
+
namespace torch::lazy {
|
| 24 |
+
|
| 25 |
+
static const hash_t kHashSeed(static_cast<uint32_t>(0x5a2d296e9));
|
| 26 |
+
|
| 27 |
+
class Node;
|
| 28 |
+
struct Output;
|
| 29 |
+
struct Value;
|
| 30 |
+
|
| 31 |
+
using NodePtr = std::shared_ptr<Node>;
|
| 32 |
+
|
| 33 |
+
// The Kind of operation a Node can be associated to.
|
| 34 |
+
struct TORCH_API OpKind {
|
| 35 |
+
OpKind() = default;
|
| 36 |
+
explicit OpKind(c10::Symbol op) : op(op) {}
|
| 37 |
+
|
| 38 |
+
bool operator==(const OpKind& rhs) const {
|
| 39 |
+
return op == rhs.op;
|
| 40 |
+
}
|
| 41 |
+
bool operator!=(const OpKind& rhs) const {
|
| 42 |
+
return !operator==(rhs);
|
| 43 |
+
}
|
| 44 |
+
bool operator<(const OpKind& rhs) const {
|
| 45 |
+
return c10::unique_t(op) < c10::unique_t(rhs.op);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
hash_t hash() const;
|
| 49 |
+
|
| 50 |
+
std::string ToString() const {
|
| 51 |
+
return op.toQualString();
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Retrieves an existing operation object, or creates a new one. Operations
|
| 55 |
+
// that are specific to lazy tensors, should live within the 'lazy_tensors::'
|
| 56 |
+
// namespace.
|
| 57 |
+
static OpKind Get(const std::string& name);
|
| 58 |
+
|
| 59 |
+
c10::Symbol op;
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
inline std::ostream& operator<<(std::ostream& stream, const OpKind& op) {
|
| 63 |
+
stream << op.ToString();
|
| 64 |
+
return stream;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
using OpList = c10::ArrayRef<Value>;
|
| 68 |
+
|
| 69 |
+
hash_t OperandHashes(
|
| 70 |
+
const OpList& operands,
|
| 71 |
+
const hash_t& seed,
|
| 72 |
+
bool bakeInSizes);
|
| 73 |
+
// A node in the graph. Nodes for operations which require extra data to be
|
| 74 |
+
// stored for lowering should inherit from this class and add an operation
|
| 75 |
+
// specific member there. For example, a constant might create a new
|
| 76 |
+
// NodeConstant class (inheriting from Node) with an extra lazy_tensors::Literal
|
| 77 |
+
// field, or a tensor value might create a new NodeTensor with a computation
|
| 78 |
+
// client data handle in it.
|
| 79 |
+
class TORCH_API Node {
|
| 80 |
+
public:
|
| 81 |
+
static bool enableDynamicShape();
|
| 82 |
+
|
| 83 |
+
// Creates a new node with the given op name. The op is a unique identifier
|
| 84 |
+
// for the operation. The num_outputs tells how many outputs a given operation
|
| 85 |
+
// generates.
|
| 86 |
+
//
|
| 87 |
+
// None leaf node's node_hash does not contains shape information always.
|
| 88 |
+
// So we pass in the hash value rather than a function.
|
| 89 |
+
Node(OpKind op, size_t num_outputs);
|
| 90 |
+
|
| 91 |
+
// Construct node with operands and shapes
|
| 92 |
+
Node(
|
| 93 |
+
OpKind op,
|
| 94 |
+
OpList operands,
|
| 95 |
+
std::vector<Shape>&& shapes,
|
| 96 |
+
size_t num_outputs = 1);
|
| 97 |
+
|
| 98 |
+
// Construct node with operands and no shape
|
| 99 |
+
Node(OpKind op, OpList operands, size_t num_outputs = 1);
|
| 100 |
+
|
| 101 |
+
// Construct node with shape and no operands
|
| 102 |
+
Node(OpKind op, Shape shape, size_t num_outputs = 1);
|
| 103 |
+
|
| 104 |
+
virtual ~Node() = default;
|
| 105 |
+
|
| 106 |
+
const OpKind& op() const {
|
| 107 |
+
return op_;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
size_t num_outputs() const {
|
| 111 |
+
return num_outputs_;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// Retrieves the full shape of the IR Node.
|
| 115 |
+
virtual c10::ArrayRef<Shape> shapes() const;
|
| 116 |
+
|
| 117 |
+
virtual const Shape& shape(size_t output_index = 0) const;
|
| 118 |
+
|
| 119 |
+
// Add the shape computed by the shape_fn
|
| 120 |
+
void addComputedShape(const std::function<Shape()>& shape_fn);
|
| 121 |
+
|
| 122 |
+
// Compute the shape using the provided shape_fn if not previously cached
|
| 123 |
+
Shape computeShape(const std::function<Shape()>& shape_fn);
|
| 124 |
+
|
| 125 |
+
virtual const std::vector<Output>& operands() const;
|
| 126 |
+
|
| 127 |
+
virtual const Output& operand(size_t i) const;
|
| 128 |
+
|
| 129 |
+
// Gets operand at index i if index is valid, or kNullOutput otherwise.
|
| 130 |
+
virtual const Output& nullable_operand(size_t i) const;
|
| 131 |
+
|
| 132 |
+
// Returns the hash of the dag used to look up the compiled graph
|
| 133 |
+
virtual hash_t hash() const = 0;
|
| 134 |
+
|
| 135 |
+
// Returns the hash of the dag used to for shape caching
|
| 136 |
+
virtual hash_t shapeHash() const = 0;
|
| 137 |
+
|
| 138 |
+
const MetaData& metadata() const {
|
| 139 |
+
return metadata_;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
UserMetaData* user_metadata() const {
|
| 143 |
+
return user_metadata_.get();
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
std::shared_ptr<UserMetaData> SetUserMetadata(
|
| 147 |
+
std::shared_ptr<UserMetaData> user_meta) {
|
| 148 |
+
std::swap(user_metadata_, user_meta);
|
| 149 |
+
return user_meta;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
virtual std::string ToString() const;
|
| 153 |
+
|
| 154 |
+
private:
|
| 155 |
+
// The ID of the operation captured by this node.
|
| 156 |
+
OpKind op_;
|
| 157 |
+
size_t num_outputs_ = 1;
|
| 158 |
+
|
| 159 |
+
// The IR specific metadata attached to the IR node.
|
| 160 |
+
MetaData metadata_;
|
| 161 |
+
// The IR framework user can attach a user defined metadata object deriving
|
| 162 |
+
// from UserMetaData.
|
| 163 |
+
std::shared_ptr<UserMetaData> user_metadata_;
|
| 164 |
+
|
| 165 |
+
protected:
|
| 166 |
+
// Adds node's index output number as operand.
|
| 167 |
+
void AddOperand(const NodePtr& node, size_t index = 0);
|
| 168 |
+
|
| 169 |
+
std::vector<Shape> shapes_;
|
| 170 |
+
// A node holds a real reference to its operands.
|
| 171 |
+
std::vector<NodePtr> operands_;
|
| 172 |
+
// Outputs do not hold references on the nodes, and neither do the uses, since
|
| 173 |
+
// otherwise we get into circular reference counting.
|
| 174 |
+
std::vector<Output> operands_as_outputs_;
|
| 175 |
+
};
|
| 176 |
+
|
| 177 |
+
inline std::ostream& operator<<(std::ostream& stream, const Node& node) {
|
| 178 |
+
stream << node.ToString();
|
| 179 |
+
return stream;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
// Note: Keep this version of NodeCast for smooth PyTorch/XLA migration, and
|
| 183 |
+
// clean up once the migration is done.
|
| 184 |
+
template <typename T>
|
| 185 |
+
const T* NodeCast(const Node* node, OpKind op) {
|
| 186 |
+
if (op != node->op()) {
|
| 187 |
+
return nullptr;
|
| 188 |
+
}
|
| 189 |
+
#ifdef NDEBUG
|
| 190 |
+
return static_cast<const T*>(node);
|
| 191 |
+
#else
|
| 192 |
+
return &dynamic_cast<const T&>(*node);
|
| 193 |
+
#endif
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
template <typename T>
|
| 197 |
+
const T* NodeCast(const Node* node) {
|
| 198 |
+
if (T::ClassOpKind() != node->op()) {
|
| 199 |
+
return nullptr;
|
| 200 |
+
}
|
| 201 |
+
// TODO: Some IR classes share the same opkind, such as Mean and MeanDim, so
|
| 202 |
+
// static_cast is not safe here. Unless we have opkind unique for each class,
|
| 203 |
+
// we have to use dynamic_cast here.
|
| 204 |
+
return dynamic_cast<const T*>(node);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
// Represents a specific output produced by a node. Since the output of a node
|
| 208 |
+
// can be composed by multiple outputs, the node+index coordinates fully qualify
|
| 209 |
+
// each single output.
|
| 210 |
+
struct TORCH_API Output {
|
| 211 |
+
struct Hasher {
|
| 212 |
+
size_t operator()(const Output& output) const;
|
| 213 |
+
};
|
| 214 |
+
|
| 215 |
+
Output() = default;
|
| 216 |
+
explicit Output(const Node* node, size_t index = 0)
|
| 217 |
+
: node(node), index(index) {}
|
| 218 |
+
|
| 219 |
+
hash_t hash() const;
|
| 220 |
+
hash_t shapeHash() const;
|
| 221 |
+
|
| 222 |
+
bool operator==(const Output& rhs) const {
|
| 223 |
+
return node == rhs.node && index == rhs.index;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
// To compare the operands of to-be-constructed node and to-be-reused node
|
| 227 |
+
bool operator==(const Value& rhs) const;
|
| 228 |
+
|
| 229 |
+
bool operator!=(const Output& rhs) const {
|
| 230 |
+
return !operator==(rhs);
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
const Shape& shape() const {
|
| 234 |
+
return node->shape(index);
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
std::string ToString() const;
|
| 238 |
+
|
| 239 |
+
// The node providing the output.
|
| 240 |
+
const Node* node{nullptr};
|
| 241 |
+
// The index in the node's output this output refers to.
|
| 242 |
+
size_t index{0};
|
| 243 |
+
};
|
| 244 |
+
|
| 245 |
+
inline std::ostream& operator<<(std::ostream& stream, const Output& output) {
|
| 246 |
+
stream << output.ToString();
|
| 247 |
+
return stream;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
template <typename T>
|
| 251 |
+
using OutputMap = std::unordered_map<Output, T, Output::Hasher>;
|
| 252 |
+
|
| 253 |
+
// Represents an input/operand for a Node object.
|
| 254 |
+
struct TORCH_API Value {
|
| 255 |
+
Value() = default;
|
| 256 |
+
/* implicit */ Value(NodePtr&& node, size_t index = 0)
|
| 257 |
+
: node(std::move(node)), index(index) {}
|
| 258 |
+
/* implicit */ Value(const NodePtr& node, size_t index = 0)
|
| 259 |
+
: node(node), index(index) {}
|
| 260 |
+
|
| 261 |
+
hash_t hash() const;
|
| 262 |
+
hash_t shapeHash() const;
|
| 263 |
+
|
| 264 |
+
operator bool() const {
|
| 265 |
+
return node != nullptr;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
operator Output() const {
|
| 269 |
+
return Output(node.get(), index);
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
const Shape& shape() const {
|
| 273 |
+
return node->shape(index);
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
Node* operator->() const {
|
| 277 |
+
return node.get();
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
NodePtr node;
|
| 281 |
+
size_t index = 0;
|
| 282 |
+
};
|
| 283 |
+
|
| 284 |
+
} // namespace torch::lazy
|
| 285 |
+
|
| 286 |
+
namespace c10 {
|
| 287 |
+
// Explicit template instantiation to make ArrayRef<Value> work
|
| 288 |
+
template class at::ArrayRef<torch::lazy::Value>;
|
| 289 |
+
} // namespace c10
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ir_builder.h
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/core/ScalarType.h>
|
| 4 |
+
#include <torch/csrc/lazy/backend/backend_interface.h>
|
| 5 |
+
#include <torch/csrc/lazy/core/config.h>
|
| 6 |
+
#include <torch/csrc/lazy/core/ir.h>
|
| 7 |
+
#include <torch/csrc/lazy/core/tensor.h>
|
| 8 |
+
#include <torch/csrc/lazy/core/trie.h>
|
| 9 |
+
#include <optional>
|
| 10 |
+
#include <vector>
|
| 11 |
+
|
| 12 |
+
// This file is part of the backend interface. So, ops shouldn't be added or
|
| 13 |
+
// removed without due process The exception to this being the view ops which
|
| 14 |
+
// will be removed soon pending functionalization
|
| 15 |
+
|
| 16 |
+
namespace torch::lazy {
|
| 17 |
+
|
| 18 |
+
template <typename T, typename... Args>
|
| 19 |
+
NodePtr ReuseNode(Args&&... args) {
|
| 20 |
+
if (FLAGS_torch_lazy_reuse_ir) {
|
| 21 |
+
return LookupNodeFromTrieCache<T>(std::forward<Args>(args)...);
|
| 22 |
+
}
|
| 23 |
+
return nullptr;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
// Caching an IR node into TrieCache
|
| 27 |
+
static inline void CacheNode(NodePtr node) {
|
| 28 |
+
if (FLAGS_torch_lazy_reuse_ir) {
|
| 29 |
+
TrieCache::Get()->Insert(std::move(node));
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
template <typename T, typename... Args>
|
| 34 |
+
NodePtr MakeNode(Args&&... args) {
|
| 35 |
+
return std::make_shared<T>(std::forward<Args>(args)...);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
// op is passed in for a more efficient node casting, see the implementation of
|
| 39 |
+
// NodeCast
|
| 40 |
+
template <typename T, typename... Args>
|
| 41 |
+
NodePtr ReuseOrMakeNode(Args&&... args) {
|
| 42 |
+
NodePtr node = ReuseNode<T>(std::forward<Args>(args)...);
|
| 43 |
+
if (!node) {
|
| 44 |
+
node = MakeNode<T>(std::forward<Args>(args)...);
|
| 45 |
+
CacheNode(node);
|
| 46 |
+
}
|
| 47 |
+
return node;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
struct IrBuilder {
|
| 51 |
+
virtual NodePtr MakeDeviceData(
|
| 52 |
+
const std::shared_ptr<BackendData>& data) const = 0;
|
| 53 |
+
virtual NodePtr MakeScalar(
|
| 54 |
+
const at::Scalar& value,
|
| 55 |
+
const at::ScalarType& type) const = 0;
|
| 56 |
+
virtual NodePtr MakeExpand(
|
| 57 |
+
const Value& input0,
|
| 58 |
+
const std::vector<int64_t>& size,
|
| 59 |
+
const bool& is_scalar_expand) const = 0;
|
| 60 |
+
virtual NodePtr MakeCast(
|
| 61 |
+
const Value& input0,
|
| 62 |
+
const at::ScalarType& dtype,
|
| 63 |
+
const std::optional<at::ScalarType>& stype = std::nullopt) const = 0;
|
| 64 |
+
virtual NodePtr MakeTensorList(const OpList& inputs) const = 0;
|
| 65 |
+
virtual NodePtr MakeGeneric(
|
| 66 |
+
const OpKind& op,
|
| 67 |
+
const OpList& operands,
|
| 68 |
+
const Shape& shape,
|
| 69 |
+
const size_t& num_outputs = 1,
|
| 70 |
+
const hash_t& hash_seed = static_cast<uint32_t>(0x5a2d296e9)) const = 0;
|
| 71 |
+
|
| 72 |
+
// dynamic ir nodes
|
| 73 |
+
virtual NodePtr MakeSizeNode(const Value& input, size_t dim) const = 0;
|
| 74 |
+
virtual NodePtr MakeSizeAdd(const Value& a, const Value& b) const = 0;
|
| 75 |
+
virtual NodePtr MakeSizeMul(const Value& a, const Value& b) const = 0;
|
| 76 |
+
virtual NodePtr MakeSizeDiv(const Value& a, const Value& b) const = 0;
|
| 77 |
+
|
| 78 |
+
virtual ~IrBuilder() = default;
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
static inline NodePtr MakeDeviceData(const std::shared_ptr<BackendData>& data) {
|
| 82 |
+
return getIrBuilder()->MakeDeviceData(data);
|
| 83 |
+
}
|
| 84 |
+
static inline NodePtr MakeScalar(
|
| 85 |
+
const at::Scalar& value,
|
| 86 |
+
const at::ScalarType& type) {
|
| 87 |
+
return getIrBuilder()->MakeScalar(value, type);
|
| 88 |
+
}
|
| 89 |
+
static inline NodePtr MakeExpand(
|
| 90 |
+
const Value& input0,
|
| 91 |
+
const std::vector<int64_t>& size,
|
| 92 |
+
const bool& is_scalar_expand) {
|
| 93 |
+
return getIrBuilder()->MakeExpand(input0, size, is_scalar_expand);
|
| 94 |
+
}
|
| 95 |
+
static inline NodePtr MakeCast(
|
| 96 |
+
const Value& input0,
|
| 97 |
+
const at::ScalarType& dtype,
|
| 98 |
+
const std::optional<at::ScalarType>& stype = std::nullopt) {
|
| 99 |
+
return getIrBuilder()->MakeCast(input0, dtype, stype);
|
| 100 |
+
}
|
| 101 |
+
static inline NodePtr MakeTensorList(const OpList& inputs) {
|
| 102 |
+
return getIrBuilder()->MakeTensorList(inputs);
|
| 103 |
+
}
|
| 104 |
+
static inline NodePtr MakeGeneric(
|
| 105 |
+
const OpKind& op,
|
| 106 |
+
const OpList& operands,
|
| 107 |
+
const Shape& shape,
|
| 108 |
+
const size_t& num_outputs = 1,
|
| 109 |
+
const hash_t& hash_seed = static_cast<uint32_t>(0x5a2d296e9)) {
|
| 110 |
+
return getIrBuilder()->MakeGeneric(
|
| 111 |
+
op, operands, shape, num_outputs, hash_seed);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// dynamic ir nodes
|
| 115 |
+
static inline NodePtr MakeSizeNode(const Value& input, size_t dim) {
|
| 116 |
+
return getIrBuilder()->MakeSizeNode(input, dim);
|
| 117 |
+
}
|
| 118 |
+
static inline NodePtr MakeSizeAdd(const Value& a, const Value& b) {
|
| 119 |
+
return getIrBuilder()->MakeSizeAdd(a, b);
|
| 120 |
+
}
|
| 121 |
+
static inline NodePtr MakeSizeMul(const Value& a, const Value& b) {
|
| 122 |
+
return getIrBuilder()->MakeSizeAdd(a, b);
|
| 123 |
+
}
|
| 124 |
+
static inline NodePtr MakeSizeDiv(const Value& a, const Value& b) {
|
| 125 |
+
return getIrBuilder()->MakeSizeDiv(a, b);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
inline Value GetSymIntValue(const c10::SymInt& a) {
|
| 129 |
+
if (auto ma = a.maybe_as_int()) {
|
| 130 |
+
return Value(MakeScalar(*ma, at::kLong), 0);
|
| 131 |
+
} else {
|
| 132 |
+
return Value(
|
| 133 |
+
dynamic_cast<torch::lazy::SymNodeImpl*>(a.toSymNodeImplUnowned())
|
| 134 |
+
->node_,
|
| 135 |
+
0);
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
// TODO: this should return Value
|
| 140 |
+
inline std::vector<int64_t> GetSymIntArrayRefValue(c10::SymIntArrayRef arr) {
|
| 141 |
+
std::vector<int64_t> r;
|
| 142 |
+
for (const auto& a : arr) {
|
| 143 |
+
r.emplace_back(a.guard_int(__FILE__, __LINE__));
|
| 144 |
+
}
|
| 145 |
+
return r;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ir_dump_util.h
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/lazy/core/ir.h>
|
| 4 |
+
|
| 5 |
+
#include <string>
|
| 6 |
+
|
| 7 |
+
namespace torch::lazy {
|
| 8 |
+
|
| 9 |
+
class BackendDevice;
|
| 10 |
+
|
| 11 |
+
class TORCH_API DumpUtil {
|
| 12 |
+
public:
|
| 13 |
+
static std::string ToDot(c10::ArrayRef<const Node*> nodes);
|
| 14 |
+
|
| 15 |
+
static std::string PostOrderToDot(
|
| 16 |
+
c10::ArrayRef<const Node*> post_order,
|
| 17 |
+
c10::ArrayRef<const Node*> roots);
|
| 18 |
+
|
| 19 |
+
static std::string ToText(c10::ArrayRef<const Node*> nodes);
|
| 20 |
+
|
| 21 |
+
static std::string PostOrderToText(
|
| 22 |
+
c10::ArrayRef<const Node*> post_order,
|
| 23 |
+
c10::ArrayRef<const Node*> roots);
|
| 24 |
+
|
| 25 |
+
static std::string ToBackend(
|
| 26 |
+
c10::ArrayRef<Value> values,
|
| 27 |
+
const BackendDevice& device);
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ir_metadata.h
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/macros/Macros.h>
|
| 4 |
+
|
| 5 |
+
#include <string>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
namespace torch::lazy {
|
| 9 |
+
struct SourceLocation {
|
| 10 |
+
std::string file;
|
| 11 |
+
std::string function;
|
| 12 |
+
int line = -1;
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
TORCH_API void EmitShortFrameInfo(
|
| 16 |
+
std::ostream& stream,
|
| 17 |
+
const std::vector<SourceLocation>& frames);
|
| 18 |
+
|
| 19 |
+
TORCH_API std::ostream& operator<<(
|
| 20 |
+
std::ostream& stream,
|
| 21 |
+
const std::vector<SourceLocation>& frames);
|
| 22 |
+
|
| 23 |
+
// The base class for user defined metadata which is possible to attach to IR
|
| 24 |
+
// nodes.
|
| 25 |
+
struct TORCH_API UserMetaData {
|
| 26 |
+
virtual ~UserMetaData() = default;
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
struct TORCH_API MetaData {
|
| 30 |
+
std::string scope;
|
| 31 |
+
std::vector<SourceLocation> frame_info;
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
// TODO(whc) is this going to be used outside of in IR decompositions?
|
| 35 |
+
// RAII data structure to be used a stack variable to enter a new IR scope. IR
|
| 36 |
+
// scope names will appear in the IR and will help identifying the source of the
|
| 37 |
+
// single IR nodes.
|
| 38 |
+
struct TORCH_API ScopePusher {
|
| 39 |
+
explicit ScopePusher(const std::string& name);
|
| 40 |
+
~ScopePusher();
|
| 41 |
+
ScopePusher(ScopePusher&& other) = delete;
|
| 42 |
+
ScopePusher(const ScopePusher&) = delete;
|
| 43 |
+
ScopePusher& operator=(const ScopePusher&) = delete;
|
| 44 |
+
ScopePusher& operator=(ScopePusher&&) = delete;
|
| 45 |
+
|
| 46 |
+
static void ResetScopes();
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
TORCH_API MetaData GetMetaDataIfDebugging();
|
| 50 |
+
|
| 51 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ir_util.h
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <unordered_map>
|
| 4 |
+
#include <vector>
|
| 5 |
+
|
| 6 |
+
#include <torch/csrc/lazy/core/ir.h>
|
| 7 |
+
|
| 8 |
+
namespace torch::lazy {
|
| 9 |
+
|
| 10 |
+
class TORCH_API Util {
|
| 11 |
+
public:
|
| 12 |
+
// Tracks the emission status of the nodes during the post-order generation.
|
| 13 |
+
// It helps tracking loops within the computation graphs.
|
| 14 |
+
enum EmitStatus {
|
| 15 |
+
kNotEmitted,
|
| 16 |
+
kEmitting,
|
| 17 |
+
kEmitted,
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
using EmissionMap = std::unordered_map<const Node*, EmitStatus>;
|
| 21 |
+
|
| 22 |
+
// Computes the post order from the given node, without using recursion. The
|
| 23 |
+
// emission map can be used as saved state, for multiple separate calls to
|
| 24 |
+
// this API. The returned post-order can be empty if the node has already been
|
| 25 |
+
// emitted inside the emission map. An error is generated if a loop is
|
| 26 |
+
// detected.
|
| 27 |
+
static std::vector<const Node*> ComputePostOrder(
|
| 28 |
+
const Node* node,
|
| 29 |
+
EmissionMap* emap);
|
| 30 |
+
|
| 31 |
+
static std::vector<const Node*> ComputePostOrder(
|
| 32 |
+
c10::ArrayRef<const Node*> nodes,
|
| 33 |
+
EmissionMap* emap);
|
| 34 |
+
|
| 35 |
+
// Same as above, but computes the post order on the set of nodes specified as
|
| 36 |
+
// argument.
|
| 37 |
+
static std::vector<const Node*> ComputePostOrder(
|
| 38 |
+
c10::ArrayRef<const Node*> nodes);
|
| 39 |
+
|
| 40 |
+
// Retrieves the number of nodes within the graph whose sink are passed in the
|
| 41 |
+
// nodes argument.
|
| 42 |
+
static size_t GetGraphSize(c10::ArrayRef<const Node*> nodes);
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/lazy_graph_executor.h
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/util/ArrayRef.h>
|
| 4 |
+
#include <torch/csrc/lazy/backend/lowering_context.h>
|
| 5 |
+
#include <torch/csrc/lazy/core/cache.h>
|
| 6 |
+
#include <torch/csrc/lazy/core/ir_util.h>
|
| 7 |
+
#include <torch/csrc/lazy/core/multi_wait.h>
|
| 8 |
+
#include <torch/csrc/lazy/core/tensor.h>
|
| 9 |
+
#include <torch/csrc/lazy/core/util.h>
|
| 10 |
+
|
| 11 |
+
namespace torch::lazy {
|
| 12 |
+
|
| 13 |
+
class TORCH_API LazyGraphExecutor {
|
| 14 |
+
public:
|
| 15 |
+
struct DeviceDataInfo : public BackendData::Info {
|
| 16 |
+
DeviceDataInfo(int64_t tensor_id, bool read_only)
|
| 17 |
+
: tensor_id(tensor_id), read_only(read_only) {}
|
| 18 |
+
|
| 19 |
+
int64_t tensor_id = 0;
|
| 20 |
+
bool read_only = false;
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
// Register a lazy graph executor instance that can be retrieved using Get()
|
| 24 |
+
static void Register(LazyGraphExecutor*);
|
| 25 |
+
static LazyGraphExecutor* Get();
|
| 26 |
+
|
| 27 |
+
virtual ~LazyGraphExecutor() = default;
|
| 28 |
+
|
| 29 |
+
// Override these methods to perform custom tensor registration and
|
| 30 |
+
// unregistration Note: It is vital that the parent implementations are also
|
| 31 |
+
// called in order for the tensors to show up in the live tensor list
|
| 32 |
+
virtual void RegisterTensor(std::shared_ptr<LazyTensor::Data> data);
|
| 33 |
+
virtual void UnregisterTensor(LazyTensor::Data* data);
|
| 34 |
+
|
| 35 |
+
// Seed for random generator.
|
| 36 |
+
// Override to supply your own DeviceContextArena.
|
| 37 |
+
virtual Value GetRngSeed(const BackendDevice& device);
|
| 38 |
+
virtual uint64_t GetRunningSeed(const BackendDevice& device);
|
| 39 |
+
virtual void SetRngSeed(const BackendDevice& device, uint64_t seed);
|
| 40 |
+
|
| 41 |
+
void DeviceBarrier(const BackendDevice& device);
|
| 42 |
+
|
| 43 |
+
BackendDataPtr GetDeviceData(
|
| 44 |
+
const at::Tensor& tensor,
|
| 45 |
+
const BackendDevice& device);
|
| 46 |
+
|
| 47 |
+
BackendDataPtr GetDeviceData(
|
| 48 |
+
const at::Scalar& value,
|
| 49 |
+
at::ScalarType scalar_type,
|
| 50 |
+
const BackendDevice& device);
|
| 51 |
+
|
| 52 |
+
// Retrieves the set of lazy tensors which are currently live in the system,
|
| 53 |
+
// for the given device. If device is nullptr, the live tensors for all
|
| 54 |
+
// devices will be returned. Returned tensors are sorted by device as primary
|
| 55 |
+
// key, and by unique ID as secondary key.
|
| 56 |
+
std::vector<LazyTensorPtr> GetLiveTensors(const BackendDevice* device);
|
| 57 |
+
|
| 58 |
+
// Makes sure that any outstanding IR operation accumulated over live tensors,
|
| 59 |
+
// gets turned into device data. If wait is true, the sync operation will be
|
| 60 |
+
// run synchronously. The devices argument, if not empty, tells the devices
|
| 61 |
+
// which should be partecipating into the replicated computation.
|
| 62 |
+
virtual void SyncLiveTensorsGraph(
|
| 63 |
+
const BackendDevice* device,
|
| 64 |
+
c10::ArrayRef<std::string> devices,
|
| 65 |
+
bool wait);
|
| 66 |
+
|
| 67 |
+
// Applies all the pending IR operations queued over the input tensors. All
|
| 68 |
+
// the tensors must be on the same device. If wait is true, the sync operation
|
| 69 |
+
// will be run synchronously. The devices argument, if not empty, tells the
|
| 70 |
+
// devices which should be partecipating into the replicated computation.
|
| 71 |
+
void SyncTensorsGraph(
|
| 72 |
+
std::vector<LazyTensorPtr>* tensors,
|
| 73 |
+
c10::ArrayRef<std::string> devices,
|
| 74 |
+
bool wait,
|
| 75 |
+
bool sync_ltc_data);
|
| 76 |
+
|
| 77 |
+
// Marks an execution step, which allows the tensor framework to understand
|
| 78 |
+
// the computation boundaries.
|
| 79 |
+
// Override to supply your own DeviceContextArena.
|
| 80 |
+
virtual void MarkStep(const BackendDevice& device);
|
| 81 |
+
|
| 82 |
+
// Waits for all the outstanding operations on all the supplied devices.
|
| 83 |
+
// If devices is empty, the wait will happen for all local devices.
|
| 84 |
+
void WaitDeviceOps(c10::ArrayRef<BackendDevice> devices);
|
| 85 |
+
|
| 86 |
+
// Retrieves the PyTorch CPU tensors behind the lazy tensors IR operations.
|
| 87 |
+
// All the tensors must be on the same device.
|
| 88 |
+
std::vector<at::Tensor> GetTensors(std::vector<LazyTensorPtr>* tensors);
|
| 89 |
+
|
| 90 |
+
size_t IncTrimCounter() const;
|
| 91 |
+
|
| 92 |
+
// Dumps the backend specific text of the computation accumulated in the graph
|
| 93 |
+
// which is attached the tensors.
|
| 94 |
+
std::string DumpBackendComputation(const std::vector<LazyTensorPtr>& tensors);
|
| 95 |
+
|
| 96 |
+
Value GetDeviceDataIrValue(
|
| 97 |
+
const at::Scalar& value,
|
| 98 |
+
c10::ScalarType type,
|
| 99 |
+
const BackendDevice& device);
|
| 100 |
+
Value GetIrValueForScalar(
|
| 101 |
+
const at::Scalar& value,
|
| 102 |
+
c10::ScalarType type,
|
| 103 |
+
const BackendDevice& device);
|
| 104 |
+
Value GetIrValueForScalar(
|
| 105 |
+
const at::Scalar& value,
|
| 106 |
+
const BackendDevice& device);
|
| 107 |
+
|
| 108 |
+
// TODO: even though this API is currently used **only** in codegen to
|
| 109 |
+
// generate real scalar IR values vs scalar tensors, we would like to
|
| 110 |
+
// use it in other cases where `GetIrValueForXXXScalar` is used, as well
|
| 111 |
+
// In order to do that, we need to untangle the cases where we don't need
|
| 112 |
+
// `expand` and where we don't expect a scalar tensor
|
| 113 |
+
Value GetIrValueForScalarFromCodegen(
|
| 114 |
+
const at::Scalar& value,
|
| 115 |
+
const BackendDevice& device);
|
| 116 |
+
Value GetIrValueForExpandedScalar(
|
| 117 |
+
const at::Scalar& value,
|
| 118 |
+
const Shape& shape,
|
| 119 |
+
const BackendDevice& device);
|
| 120 |
+
|
| 121 |
+
struct CachedComputation {
|
| 122 |
+
explicit CachedComputation(ComputationPtr computation)
|
| 123 |
+
: computation(std::move(computation)) {}
|
| 124 |
+
|
| 125 |
+
ComputationPtr computation;
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
using ComputationCache = Cache<hash_t, CachedComputation, HashReducer>;
|
| 129 |
+
|
| 130 |
+
ComputationCache* GetComputationCache();
|
| 131 |
+
|
| 132 |
+
hash_t GetGraphHash(const std::vector<LazyTensorPtr>& tensors);
|
| 133 |
+
|
| 134 |
+
// Clear the computation cache.
|
| 135 |
+
void ClearComputationCache();
|
| 136 |
+
// Remove a specific computation cache entry from its hash.
|
| 137 |
+
void RemoveFromComputationCache(const hash_t& hash);
|
| 138 |
+
|
| 139 |
+
protected:
|
| 140 |
+
// TODO(alanwaketan): Revisit if all of them need to be accessible to
|
| 141 |
+
// derived classes.
|
| 142 |
+
|
| 143 |
+
struct SyncTensorsConfig {
|
| 144 |
+
// Whether we want to force data on the target tensors (hence trimming
|
| 145 |
+
// the IR graph above them).
|
| 146 |
+
bool force_ltc_data = true;
|
| 147 |
+
// Whether when setting the data, the other properties of the tensor
|
| 148 |
+
// state should be reset.
|
| 149 |
+
bool sync_ltc_data = true;
|
| 150 |
+
};
|
| 151 |
+
|
| 152 |
+
struct SyncTensorCollection {
|
| 153 |
+
SyncTensorCollection() : hash(0) {}
|
| 154 |
+
|
| 155 |
+
SyncTensorsConfig config;
|
| 156 |
+
std::vector<size_t> indices;
|
| 157 |
+
hash_t hash;
|
| 158 |
+
std::vector<ExceptionCleanup> unlocker;
|
| 159 |
+
BackendDevice device;
|
| 160 |
+
};
|
| 161 |
+
|
| 162 |
+
struct PostOrderData {
|
| 163 |
+
std::vector<const Node*> post_order;
|
| 164 |
+
Util::EmissionMap emission_map;
|
| 165 |
+
std::vector<BackendDataPtr> parameters_data;
|
| 166 |
+
std::vector<size_t> parameter_sequence;
|
| 167 |
+
};
|
| 168 |
+
|
| 169 |
+
// Locking:
|
| 170 |
+
// We perform two kinds of operations of tensors, synchronous and
|
| 171 |
+
// asynchronous. The ApplyPendingGraph() are synchronous, as we need the
|
| 172 |
+
// device data result immediately. Before the synchronous operations can
|
| 173 |
+
// start, they need to wait that the pending asynchronous operations have
|
| 174 |
+
// completed. Synchronous operations do not hold device locks, since they are
|
| 175 |
+
// strictly sequential, dictated by the PyTorch execution order. The
|
| 176 |
+
// SyncTensorsGraph() is asynchronous, and returns immediately after having
|
| 177 |
+
// scheduled the asynchronous operation. While executing, the asynchronous
|
| 178 |
+
// operations will hold locks on all the participating devices (in most common
|
| 179 |
+
// cases there will be only one device).
|
| 180 |
+
// Since asynchronous operations capture device locks, only one asynchronous
|
| 181 |
+
// operation can execute at the same time, on a given device. Tensor
|
| 182 |
+
// operations which send data to device do not need to hold any device locks
|
| 183 |
+
// while doing so. Only operations which _use_ device data (computations, and
|
| 184 |
+
// transfer from server) need to wait for asynchronous operations to complete
|
| 185 |
+
// (barrier).
|
| 186 |
+
|
| 187 |
+
class DeviceLocker {
|
| 188 |
+
public:
|
| 189 |
+
explicit DeviceLocker(BackendDevice device) : device_(std::move(device)) {}
|
| 190 |
+
|
| 191 |
+
const BackendDevice& device() const {
|
| 192 |
+
return device_;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
void Lock();
|
| 196 |
+
void Unlock(std::exception_ptr exptr);
|
| 197 |
+
void Barrier();
|
| 198 |
+
|
| 199 |
+
private:
|
| 200 |
+
void CheckResetException();
|
| 201 |
+
|
| 202 |
+
BackendDevice device_;
|
| 203 |
+
std::mutex mutex_;
|
| 204 |
+
std::condition_variable cv_;
|
| 205 |
+
bool locked_ = false;
|
| 206 |
+
std::exception_ptr exptr_;
|
| 207 |
+
};
|
| 208 |
+
|
| 209 |
+
class DeviceLockerArena {
|
| 210 |
+
public:
|
| 211 |
+
static DeviceLockerArena* Get();
|
| 212 |
+
|
| 213 |
+
std::shared_ptr<DeviceLocker> GetLocker(const BackendDevice& device);
|
| 214 |
+
|
| 215 |
+
void DeviceBarrier(const BackendDevice& device);
|
| 216 |
+
|
| 217 |
+
// Use a set to impose an order on the device locking sequence (ABBA
|
| 218 |
+
// prevention).
|
| 219 |
+
std::vector<ExceptionCleanup> LockDevices(
|
| 220 |
+
const std::set<BackendDevice>& devices);
|
| 221 |
+
|
| 222 |
+
private:
|
| 223 |
+
ExceptionCleanup LockDevice(const BackendDevice& device);
|
| 224 |
+
|
| 225 |
+
std::mutex mutex_;
|
| 226 |
+
std::map<BackendDevice, std::shared_ptr<DeviceLocker>> lockers_;
|
| 227 |
+
};
|
| 228 |
+
|
| 229 |
+
class DataCacheArena {
|
| 230 |
+
public:
|
| 231 |
+
static DataCacheArena* Get();
|
| 232 |
+
|
| 233 |
+
BackendDataPtr GetDeviceData(
|
| 234 |
+
const at::Tensor& tensor,
|
| 235 |
+
const BackendDevice& device);
|
| 236 |
+
|
| 237 |
+
BackendDataPtr GetDeviceData(
|
| 238 |
+
const at::Scalar& value,
|
| 239 |
+
at::ScalarType scalar_type,
|
| 240 |
+
const BackendDevice& device);
|
| 241 |
+
|
| 242 |
+
private:
|
| 243 |
+
struct TensorHasher {
|
| 244 |
+
size_t operator()(const at::Tensor& tensor) const;
|
| 245 |
+
};
|
| 246 |
+
struct TensorComparer {
|
| 247 |
+
bool operator()(const at::Tensor& tensor1, const at::Tensor& tensor2)
|
| 248 |
+
const;
|
| 249 |
+
};
|
| 250 |
+
|
| 251 |
+
explicit DataCacheArena(size_t max_cache_size);
|
| 252 |
+
|
| 253 |
+
using DataCache =
|
| 254 |
+
Cache<at::Tensor, BackendData, TensorHasher, TensorComparer>;
|
| 255 |
+
|
| 256 |
+
DataCache* GetDataCache(const BackendDevice& device);
|
| 257 |
+
|
| 258 |
+
size_t max_cache_size_ = 0;
|
| 259 |
+
std::mutex mutex_;
|
| 260 |
+
std::map<BackendDevice, std::unique_ptr<DataCache>> device_caches_;
|
| 261 |
+
};
|
| 262 |
+
|
| 263 |
+
// The DeviceContextArena holds per device live information and statistics,
|
| 264 |
+
// among which the lazy tensors which are currently alive in the system. This
|
| 265 |
+
// is used to create computation "barriers" in order to flush pending
|
| 266 |
+
// operations and ensure the same computations are created during the training
|
| 267 |
+
// loops.
|
| 268 |
+
// TODO(alanwaketan): Add a registry such that we don't need to make all
|
| 269 |
+
// related methods virtual.
|
| 270 |
+
class DeviceContextArena {
|
| 271 |
+
protected:
|
| 272 |
+
struct DeviceContext {
|
| 273 |
+
std::mutex lock;
|
| 274 |
+
std::map<int64_t, std::weak_ptr<LazyTensor::Data>> tensors_data;
|
| 275 |
+
uint64_t seed = 101;
|
| 276 |
+
uint64_t running_seed = 101;
|
| 277 |
+
Value seed_ir_value;
|
| 278 |
+
};
|
| 279 |
+
|
| 280 |
+
public:
|
| 281 |
+
static DeviceContextArena* Get();
|
| 282 |
+
virtual ~DeviceContextArena() = default;
|
| 283 |
+
|
| 284 |
+
void RegisterTensor(std::shared_ptr<LazyTensor::Data> data);
|
| 285 |
+
void UnregisterTensor(LazyTensor::Data* data);
|
| 286 |
+
|
| 287 |
+
std::vector<LazyTensorPtr> GetLiveTensors(const BackendDevice* device);
|
| 288 |
+
|
| 289 |
+
// Overriding it allow derived class to use their own IRs for Value.
|
| 290 |
+
virtual Value GetRngSeed(const BackendDevice& device);
|
| 291 |
+
uint64_t GetRunningSeed(const BackendDevice& device);
|
| 292 |
+
void SetRngSeed(const BackendDevice& device, uint64_t seed);
|
| 293 |
+
|
| 294 |
+
void MarkStep(const BackendDevice& device);
|
| 295 |
+
|
| 296 |
+
std::vector<BackendDevice> GetActiveDevices();
|
| 297 |
+
|
| 298 |
+
protected:
|
| 299 |
+
DeviceContext* GetDeviceContext(const BackendDevice& device);
|
| 300 |
+
|
| 301 |
+
void ForAllDeviceContexts(
|
| 302 |
+
const std::function<void(DeviceContext*)>& fn,
|
| 303 |
+
const BackendDevice* device);
|
| 304 |
+
|
| 305 |
+
// Overriding it allow derived class to use their own conversions.
|
| 306 |
+
virtual Value IrValueFromScalar(
|
| 307 |
+
const at::Scalar& value,
|
| 308 |
+
at::ScalarType scalar_type,
|
| 309 |
+
const BackendDevice& device);
|
| 310 |
+
|
| 311 |
+
private:
|
| 312 |
+
std::vector<DeviceContext*> GetAllDeviceContexts();
|
| 313 |
+
|
| 314 |
+
std::mutex lock_;
|
| 315 |
+
std::map<BackendDevice, DeviceContext*> device_contexts_;
|
| 316 |
+
};
|
| 317 |
+
|
| 318 |
+
struct Async {
|
| 319 |
+
Async(
|
| 320 |
+
SyncTensorCollection* coll,
|
| 321 |
+
std::vector<BackendDataPtr> parameters_data,
|
| 322 |
+
std::vector<BackendDataPtr> tensors_data,
|
| 323 |
+
ComputationCache::TypePtr cached_computation);
|
| 324 |
+
virtual ~Async() = default;
|
| 325 |
+
|
| 326 |
+
void Wait();
|
| 327 |
+
|
| 328 |
+
MultiWait mwait;
|
| 329 |
+
std::vector<size_t> indices;
|
| 330 |
+
std::vector<ExceptionCleanup> unlocker;
|
| 331 |
+
std::vector<BackendDataPtr> parameters_data;
|
| 332 |
+
BackendDevice device;
|
| 333 |
+
ComputationCache::TypePtr cached_computation;
|
| 334 |
+
std::vector<BackendDataPtr> tensors_data;
|
| 335 |
+
};
|
| 336 |
+
|
| 337 |
+
void ResetTrimCounter() const;
|
| 338 |
+
|
| 339 |
+
// Waits for this SyncTensorCollection's device barrier and acquire the lock.
|
| 340 |
+
virtual void TensorCollectionBarrier(SyncTensorCollection* coll);
|
| 341 |
+
|
| 342 |
+
// One can override to insert your own profiler.
|
| 343 |
+
virtual PostOrderData RunPostOrder(
|
| 344 |
+
const std::vector<Value>& ir_values,
|
| 345 |
+
SyncTensorCollection* coll);
|
| 346 |
+
|
| 347 |
+
private:
|
| 348 |
+
struct CompilationResult {
|
| 349 |
+
BackendDevice device;
|
| 350 |
+
size_t emitted_nodes = 0;
|
| 351 |
+
ComputationPtr computation;
|
| 352 |
+
std::vector<BackendDataPtr> parameters_data;
|
| 353 |
+
};
|
| 354 |
+
|
| 355 |
+
virtual bool ShouldSyncTensor(const LazyTensorPtr& tensor) const;
|
| 356 |
+
|
| 357 |
+
SyncTensorCollection CollectSyncTensors(
|
| 358 |
+
const std::vector<LazyTensorPtr>& tensors,
|
| 359 |
+
const SyncTensorsConfig& config);
|
| 360 |
+
|
| 361 |
+
std::vector<Value> CollectRoots(
|
| 362 |
+
const std::vector<LazyTensorPtr>& tensors,
|
| 363 |
+
c10::ArrayRef<size_t> indices);
|
| 364 |
+
|
| 365 |
+
std::vector<BackendDataPtr> SetTensorData(
|
| 366 |
+
std::vector<LazyTensorPtr>* tensors,
|
| 367 |
+
const SyncTensorsConfig& config,
|
| 368 |
+
c10::ArrayRef<size_t> indices,
|
| 369 |
+
const std::vector<torch::lazy::BackendDataPtr>& tensor_data_vec);
|
| 370 |
+
|
| 371 |
+
void ExtractIRAndPrepareTensorData(
|
| 372 |
+
std::vector<LazyTensorPtr>* tensors,
|
| 373 |
+
const SyncTensorsConfig& config,
|
| 374 |
+
c10::ArrayRef<size_t> indices,
|
| 375 |
+
std::vector<Value>& ir_values,
|
| 376 |
+
std::vector<BackendDataPtr>& tensor_data_vec);
|
| 377 |
+
|
| 378 |
+
std::shared_ptr<Async> TryRunCachedSync(
|
| 379 |
+
std::vector<LazyTensorPtr>* tensors,
|
| 380 |
+
SyncTensorCollection* coll,
|
| 381 |
+
PostOrderData* po_data,
|
| 382 |
+
const std::vector<BackendDataPtr>& tensor_data_vec);
|
| 383 |
+
|
| 384 |
+
CompilationResult Compile(
|
| 385 |
+
const std::vector<LazyTensorPtr>& tensors,
|
| 386 |
+
c10::ArrayRef<std::string> devices,
|
| 387 |
+
const SyncTensorCollection& coll,
|
| 388 |
+
PostOrderData* po_data,
|
| 389 |
+
const std::vector<Value>& ir_values);
|
| 390 |
+
|
| 391 |
+
ComputationCache::TypePtr LookupCachedCompile(const hash_t& hash);
|
| 392 |
+
|
| 393 |
+
std::shared_ptr<Async> SyncTensorsGraphInternal(
|
| 394 |
+
std::vector<LazyTensorPtr>* tensors,
|
| 395 |
+
c10::ArrayRef<std::string> devices,
|
| 396 |
+
const SyncTensorsConfig& config);
|
| 397 |
+
|
| 398 |
+
// Schedules the execution of a sync tensors operation in background. The
|
| 399 |
+
// asynchronous operation will hold the device locks by capturing the ones
|
| 400 |
+
// present within the coll structure.
|
| 401 |
+
std::shared_ptr<Async> ScheduleSyncTensorsGraph(
|
| 402 |
+
SyncTensorCollection* coll,
|
| 403 |
+
std::vector<BackendDataPtr> parameters_data,
|
| 404 |
+
std::vector<BackendDataPtr> tensors_data,
|
| 405 |
+
ComputationCache::TypePtr cached_computation);
|
| 406 |
+
|
| 407 |
+
std::shared_ptr<Async> ScheduleSyncTensorsGraph(
|
| 408 |
+
std::vector<LazyTensorPtr>* tensors,
|
| 409 |
+
SyncTensorCollection* coll,
|
| 410 |
+
std::vector<BackendDataPtr> parameters_data,
|
| 411 |
+
ComputationCache::TypePtr cached_computation,
|
| 412 |
+
const std::vector<BackendDataPtr>& tensor_data_vec);
|
| 413 |
+
|
| 414 |
+
std::vector<at::Tensor> GetTensorsFused(std::vector<LazyTensorPtr>* tensors);
|
| 415 |
+
|
| 416 |
+
std::vector<at::Tensor> FetchTensors(
|
| 417 |
+
std::vector<LazyTensorPtr>* tensors,
|
| 418 |
+
c10::ArrayRef<BackendDataPtr> tensors_data,
|
| 419 |
+
const std::vector<size_t>* indices);
|
| 420 |
+
|
| 421 |
+
// Gathers the device data for all the input tensors, after an
|
| 422 |
+
// asynchronous operation.
|
| 423 |
+
std::vector<BackendDataPtr> GatherTensorsData(
|
| 424 |
+
const std::vector<LazyTensorPtr>& tensors,
|
| 425 |
+
c10::ArrayRef<size_t> indices,
|
| 426 |
+
c10::ArrayRef<BackendDataPtr> tensors_data);
|
| 427 |
+
};
|
| 428 |
+
|
| 429 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/metrics.h
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* This file is adapted from PyTorch/XLA
|
| 3 |
+
* https://github.com/pytorch/xla/blob/e0e5f937a0ba8d904f9608137dc8c51ba439df2d/third_party/xla_client/metrics.h
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
#pragma once
|
| 7 |
+
|
| 8 |
+
#include <atomic>
|
| 9 |
+
#include <functional>
|
| 10 |
+
#include <map>
|
| 11 |
+
#include <memory>
|
| 12 |
+
#include <mutex>
|
| 13 |
+
#include <string>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
#include <c10/macros/Export.h>
|
| 17 |
+
|
| 18 |
+
namespace torch::lazy {
|
| 19 |
+
|
| 20 |
+
struct TORCH_API Sample {
|
| 21 |
+
Sample() = default;
|
| 22 |
+
Sample(int64_t timestamp_ns, double value)
|
| 23 |
+
: timestamp_ns(timestamp_ns), value(value) {}
|
| 24 |
+
|
| 25 |
+
int64_t timestamp_ns = 0;
|
| 26 |
+
double value = 0;
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
using MetricReprFn = std::function<std::string(double)>;
|
| 30 |
+
|
| 31 |
+
// Class used to collect time-stamped numeric samples. The samples are stored in
|
| 32 |
+
// a circular buffer whose size can be configured at constructor time.
|
| 33 |
+
class TORCH_API MetricData {
|
| 34 |
+
public:
|
| 35 |
+
// Creates a new MetricData object with the internal circular buffer storing
|
| 36 |
+
// max_samples samples. The repr_fn argument allow to specify a function which
|
| 37 |
+
// pretty-prints a sample value.
|
| 38 |
+
MetricData(MetricReprFn repr_fn, size_t max_samples);
|
| 39 |
+
|
| 40 |
+
// Returns the total values of all the samples being posted to this metric.
|
| 41 |
+
double Accumulator() const;
|
| 42 |
+
|
| 43 |
+
size_t TotalSamples() const;
|
| 44 |
+
|
| 45 |
+
void AddSample(int64_t timestamp_ns, double value);
|
| 46 |
+
|
| 47 |
+
// Returns a vector with all the current samples, from the oldest to the
|
| 48 |
+
// newer. If accumulator is not nullptr, it will receive the current value of
|
| 49 |
+
// the metrics' accumulator (the sum of all posted values). If total_samples
|
| 50 |
+
// is not nullptr, it will receive the count of the posted values.
|
| 51 |
+
std::vector<Sample> Samples(double* accumulator, size_t* total_samples) const;
|
| 52 |
+
|
| 53 |
+
std::string Repr(double value) const {
|
| 54 |
+
return repr_fn_(value);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void Reset();
|
| 58 |
+
|
| 59 |
+
bool IsValid() const {
|
| 60 |
+
return TotalSamples() > 0;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
private:
|
| 64 |
+
mutable std::mutex lock_;
|
| 65 |
+
MetricReprFn repr_fn_;
|
| 66 |
+
size_t count_ = 0;
|
| 67 |
+
std::vector<Sample> samples_;
|
| 68 |
+
double accumulator_ = 0.0;
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
// Counters are a very lightweight form of metrics which do not need to track
|
| 72 |
+
// sample time.
|
| 73 |
+
class TORCH_API CounterData {
|
| 74 |
+
public:
|
| 75 |
+
CounterData() : value_(0) {}
|
| 76 |
+
|
| 77 |
+
void AddValue(int64_t value) {
|
| 78 |
+
value_ += value;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
int64_t Value() const {
|
| 82 |
+
return value_;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
void Reset() {
|
| 86 |
+
value_ = 0;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
bool IsValid() const {
|
| 90 |
+
return value_ > 0;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
private:
|
| 94 |
+
std::atomic<int64_t> value_;
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
class TORCH_API MetricsArena {
|
| 98 |
+
public:
|
| 99 |
+
static MetricsArena* Get();
|
| 100 |
+
|
| 101 |
+
void ResetCounters();
|
| 102 |
+
void ResetMetrics();
|
| 103 |
+
|
| 104 |
+
// Registers a new metric in the global arena.
|
| 105 |
+
void RegisterMetric(
|
| 106 |
+
const std::string& name,
|
| 107 |
+
MetricReprFn repr_fn,
|
| 108 |
+
size_t max_samples,
|
| 109 |
+
std::shared_ptr<MetricData>* data);
|
| 110 |
+
|
| 111 |
+
void RegisterCounter(
|
| 112 |
+
const std::string& name,
|
| 113 |
+
std::shared_ptr<CounterData>* data);
|
| 114 |
+
|
| 115 |
+
void ForEachMetric(
|
| 116 |
+
const std::function<void(const std::string&, MetricData*)>& metric_func);
|
| 117 |
+
|
| 118 |
+
void ForEachCounter(
|
| 119 |
+
const std::function<void(const std::string&, CounterData*)>&
|
| 120 |
+
counter_func);
|
| 121 |
+
|
| 122 |
+
std::vector<std::string> GetMetricNames();
|
| 123 |
+
|
| 124 |
+
MetricData* GetMetric(const std::string& name);
|
| 125 |
+
|
| 126 |
+
std::vector<std::string> GetCounterNames();
|
| 127 |
+
|
| 128 |
+
CounterData* GetCounter(const std::string& name);
|
| 129 |
+
|
| 130 |
+
private:
|
| 131 |
+
std::mutex lock_;
|
| 132 |
+
std::map<std::string, std::shared_ptr<MetricData>> metrics_;
|
| 133 |
+
std::map<std::string, std::shared_ptr<CounterData>> counters_;
|
| 134 |
+
};
|
| 135 |
+
|
| 136 |
+
// Emits the value in a to_string() conversion.
|
| 137 |
+
TORCH_API std::string MetricFnValue(double value);
|
| 138 |
+
// Emits the value in a humanized bytes representation.
|
| 139 |
+
TORCH_API std::string MetricFnBytes(double value);
|
| 140 |
+
// Emits the value in a humanized time representation. The value is expressed in
|
| 141 |
+
// nanoseconds EPOCH time.
|
| 142 |
+
TORCH_API std::string MetricFnTime(double value);
|
| 143 |
+
|
| 144 |
+
// The typical use of a Metric is one in which it gets created either in a
|
| 145 |
+
// global scope context:
|
| 146 |
+
// static Metric* metric = new Metric("RpcCount");
|
| 147 |
+
// Or within a function scope:
|
| 148 |
+
// void MyFunction(...) {
|
| 149 |
+
// static Metric* metric = new Metric("RpcCount");
|
| 150 |
+
// ...
|
| 151 |
+
// metric->AddSample(ts_nanos, some_value);
|
| 152 |
+
// }
|
| 153 |
+
class TORCH_API Metric {
|
| 154 |
+
public:
|
| 155 |
+
explicit Metric(
|
| 156 |
+
std::string name,
|
| 157 |
+
MetricReprFn repr_fn = MetricFnValue,
|
| 158 |
+
size_t max_samples = 0);
|
| 159 |
+
|
| 160 |
+
const std::string& Name() const {
|
| 161 |
+
return name_;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
double Accumulator() const;
|
| 165 |
+
|
| 166 |
+
void AddSample(int64_t timestamp_ns, double value);
|
| 167 |
+
|
| 168 |
+
void AddSample(double value);
|
| 169 |
+
|
| 170 |
+
std::vector<Sample> Samples(double* accumulator, size_t* total_samples) const;
|
| 171 |
+
|
| 172 |
+
std::string Repr(double value) const;
|
| 173 |
+
|
| 174 |
+
private:
|
| 175 |
+
MetricData* GetData() const;
|
| 176 |
+
|
| 177 |
+
std::string name_;
|
| 178 |
+
MetricReprFn repr_fn_;
|
| 179 |
+
size_t max_samples_;
|
| 180 |
+
mutable std::shared_ptr<MetricData> data_ptr_;
|
| 181 |
+
mutable std::atomic<MetricData*> data_;
|
| 182 |
+
};
|
| 183 |
+
|
| 184 |
+
// A Counter is a lightweight form of metric which tracks an integer value which
|
| 185 |
+
// can increase or decrease.
|
| 186 |
+
// A typical use is as:
|
| 187 |
+
// static Counter* counter = new Counter("MyCounter");
|
| 188 |
+
// ...
|
| 189 |
+
// counter->AddValue(+1);
|
| 190 |
+
class TORCH_API Counter {
|
| 191 |
+
public:
|
| 192 |
+
explicit Counter(std::string name);
|
| 193 |
+
|
| 194 |
+
void AddValue(int64_t value) {
|
| 195 |
+
GetData()->AddValue(value);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
int64_t Value() const {
|
| 199 |
+
return GetData()->Value();
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
private:
|
| 203 |
+
CounterData* GetData() const;
|
| 204 |
+
|
| 205 |
+
std::string name_;
|
| 206 |
+
mutable std::shared_ptr<CounterData> data_ptr_;
|
| 207 |
+
mutable std::atomic<CounterData*> data_;
|
| 208 |
+
};
|
| 209 |
+
|
| 210 |
+
#define TORCH_LAZY_COUNTER(name, value) \
|
| 211 |
+
do { \
|
| 212 |
+
static ::torch::lazy::Counter* __counter = \
|
| 213 |
+
new ::torch::lazy::Counter(name); \
|
| 214 |
+
__counter->AddValue(value); \
|
| 215 |
+
} while (0)
|
| 216 |
+
|
| 217 |
+
#define TORCH_LAZY_FN_COUNTER(ns) TORCH_LAZY_COUNTER(c10::str(ns, __func__), 1)
|
| 218 |
+
|
| 219 |
+
#define TORCH_LAZY_VALUE_METRIC(name, value) \
|
| 220 |
+
do { \
|
| 221 |
+
static ::torch::lazy::Metric* __metric = \
|
| 222 |
+
new ::torch::lazy::Metric(name, torch::lazy::MetricFnValue); \
|
| 223 |
+
__metric->AddSample(value); \
|
| 224 |
+
} while (0)
|
| 225 |
+
|
| 226 |
+
// Creates a report with the current metrics statistics.
|
| 227 |
+
TORCH_API std::string CreateMetricReport();
|
| 228 |
+
|
| 229 |
+
// Creates a report with the selected metrics statistics.
|
| 230 |
+
TORCH_API std::string CreateMetricReport(
|
| 231 |
+
const std::vector<std::string>& counter_names,
|
| 232 |
+
const std::vector<std::string>& metric_names);
|
| 233 |
+
|
| 234 |
+
// Returns the currently registered metric names. Note that the list can grow
|
| 235 |
+
// since metrics are usually function initialized (they are static function
|
| 236 |
+
// variables).
|
| 237 |
+
TORCH_API std::vector<std::string> GetMetricNames();
|
| 238 |
+
|
| 239 |
+
// Retrieves the metric data of a given metric, or nullptr if such metric does
|
| 240 |
+
// not exist.
|
| 241 |
+
TORCH_API MetricData* GetMetric(const std::string& name);
|
| 242 |
+
|
| 243 |
+
// Returns the currently registered counter names. Note that the list can grow
|
| 244 |
+
// since counters are usually function initialized (they are static function
|
| 245 |
+
// variables).
|
| 246 |
+
TORCH_API std::vector<std::string> GetCounterNames();
|
| 247 |
+
|
| 248 |
+
// Retrieves the counter data of a given counter, or nullptr if such counter
|
| 249 |
+
// does not exist.
|
| 250 |
+
TORCH_API CounterData* GetCounter(const std::string& name);
|
| 251 |
+
|
| 252 |
+
// Retrieves the current EPOCH time in nanoseconds.
|
| 253 |
+
TORCH_API int64_t NowNs();
|
| 254 |
+
|
| 255 |
+
// Scope based utility class TORCH_API to measure the time the code takes within
|
| 256 |
+
// a given C++ scope.
|
| 257 |
+
class TORCH_API TimedSection {
|
| 258 |
+
public:
|
| 259 |
+
explicit TimedSection(Metric* metric) : metric_(metric), start_(NowNs()) {}
|
| 260 |
+
|
| 261 |
+
TimedSection(TimedSection&& other) = delete;
|
| 262 |
+
TimedSection(const TimedSection&) = delete;
|
| 263 |
+
TimedSection& operator=(const TimedSection&) = delete;
|
| 264 |
+
TimedSection& operator=(TimedSection&&) = delete;
|
| 265 |
+
~TimedSection() {
|
| 266 |
+
int64_t now = NowNs();
|
| 267 |
+
metric_->AddSample(now, static_cast<double>(now - start_));
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
double Elapsed() const {
|
| 271 |
+
return 1e-9 * static_cast<double>(NowNs() - start_);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
private:
|
| 275 |
+
Metric* metric_;
|
| 276 |
+
int64_t start_;
|
| 277 |
+
};
|
| 278 |
+
|
| 279 |
+
#define TORCH_LAZY_TIMED(name) \
|
| 280 |
+
static torch::lazy::Metric* timed_metric = \
|
| 281 |
+
new torch::lazy::Metric(name, torch::lazy::MetricFnTime); \
|
| 282 |
+
torch::lazy::TimedSection timed_section(timed_metric)
|
| 283 |
+
|
| 284 |
+
#define TORCH_LAZY_FN_COUNTER_TIMED_TRACING(ns) \
|
| 285 |
+
TORCH_LAZY_FN_COUNTER(ns); \
|
| 286 |
+
TORCH_LAZY_TIMED("LazyTracing")
|
| 287 |
+
|
| 288 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/multi_wait.h
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* This file is adapted from PyTorch/XLA
|
| 3 |
+
* https://github.com/pytorch/xla/blob/e0e5f937a0ba8d904f9608137dc8c51ba439df2d/third_party/xla_client/multi_wait.h
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
#pragma once
|
| 7 |
+
|
| 8 |
+
#include <condition_variable>
|
| 9 |
+
#include <exception>
|
| 10 |
+
#include <functional>
|
| 11 |
+
#include <memory>
|
| 12 |
+
#include <mutex>
|
| 13 |
+
|
| 14 |
+
#include <c10/macros/Export.h>
|
| 15 |
+
|
| 16 |
+
namespace torch::lazy {
|
| 17 |
+
|
| 18 |
+
// Support waiting for a number of tasks to complete.
|
| 19 |
+
class TORCH_API MultiWait {
|
| 20 |
+
public:
|
| 21 |
+
explicit MultiWait(size_t count) : count_(count) {}
|
| 22 |
+
|
| 23 |
+
// Signal the completion of a single task.
|
| 24 |
+
void Done();
|
| 25 |
+
|
| 26 |
+
// Waits until at least count (passed as constructor value) completions
|
| 27 |
+
// happened.
|
| 28 |
+
void Wait();
|
| 29 |
+
|
| 30 |
+
// Same as above, but waits up to wait_seconds.
|
| 31 |
+
void Wait(double wait_seconds);
|
| 32 |
+
|
| 33 |
+
// Resets the threshold counter for the MultiWait object. The completed count
|
| 34 |
+
// is also reset to zero.
|
| 35 |
+
void Reset(size_t count);
|
| 36 |
+
|
| 37 |
+
// Creates a completer functor which signals the mult wait object once func
|
| 38 |
+
// has completed. Handles exceptions by signaling the multi wait with the
|
| 39 |
+
// proper status value. This API returns a function which captures a MultiWait
|
| 40 |
+
// reference, so care must be taken such that the reference remains valid for
|
| 41 |
+
// the whole lifetime of the returned function.
|
| 42 |
+
std::function<void()> Completer(std::function<void()> func);
|
| 43 |
+
|
| 44 |
+
// Similar as the above API, but with explicit capture of the MultiWait shared
|
| 45 |
+
// pointer.
|
| 46 |
+
static std::function<void()> Completer(
|
| 47 |
+
std::shared_ptr<MultiWait> mwait,
|
| 48 |
+
std::function<void()> func);
|
| 49 |
+
|
| 50 |
+
private:
|
| 51 |
+
void Complete(const std::function<void()>& func);
|
| 52 |
+
|
| 53 |
+
std::mutex mutex_;
|
| 54 |
+
std::condition_variable cv_;
|
| 55 |
+
size_t count_ = 0;
|
| 56 |
+
size_t completed_count_ = 0;
|
| 57 |
+
std::exception_ptr exptr_;
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ops/arithmetic_ir_ops.h
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/lazy/core/ir.h>
|
| 4 |
+
|
| 5 |
+
namespace torch::lazy {
|
| 6 |
+
|
| 7 |
+
TORCH_API NodePtr operator+(const Value& node1, const Value& node2);
|
| 8 |
+
TORCH_API NodePtr operator-(const Value& node1, const Value& node2);
|
| 9 |
+
TORCH_API NodePtr operator*(const Value& node1, const Value& node2);
|
| 10 |
+
TORCH_API NodePtr operator/(const Value& node1, const Value& node2);
|
| 11 |
+
|
| 12 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/ops/utils.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <vector>
|
| 2 |
+
|
| 3 |
+
#include <torch/csrc/lazy/core/tensor_util.h>
|
| 4 |
+
#include <torch/csrc/lazy/core/util.h>
|
| 5 |
+
|
| 6 |
+
namespace torch::lazy {
|
| 7 |
+
|
| 8 |
+
TORCH_API bool StrideIsSupported(c10::ArrayRef<int64_t> stride);
|
| 9 |
+
|
| 10 |
+
TORCH_API std::vector<int64_t> GetArrayStridePermutation(
|
| 11 |
+
c10::ArrayRef<int64_t> stride);
|
| 12 |
+
|
| 13 |
+
TORCH_API Shape MakeDiagonalShape(
|
| 14 |
+
const Shape& shape,
|
| 15 |
+
int64_t offset,
|
| 16 |
+
int64_t dim1,
|
| 17 |
+
int64_t dim2);
|
| 18 |
+
|
| 19 |
+
TORCH_API Shape
|
| 20 |
+
MakePermuteShape(const Shape& source_shape, c10::ArrayRef<int64_t> permutation);
|
| 21 |
+
|
| 22 |
+
TORCH_API Shape MakeSelectShape(
|
| 23 |
+
const Shape& shape,
|
| 24 |
+
int64_t dim,
|
| 25 |
+
int64_t start,
|
| 26 |
+
int64_t end,
|
| 27 |
+
int64_t stride);
|
| 28 |
+
|
| 29 |
+
TORCH_API int64_t GetStride(int64_t start, int64_t end, int64_t stride);
|
| 30 |
+
|
| 31 |
+
TORCH_API std::vector<int64_t> BuildSqueezedDimensions(
|
| 32 |
+
c10::ArrayRef<int64_t> dimensions,
|
| 33 |
+
int64_t squeeze_dim);
|
| 34 |
+
|
| 35 |
+
TORCH_API std::vector<int64_t> BuildUnsqueezedDimensions(
|
| 36 |
+
c10::ArrayRef<int64_t> dimensions,
|
| 37 |
+
int64_t squeeze_dim);
|
| 38 |
+
|
| 39 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/permutation_util.h
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/util/ArrayRef.h>
|
| 4 |
+
#include <c10/util/Exception.h>
|
| 5 |
+
#include <c10/util/irange.h>
|
| 6 |
+
|
| 7 |
+
#include <vector>
|
| 8 |
+
|
| 9 |
+
namespace torch::lazy {
|
| 10 |
+
|
| 11 |
+
TORCH_API std::vector<int64_t> InversePermutation(
|
| 12 |
+
c10::ArrayRef<int64_t> input_permutation);
|
| 13 |
+
|
| 14 |
+
TORCH_API bool IsPermutation(c10::ArrayRef<int64_t> permutation);
|
| 15 |
+
|
| 16 |
+
// Gathers the input using the order specified by the permutation. For each i,
|
| 17 |
+
// output[i] = dimensions[permutation[i]]. The given permutation must be the
|
| 18 |
+
// same size as the input.
|
| 19 |
+
template <typename Container>
|
| 20 |
+
std::vector<typename Container::value_type> PermuteDimensions(
|
| 21 |
+
c10::ArrayRef<int64_t> permutation,
|
| 22 |
+
const Container& dimensions) {
|
| 23 |
+
using T = typename Container::value_type;
|
| 24 |
+
TORCH_CHECK(
|
| 25 |
+
dimensions.size() == permutation.size(),
|
| 26 |
+
"Invalid permutation specified. dimensions.size() != permutation.size() (",
|
| 27 |
+
dimensions.size(),
|
| 28 |
+
" vs. ",
|
| 29 |
+
permutation.size(),
|
| 30 |
+
")");
|
| 31 |
+
TORCH_CHECK(
|
| 32 |
+
IsPermutation(permutation),
|
| 33 |
+
"Invalid permutation specified. Permutation is not permutation");
|
| 34 |
+
std::vector<T> output(dimensions.size());
|
| 35 |
+
for (const auto i : c10::irange(permutation.size())) {
|
| 36 |
+
output[i] = dimensions[permutation[i]];
|
| 37 |
+
}
|
| 38 |
+
return output;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/shape.h
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ostream>
|
| 4 |
+
#include <vector>
|
| 5 |
+
|
| 6 |
+
#include <c10/core/Scalar.h>
|
| 7 |
+
#include <torch/csrc/jit/passes/symbolic_shape_analysis.h>
|
| 8 |
+
#include <torch/csrc/lazy/core/hash.h>
|
| 9 |
+
|
| 10 |
+
TORCH_DECLARE_bool(ltc_enable_symbolic_shapes);
|
| 11 |
+
|
| 12 |
+
namespace torch::lazy {
|
| 13 |
+
|
| 14 |
+
class TORCH_API Shape {
|
| 15 |
+
public:
|
| 16 |
+
Shape() = default;
|
| 17 |
+
|
| 18 |
+
Shape(
|
| 19 |
+
at::ScalarType scalar_type,
|
| 20 |
+
c10::ArrayRef<int64_t> sizes,
|
| 21 |
+
std::optional<std::vector<bool>> is_symbolic = std::nullopt);
|
| 22 |
+
|
| 23 |
+
std::string to_string() const;
|
| 24 |
+
|
| 25 |
+
c10::ScalarType scalar_type() const {
|
| 26 |
+
return scalar_type_;
|
| 27 |
+
}
|
| 28 |
+
void set_scalar_type(at::ScalarType value) {
|
| 29 |
+
scalar_type_ = value;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
int64_t dim() const {
|
| 33 |
+
return static_cast<int64_t>(sizes_.size());
|
| 34 |
+
}
|
| 35 |
+
c10::ArrayRef<int64_t> sizes() const {
|
| 36 |
+
return sizes_;
|
| 37 |
+
}
|
| 38 |
+
int64_t size(int64_t dim) const {
|
| 39 |
+
return sizes_.at(dim);
|
| 40 |
+
}
|
| 41 |
+
void set_size(int64_t dim, int64_t size) {
|
| 42 |
+
sizes_.at(dim) = size;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
const std::optional<std::vector<bool>>& is_symbolic() const {
|
| 46 |
+
return is_symbolic_;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// Makes a copy with symbolic dims applied
|
| 50 |
+
Shape with_symbolic_dims(
|
| 51 |
+
std::optional<std::vector<bool>> symbolic_dims) const;
|
| 52 |
+
|
| 53 |
+
size_t numel() const;
|
| 54 |
+
hash_t hash(bool bakeInSizes) const;
|
| 55 |
+
|
| 56 |
+
bool operator==(const Shape& other) const;
|
| 57 |
+
|
| 58 |
+
private:
|
| 59 |
+
c10::ScalarType scalar_type_{c10::ScalarType::Undefined};
|
| 60 |
+
|
| 61 |
+
// Sizes are the upper bound sizes for a tensor, used by XLA.
|
| 62 |
+
std::vector<int64_t> sizes_;
|
| 63 |
+
// Stores which dimensions are symbolic
|
| 64 |
+
// If nullopt, either it hasn't been initialized or the symbolic
|
| 65 |
+
// dimensions are not calculable
|
| 66 |
+
std::optional<std::vector<bool>> is_symbolic_ = std::nullopt;
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
TORCH_API std::ostream& operator<<(std::ostream& out, const Shape& shape);
|
| 70 |
+
|
| 71 |
+
TORCH_API bool symbolicShapeEnabled();
|
| 72 |
+
// Calculate and applies symbolic shapes onto the
|
| 73 |
+
// Shape objects passed to result_shapes
|
| 74 |
+
TORCH_API void applySymbolicShapesOnLT(
|
| 75 |
+
const char* schema_str,
|
| 76 |
+
std::vector<c10::IValue> args,
|
| 77 |
+
std::vector<Shape>& result_shapes);
|
| 78 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/shape_inference.h
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/Tensor.h>
|
| 4 |
+
#include <c10/core/ScalarType.h>
|
| 5 |
+
#include <c10/core/SymInt.h>
|
| 6 |
+
#include <c10/core/SymIntArrayRef.h>
|
| 7 |
+
#include <c10/core/SymNodeImpl.h>
|
| 8 |
+
#include <c10/macros/Export.h>
|
| 9 |
+
#include <torch/csrc/lazy/backend/backend_data.h>
|
| 10 |
+
#include <torch/csrc/lazy/core/ir.h>
|
| 11 |
+
#include <torch/csrc/lazy/core/shape.h>
|
| 12 |
+
#include <torch/csrc/lazy/core/tensor.h>
|
| 13 |
+
#include <optional>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
namespace torch::lazy {
|
| 17 |
+
// Turn clang-format off, as we rely on the whole signature being on one line
|
| 18 |
+
// for codegen.
|
| 19 |
+
// clang-format off
|
| 20 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape__adaptive_avg_pool2d(const at::Tensor & self, at::IntArrayRef output_size);
|
| 21 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape__adaptive_avg_pool2d_backward(const at::Tensor & grad_output, const at::Tensor & self);
|
| 22 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape__adaptive_avg_pool3d(const at::Tensor & self, at::IntArrayRef output_size);
|
| 23 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape__adaptive_avg_pool3d_backward(const at::Tensor & grad_output, const at::Tensor & self);
|
| 24 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_abs(const at::Tensor & self);
|
| 25 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_arange_out(const at::Scalar & start, const at::Scalar & end, const at::Scalar & step, at::Tensor & out);
|
| 26 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_bernoulli(const at::Tensor & self, ::std::optional<at::Generator> generator);
|
| 27 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_bernoulli(const at::Tensor & self, double p, ::std::optional<at::Generator> generator);
|
| 28 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_binary_cross_entropy(const at::Tensor & self, const at::Tensor & target, const ::std::optional<at::Tensor> & weight, int64_t reduction);
|
| 29 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_binary_cross_entropy_backward(const at::Tensor & grad_output, const at::Tensor & self, const at::Tensor & target, const ::std::optional<at::Tensor> & weight, int64_t reduction);
|
| 30 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_cat(at::TensorList tensors, int64_t dim);
|
| 31 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_cholesky(const at::Tensor & self, bool upper);
|
| 32 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_clamp_min(const at::Tensor & self, const at::Scalar & min);
|
| 33 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_clone(const at::Tensor & self, ::std::optional<at::MemoryFormat> memory_format);
|
| 34 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_constant_pad_nd(const at::Tensor & self, at::IntArrayRef pad, const at::Scalar & value);
|
| 35 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_convolution(const at::Tensor & input, const at::Tensor & weight, const ::std::optional<at::Tensor> & bias, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, int64_t groups);
|
| 36 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_convolution_backward(const at::Tensor & grad_output, const at::Tensor & input, const at::Tensor & weight, at::OptionalIntArrayRef bias_sizes, at::IntArrayRef stride, at::IntArrayRef padding, at::IntArrayRef dilation, bool transposed, at::IntArrayRef output_padding, int64_t groups, ::std::array<bool,3> output_mask);
|
| 37 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_embedding(const at::Tensor & weight, const at::Tensor & indices, int64_t padding_idx, bool scale_grad_by_freq, bool sparse);
|
| 38 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_embedding_dense_backward(const at::Tensor & grad_output, const at::Tensor & indices, int64_t num_weights, int64_t padding_idx, bool scale_grad_by_freq);
|
| 39 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_expand(const at::Tensor & self, at::IntArrayRef size, bool implicit);
|
| 40 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_expand(const at::Tensor & self, c10::SymIntArrayRef size, bool implicit);
|
| 41 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_flip(const at::Tensor & self, at::IntArrayRef dims);
|
| 42 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_glu_backward(const at::Tensor & grad_output, const at::Tensor & self, int64_t dim);
|
| 43 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_glu_jvp(const at::Tensor & glu, const at::Tensor & x, const at::Tensor & dx, int64_t dim);
|
| 44 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_grid_sampler_2d(const at::Tensor & input, const at::Tensor & grid, int64_t interpolation_mode, int64_t padding_mode, bool align_corners);
|
| 45 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_grid_sampler_2d_backward(const at::Tensor & grad_output, const at::Tensor & input, const at::Tensor & grid, int64_t interpolation_mode, int64_t padding_mode, bool align_corners, ::std::array<bool,2> output_mask);
|
| 46 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_index_select(const at::Tensor & self, int64_t dim, const at::Tensor & index);
|
| 47 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_inverse(const at::Tensor & self);
|
| 48 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_isnan(const at::Tensor & self);
|
| 49 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_log_sigmoid_backward(const at::Tensor & grad_output, const at::Tensor & self, const at::Tensor & buffer);
|
| 50 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_log_sigmoid_forward(const at::Tensor & self);
|
| 51 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_logdet(const at::Tensor & self);
|
| 52 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_logical_and(const at::Tensor & self, const at::Tensor & other);
|
| 53 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_logical_not(const at::Tensor & self);
|
| 54 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_logical_or(const at::Tensor & self, const at::Tensor & other);
|
| 55 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_logical_xor(const at::Tensor & self, const at::Tensor & other);
|
| 56 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_masked_fill(const at::Tensor & self, const at::Tensor & mask, const at::Scalar & value);
|
| 57 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_masked_fill(const at::Tensor & self, const at::Tensor & mask, const at::Tensor & value);
|
| 58 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_max(const at::Tensor & self);
|
| 59 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_mean(const at::Tensor & self, ::std::optional<at::ScalarType> dtype);
|
| 60 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_min(const at::Tensor & self);
|
| 61 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_mv(const at::Tensor & self, const at::Tensor & vec);
|
| 62 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_native_batch_norm(const at::Tensor & input, const ::std::optional<at::Tensor> & weight, const ::std::optional<at::Tensor> & bias, const ::std::optional<at::Tensor> & running_mean, const ::std::optional<at::Tensor> & running_var, bool training, double momentum, double eps);
|
| 63 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_native_batch_norm_backward(const at::Tensor & grad_out, const at::Tensor & input, const ::std::optional<at::Tensor> & weight, const ::std::optional<at::Tensor> & running_mean, const ::std::optional<at::Tensor> & running_var, const ::std::optional<at::Tensor> & save_mean, const ::std::optional<at::Tensor> & save_invstd, bool train, double eps, ::std::array<bool,3> output_mask);
|
| 64 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_native_dropout(const at::Tensor & input, double p, ::std::optional<bool> train);
|
| 65 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_native_dropout_backward(const at::Tensor & grad_output, const at::Tensor & mask, double scale);
|
| 66 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_native_layer_norm(const at::Tensor & input, at::IntArrayRef normalized_shape, const ::std::optional<at::Tensor> & weight, const ::std::optional<at::Tensor> & bias, double eps);
|
| 67 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_native_layer_norm_backward(const at::Tensor & grad_out, const at::Tensor & input, at::IntArrayRef normalized_shape, const at::Tensor & mean, const at::Tensor & rstd, const ::std::optional<at::Tensor> & weight, const ::std::optional<at::Tensor> & bias, ::std::array<bool,3> output_mask);
|
| 68 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_new_empty_strided(const at::Tensor & self, at::IntArrayRef size, at::IntArrayRef stride, ::std::optional<at::ScalarType> dtype, ::std::optional<at::Layout> layout, ::std::optional<at::Device> device, ::std::optional<bool> pin_memory);
|
| 69 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_nll_loss2d_backward(const at::Tensor & grad_output, const at::Tensor & self, const at::Tensor & target, const ::std::optional<at::Tensor> & weight, int64_t reduction, int64_t ignore_index, const at::Tensor & total_weight);
|
| 70 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_nll_loss2d_forward(const at::Tensor & self, const at::Tensor & target, const ::std::optional<at::Tensor> & weight, int64_t reduction, int64_t ignore_index);
|
| 71 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_nonzero(const at::Tensor & self);
|
| 72 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_normal_functional(const at::Tensor & self, double mean, double std, ::std::optional<at::Generator> generator);
|
| 73 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_random(const at::Tensor & self, ::std::optional<at::Generator> generator);
|
| 74 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_random(const at::Tensor & self, int64_t to, ::std::optional<at::Generator> generator);
|
| 75 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_random(const at::Tensor & self, int64_t from, ::std::optional<int64_t> to, ::std::optional<at::Generator> generator);
|
| 76 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_relu(const at::Tensor & self);
|
| 77 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_repeat(const at::Tensor & self, at::IntArrayRef repeats);
|
| 78 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_slogdet(const at::Tensor & self);
|
| 79 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_smooth_l1_loss_backward(const at::Tensor & grad_output, const at::Tensor & self, const at::Tensor & target, int64_t reduction, double beta);
|
| 80 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_sort(const at::Tensor & self, int64_t dim, bool descending);
|
| 81 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_stack(at::TensorList tensors, int64_t dim);
|
| 82 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_std(const at::Tensor & self, bool unbiased);
|
| 83 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_std(const at::Tensor & self, at::OptionalIntArrayRef dim, bool unbiased, bool keepdim);
|
| 84 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_std(const at::Tensor & self, at::OptionalIntArrayRef dim, const ::std::optional<at::Scalar> & correction, bool keepdim);
|
| 85 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_sum(const at::Tensor & self, ::std::optional<at::ScalarType> dtype);
|
| 86 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape__to_copy(const at::Tensor & self, ::std::optional<at::ScalarType> dtype, ::std::optional<at::Layout> layout, ::std::optional<at::Device> device, ::std::optional<bool> pin_memory, bool non_blocking, ::std::optional<at::MemoryFormat> memory_format);
|
| 87 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_take(const at::Tensor & self, const at::Tensor & index);
|
| 88 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_trace(const at::Tensor & self);
|
| 89 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_zero(const at::Tensor & self);
|
| 90 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_narrow_copy_symint(const at::Tensor & self, int64_t dim, int64_t start, c10::SymInt length);
|
| 91 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_hardswish(const at::Tensor & self);
|
| 92 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_hardswish_backward(const at::Tensor & grad_output, const at::Tensor & self);
|
| 93 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_selu(const at::Tensor & self);
|
| 94 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_uniform(const at::Tensor & self, double from, double to, ::std::optional<at::Generator> generator);
|
| 95 |
+
|
| 96 |
+
// Non-Native ops
|
| 97 |
+
TORCH_API std::vector<Shape> compute_shape_scalar(const at::Scalar& value, const at::ScalarType& type);
|
| 98 |
+
TORCH_API std::vector<Shape> compute_shape_expand(const Output& input0, const std::vector<int64_t>& size, const bool& is_scalar_expand);
|
| 99 |
+
TORCH_API std::vector<Shape> compute_shape_view(const Output& input0, const std::vector<int64_t>& output_sizes);
|
| 100 |
+
TORCH_API std::vector<Shape> compute_shape_cast(const Output& input0, const at::ScalarType& dtype, const ::std::optional<at::ScalarType>& stype);
|
| 101 |
+
|
| 102 |
+
// View Ops
|
| 103 |
+
// (Now that functionalization pass is used, we should kill these in a later PR)
|
| 104 |
+
TORCH_API std::vector<Shape> compute_shape_as_strided_view_update(const Output& target, const Output& input, const std::vector<int64_t>& size, const std::vector<int64_t>& stride, const int64_t& storage_offset);
|
| 105 |
+
TORCH_API std::vector<Shape> compute_shape_as_strided(const Output& input, const std::vector<int64_t>& size, const std::vector<int64_t>& stride, const int64_t& storage_offset);
|
| 106 |
+
TORCH_API std::vector<Shape> compute_shape_diagonal_view_update(const Output& target, const Output& input, const int64_t& offset, const int64_t& dim1, const int64_t& dim2);
|
| 107 |
+
TORCH_API std::vector<Shape> compute_shape_diagonal(const Output& input, const int64_t& offset, const int64_t& dim1, const int64_t& dim2);
|
| 108 |
+
TORCH_API std::vector<Shape> compute_shape_narrow_view_update(const Output& input, const Output& source, const std::vector<int64_t>& base_indices);
|
| 109 |
+
TORCH_API std::vector<Shape> compute_shape_narrow(const Output& input, const std::vector<int64_t>& base_indices, const std::vector<int64_t>& sizes);
|
| 110 |
+
TORCH_API std::vector<Shape> compute_shape_permute(const Output& input, const std::vector<int64_t>& dims);
|
| 111 |
+
TORCH_API std::vector<Shape> compute_shape_resize(const Output& input, const std::vector<int64_t>& size);
|
| 112 |
+
TORCH_API std::vector<Shape> compute_shape_select_view_update(const Output& target, const Output& source, const int64_t& dim, const int64_t& start, const int64_t& end, const int64_t& stride);
|
| 113 |
+
TORCH_API std::vector<Shape> compute_shape_select(const Output& input, const int64_t& dim, const int64_t& start, const int64_t& end, const int64_t& stride);
|
| 114 |
+
TORCH_API std::vector<Shape> compute_shape_squeeze(const Output& input, const int& dim);
|
| 115 |
+
TORCH_API std::vector<Shape> compute_shape_unsqueeze(const Output& input, const int& dim);
|
| 116 |
+
|
| 117 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_select_scatter(const at::Tensor & self, const at::Tensor & src, int64_t dim, int64_t index);
|
| 118 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_diagonal_scatter(const at::Tensor & self, const at::Tensor & src, int64_t offset, int64_t dim1, int64_t dim2);
|
| 119 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_slice_scatter_symint(const at::Tensor & self, const at::Tensor & src, int64_t dim, ::std::optional<c10::SymInt> start, ::std::optional<c10::SymInt> end, c10::SymInt step);
|
| 120 |
+
TORCH_API std::vector<torch::lazy::Shape> compute_shape_as_strided_scatter_symint(const at::Tensor & self, const at::Tensor & src, c10::SymIntArrayRef size, c10::SymIntArrayRef stride, ::std::optional<c10::SymInt> storage_offset);
|
| 121 |
+
// clang-format on
|
| 122 |
+
} // namespace torch::lazy
|
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib/python3.10/site-packages/torch/include/torch/csrc/lazy/core/tensor.h
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/core/SymNodeImpl.h>
|
| 4 |
+
#include <c10/util/intrusive_ptr.h>
|
| 5 |
+
#include <torch/csrc/lazy/backend/backend_data.h>
|
| 6 |
+
#include <torch/csrc/lazy/backend/backend_device.h>
|
| 7 |
+
#include <torch/csrc/lazy/core/ir.h>
|
| 8 |
+
#include <torch/csrc/lazy/core/util.h>
|
| 9 |
+
|
| 10 |
+
namespace torch::lazy {
|
| 11 |
+
|
| 12 |
+
class TORCH_API SymNodeImpl : public c10::SymNodeImpl {
|
| 13 |
+
public:
|
| 14 |
+
SymNodeImpl(NodePtr ptr) : node_(std::move(ptr)) {}
|
| 15 |
+
NodePtr node_;
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
class LazyTensor;
|
| 19 |
+
using LazyTensorPtr = c10::intrusive_ptr<LazyTensor>;
|
| 20 |
+
|
| 21 |
+
class TORCH_API LazyTensor : public c10::intrusive_ptr_target {
|
| 22 |
+
public:
|
| 23 |
+
// This is the core lazy tensor data structure where all the tensor data is
|
| 24 |
+
// held. The lazy tensor is nothing more than a shared pointer to a Data
|
| 25 |
+
// object.
|
| 26 |
+
struct Data {
|
| 27 |
+
Data(BackendDataPtr handle, BackendDevice device)
|
| 28 |
+
: handle(std::move(handle)),
|
| 29 |
+
device(std::move(device)),
|
| 30 |
+
unique_id(GetNextTensorId()) {}
|
| 31 |
+
Data(Value ir_value, BackendDevice device)
|
| 32 |
+
: ir_value(std::move(ir_value)),
|
| 33 |
+
device(std::move(device)),
|
| 34 |
+
unique_id(GetNextTensorId()) {}
|
| 35 |
+
Data(at::Tensor tensor_data, BackendDevice device)
|
| 36 |
+
: tensor_data(std::move(tensor_data)),
|
| 37 |
+
device(std::move(device)),
|
| 38 |
+
unique_id(GetNextTensorId()) {}
|
| 39 |
+
// TODO(alanwaketan): Remove this ctor. This is a
|
| 40 |
+
// temporary ctor to ease XLA LTC migration. It depends on
|
| 41 |
+
// XLA's Functionalization integration.
|
| 42 |
+
Data(BackendDevice device)
|
| 43 |
+
: device(std::move(device)), unique_id(GetNextTensorId()) {}
|
| 44 |
+
|
| 45 |
+
Data(Data&& other) = delete;
|
| 46 |
+
Data(const Data&) = delete;
|
| 47 |
+
Data& operator=(const Data&) = delete;
|
| 48 |
+
Data& operator=(Data&&) = delete;
|
| 49 |
+
virtual ~Data();
|
| 50 |
+
|
| 51 |
+
BackendDataPtr handle;
|
| 52 |
+
Value ir_value;
|
| 53 |
+
std::optional<at::Tensor> tensor_data;
|
| 54 |
+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
|
| 55 |
+
const BackendDevice device;
|
| 56 |
+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
|
| 57 |
+
const int64_t unique_id = 0;
|
| 58 |
+
size_t generation = 1;
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
static LazyTensorPtr Create(
|
| 62 |
+
const at::Tensor& tensor,
|
| 63 |
+
const BackendDevice& device);
|
| 64 |
+
static LazyTensorPtr Create(Value ir_value, const BackendDevice& device);
|
| 65 |
+
static LazyTensorPtr Create(const BackendDataPtr& handle);
|
| 66 |
+
static LazyTensorPtr Create(std::shared_ptr<Data> data);
|
| 67 |
+
|
| 68 |
+
// The default ctor previously created a null LazyTensor (one with no 'data'
|
| 69 |
+
// obj). Creating a null LazyTensor is no longer possible, since the same can
|
| 70 |
+
// be achieved by creating a null LazyTensorPtr and it is way too confusing to
|
| 71 |
+
// have to check both lazy_tensor_ptr && *lazy_tensor_ptr, so everywhere that
|
| 72 |
+
// used to rely on a LazyTensor obj with a null Data can now rely on a null
|
| 73 |
+
// LazyTensorPtr instead.
|
| 74 |
+
LazyTensor() = delete;
|
| 75 |
+
LazyTensor(const LazyTensor&) = default;
|
| 76 |
+
LazyTensor(LazyTensor&&) noexcept = default;
|
| 77 |
+
LazyTensor& operator=(const LazyTensor&) = default;
|
| 78 |
+
LazyTensor& operator=(LazyTensor&&) noexcept = default;
|
| 79 |
+
|
| 80 |
+
~LazyTensor() override = default;
|
| 81 |
+
|
| 82 |
+
size_t generation() const {
|
| 83 |
+
return data()->generation;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// Override it to use your own Shape.
|
| 87 |
+
virtual int64_t size(int64_t dim) const;
|
| 88 |
+
|
| 89 |
+
// Override it to use your own graph executor.
|
| 90 |
+
virtual at::Tensor ToTensor(bool detached);
|
| 91 |
+
|
| 92 |
+
void ShallowCopyTo(const LazyTensorPtr& dest) const;
|
| 93 |
+
|
| 94 |
+
// Assigns the tensor value to the lazy tensor.
|
| 95 |
+
void SetTensor(at::Tensor tensor);
|
| 96 |
+
|
| 97 |
+
void UpdateFromTensor(const at::Tensor& tensor, bool sync);
|
| 98 |
+
void UpdateFromTensorOut(const at::Tensor& tensor);
|
| 99 |
+
void UpdateFromTensorOut(const LazyTensorPtr& tensor);
|
| 100 |
+
|
| 101 |
+
const std::shared_ptr<Data>& data() const;
|
| 102 |
+
|
| 103 |
+
// Override it to use your own type conversion.
|
| 104 |
+
virtual at::ScalarType dtype() const;
|
| 105 |
+
|
| 106 |
+
MaybeRef<Shape> shape() const;
|
| 107 |
+
|
| 108 |
+
const BackendDevice& GetDevice() const;
|
| 109 |
+
int64_t GetUniqueId() const;
|
| 110 |
+
|
| 111 |
+
// Fetches the data behind the tensor. If the tensor has a graph defining
|
| 112 |
+
// its current value, executes the graph and fetches the data result.
|
| 113 |
+
BackendDataPtr GetDataHandle();
|
| 114 |
+
|
| 115 |
+
// Fetches the current value of the data, which can be missing (nullptr)
|
| 116 |
+
// in case the tensor has a graph defining its current value,
|
| 117 |
+
BackendDataPtr CurrentDataHandle() const;
|
| 118 |
+
|
| 119 |
+
void SetDataHandle(BackendDataPtr handle);
|
| 120 |
+
void SetDataHandle(BackendDataPtr handle, bool sync);
|
| 121 |
+
|
| 122 |
+
// Retrieves the current IR Node, or nullptr in case no active IR Node is
|
| 123 |
+
// available.
|
| 124 |
+
Value CurrentIrValue() const;
|
| 125 |
+
|
| 126 |
+
// Retrieves the IR Node representing this LazyTensor. One will be created if
|
| 127 |
+
// missing. Note that although this is a const API, it actually changes the
|
| 128 |
+
// internal state of the object.
|
| 129 |
+
Value GetIrValue() const;
|
| 130 |
+
|
| 131 |
+
void SetIrValue(Value ir_value);
|
| 132 |
+
void SetInPlaceIrValue(Value ir_value);
|
| 133 |
+
|
| 134 |
+
std::optional<at::Tensor> CurrentTensorData() const;
|
| 135 |
+
|
| 136 |
+
std::vector<LazyTensorPtr> MakeOutputTensors(const NodePtr& node) const;
|
| 137 |
+
|
| 138 |
+
LazyTensorPtr CopyTensorToDevice(const BackendDevice& device);
|
| 139 |
+
|
| 140 |
+
// Applies the queue of operations in preparation for using the data.
|
| 141 |
+
// Override it to use your own graph executor.
|
| 142 |
+
virtual void ApplyPendingGraph();
|
| 143 |
+
|
| 144 |
+
// Override it to set extra information.
|
| 145 |
+
virtual void AssignIrValue(Value ir_value) const;
|
| 146 |
+
|
| 147 |
+
protected:
|
| 148 |
+
explicit LazyTensor(std::shared_ptr<Data> data);
|
| 149 |
+
|
| 150 |
+
void SetTensorData(at::Tensor tensor_data);
|
| 151 |
+
|
| 152 |
+
// We build a graph accumulating operations, but at a given point we
|
| 153 |
+
// need to force a rendering, otherwise the graph can grow without control.
|
| 154 |
+
// Think:
|
| 155 |
+
// for i in range(0, 100000):
|
| 156 |
+
// a = a + b
|
| 157 |
+
void TryLimitGraphSize();
|
| 158 |
+
|
| 159 |
+
// Override it to instantiate your own data.
|
| 160 |
+
virtual Value GetIrValueForTensor(
|
| 161 |
+
const at::Tensor& tensor,
|
| 162 |
+
const BackendDevice& device) const;
|
| 163 |
+
|
| 164 |
+
Value CreateTensorNode(const BackendDataPtr& data, bool read_only) const;
|
| 165 |
+
|
| 166 |
+
private:
|
| 167 |
+
LazyTensor(const at::Tensor& tensor, const BackendDevice& device);
|
| 168 |
+
LazyTensor(Value ir_value, const BackendDevice& device);
|
| 169 |
+
explicit LazyTensor(const BackendDataPtr& handle);
|
| 170 |
+
|
| 171 |
+
static int64_t GetNextTensorId();
|
| 172 |
+
|
| 173 |
+
std::shared_ptr<Data> data_;
|
| 174 |
+
};
|
| 175 |
+
|
| 176 |
+
// Utils to convert at::Tensor to LazyTensor, and vice versa.
|
| 177 |
+
|
| 178 |
+
// Section 0: c10::Tensorlist ==> lazy::TensorList
|
| 179 |
+
// note: GetTensorList is not totally parallel to GetLtcTensor; A TensorList
|
| 180 |
+
// skips
|
| 181 |
+
// the LazyTensor wrappers, assuming that the list of underlying IR nodes
|
| 182 |
+
// is actually more useful for downstream computations. TBD.
|
| 183 |
+
TORCH_API torch::lazy::Value GetTensorList(at::ITensorListRef tensors);
|
| 184 |
+
|
| 185 |
+
// Section 1: at::Tensor => LazyTensor.
|
| 186 |
+
// Extracts the LazyTensor out of an at::Tensor. Returns a null LazyTensor
|
| 187 |
+
// if the tensor is not a lazy tensor.
|
| 188 |
+
TORCH_API LazyTensorPtr TryGetLtcTensor(const at::Tensor& tensor);
|
| 189 |
+
|
| 190 |
+
// Extracts the LazyTensor out of an at::Tensor. Throws an exception
|
| 191 |
+
// if the tensor is not a lazy tensor.
|
| 192 |
+
TORCH_API LazyTensorPtr GetLtcTensor(const at::Tensor& tensor);
|
| 193 |
+
|
| 194 |
+
// Same as above, applied to a list of tensors.
|
| 195 |
+
TORCH_API std::vector<LazyTensorPtr> GetLtcTensors(
|
| 196 |
+
c10::ArrayRef<at::Tensor> tensors);
|
| 197 |
+
|
| 198 |
+
// If tensor is a lazy tensor type, returns the LazyTensor embedded within it,
|
| 199 |
+
// otherwise creates a new lazy tensor type with tensor as data.
|
| 200 |
+
TORCH_API LazyTensorPtr GetOrCreateLtcTensor(
|
| 201 |
+
const std::optional<at::Tensor>& tensor,
|
| 202 |
+
const BackendDevice& device);
|
| 203 |
+
|
| 204 |
+
TORCH_API LazyTensorPtr GetLtcTensorOrCreateForWrappedNumber(
|
| 205 |
+
const at::Tensor& tensor,
|
| 206 |
+
const BackendDevice& device);
|
| 207 |
+
|
| 208 |
+
// Section 2: LazyTensor => at::Tensor.
|
| 209 |
+
// Creates an ATen tensor from an LazyTensor.
|
| 210 |
+
TORCH_API at::Tensor CreateAtenFromLtcTensor(const LazyTensorPtr& ltc_tensor);
|
| 211 |
+
TORCH_API at::Tensor CreateAtenFromLtcTensor(LazyTensor&& ltc_tensor);
|
| 212 |
+
|
| 213 |
+
// Note [Lazy Tensor Functionalization]
|
| 214 |
+
// The functionalization pass is implemented by wrapping all TensorImpl
|
| 215 |
+
// objects in C++ with an extra FunctionalTensorWrapper object,
|
| 216 |
+
// that knows how to perform functionalization
|
| 217 |
+
//
|
| 218 |
+
// Certain functions in the aten API serve as entry/exit points for
|
| 219 |
+
// functionalization, where we need to perform the wrapping/unwrapping:
|
| 220 |
+
// - aten::to.device
|
| 221 |
+
// - aten::empty
|
| 222 |
+
|
| 223 |
+
// Given a non-lazy tensor, this function creates a lazy tensor on the specified
|
| 224 |
+
// (lazy) device. The functionalize_output determines whether or not we should
|
| 225 |
+
// wrap the output in a "functional wrapper".
|
| 226 |
+
//
|
| 227 |
+
// How do you know whether to pass true/false for functionalize_output?
|
| 228 |
+
//
|
| 229 |
+
// Case 1: nonlazy -> lazy
|
| 230 |
+
// If you're implementing a function that takes in nonlazy tensors and returns
|
| 231 |
+
// lazy tensors, then you should think of that function as an "entrypoint" to
|
| 232 |
+
// functionalization, and use functionalize_output=true Examples include:
|
| 233 |
+
// - factory functions (the LTC kernel for at::empty)
|
| 234 |
+
// - CPU -> Lazy device conversions (the LTC kernel for at::to_device)
|
| 235 |
+
//
|
| 236 |
+
// Case 2: lazy -> lazy
|
| 237 |
+
// If you're implementing a function that takes in lazy tensors and returns
|
| 238 |
+
// lazy tensors,
|
| 239 |
+
// **but** requires creating lazy tensors internally,
|
| 240 |
+
// then you can assume that the current function is running inside of some
|
| 241 |
+
// outer context where functionalization is already running, that will take
|
| 242 |
+
// care of doing the wrapping for you, and use functionalize_output=true
|
| 243 |
+
// Examples include:
|
| 244 |
+
// - CPU fallback (takes in lazy tensors, converts to cpu, calls kernel,
|
| 245 |
+
// converts returns back to lazy tensors).
|
| 246 |
+
TORCH_API at::Tensor to_lazy_tensor(
|
| 247 |
+
const at::Tensor& self,
|
| 248 |
+
const c10::TensorOptions& options,
|
| 249 |
+
at::Device device,
|
| 250 |
+
bool non_blocking,
|
| 251 |
+
bool functionalize_output);
|
| 252 |
+
|
| 253 |
+
template <size_t... Indices>
|
| 254 |
+
auto TupleAtenFromLtcTensorsImpl(
|
| 255 |
+
const std::vector<LazyTensorPtr>& tensors,
|
| 256 |
+
std::index_sequence<Indices...>) {
|
| 257 |
+
return std::make_tuple(CreateAtenFromLtcTensor(tensors[Indices])...);
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
template <size_t N>
|
| 261 |
+
auto TupleAtenFromLtcTensors(const std::vector<LazyTensorPtr>& tensors) {
|
| 262 |
+
return TupleAtenFromLtcTensorsImpl(tensors, std::make_index_sequence<N>{});
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
} // namespace torch::lazy
|