Instructions to use giancap61/AXEL-AI_Virtual_Race_Engineer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M # Run inference directly in the terminal: llama cli -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M # Run inference directly in the terminal: llama cli -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M # Run inference directly in the terminal: ./build/bin/llama cli -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Use Docker
docker model run hf.co/giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
- Llama new
- LM Studio
- Jan
- Ollama
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with Ollama:
ollama run hf.co/giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
- Unsloth Desktop
- Pi
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:9931/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with Docker Model Runner:
docker model run hf.co/giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
- Lemonade
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Run and chat with the model
lemonade run user.AXEL-AI_Virtual_Race_Engineer-Q5_K_M
List all available models
lemonade list
- Hermes Agent
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:9931/v1 hermes config set model.default giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use giancap61/AXEL-AI_Virtual_Race_Engineer with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:9931/v1 \ --custom-model-id "giancap61/AXEL-AI_Virtual_Race_Engineer:Q5_K_M" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/Operator.h +19 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/Operators.cpp +19 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/Operators.h +74 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RedispatchFunctions.cpp +15 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RedispatchFunctions.h +32 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterBackendSelect.cpp +29 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterCodegenUnboxedKernels.cpp +41 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterDispatchDefinitions.ini +22 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterDispatchKey.cpp +52 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterFunctionalization.cpp +116 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterSchema.cpp +13 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegistrationDeclarations.h +4 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/TensorBody.h +756 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/TensorMethods.cpp +61 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/UfuncCPU.cpp +19 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/UfuncCPUKernel.cpp +14 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/UfuncCUDA.cu +21 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/UnboxingFunctions.cpp +35 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/UnboxingFunctions.h +32 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/ViewMetaClasses.cpp +19 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/ViewMetaClasses.h +12 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/ViewMetaClassesPythonBinding.cpp +11 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/__init__.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/context.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_annotated_fn_args.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_autograd.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_autograd_functions.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_inplace_or_view_type.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_python_functions.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_trace_type.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_variable_factories.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_variable_type.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_view_funcs.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/load_derivatives.cpython-312.pyc +0 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/ADInplaceOrViewType.cpp +38 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/Functions.cpp +44 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/Functions.h +51 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/TraceType.cpp +40 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/VariableType.cpp +77 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/VariableType.h +55 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/ViewFuncs.cpp +14 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/ViewFuncs.h +28 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/annotated_fn_args.py.in +11 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_enum_tag.cpp +15 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_fft_functions.cpp +81 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_functions.cpp +37 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_functions.h +17 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_linalg_functions.cpp +68 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_nested_functions.cpp +81 -0
- TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_nn_functions.cpp +113 -0
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/Operator.h
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// ${generated_comment}
|
| 4 |
+
|
| 5 |
+
#include <string_view>
|
| 6 |
+
#include <tuple>
|
| 7 |
+
#include <vector>
|
| 8 |
+
|
| 9 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 10 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 11 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 12 |
+
#include <ATen/core/ATen_fwd.h>
|
| 13 |
+
|
| 14 |
+
namespace at {
|
| 15 |
+
namespace _ops {
|
| 16 |
+
|
| 17 |
+
${declarations}
|
| 18 |
+
|
| 19 |
+
}} // namespace at::_ops
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/Operators.cpp
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <ATen/Tensor.h>
|
| 2 |
+
#include <ATen/core/dispatch/Dispatcher.h>
|
| 3 |
+
|
| 4 |
+
// ${generated_comment}
|
| 5 |
+
// NOTE See [Sharded File] comment in VariableType
|
| 6 |
+
|
| 7 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 8 |
+
#include <ATen/Operators.h>
|
| 9 |
+
#else
|
| 10 |
+
${operator_headers}
|
| 11 |
+
#endif
|
| 12 |
+
|
| 13 |
+
${static_dispatch_extra_headers}
|
| 14 |
+
|
| 15 |
+
namespace at { namespace _ops {
|
| 16 |
+
|
| 17 |
+
${definitions}
|
| 18 |
+
|
| 19 |
+
}} // namespace at::_ops
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/Operators.h
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// ${generated_comment}
|
| 4 |
+
|
| 5 |
+
#ifdef TORCH_ASSERT_NO_OPERATORS
|
| 6 |
+
#error This change adds a dependency on native_functions.yaml, \
|
| 7 |
+
meaning the file will need to be re-compiled every time an operator \
|
| 8 |
+
is changed or added. Consider if your change would be better placed in \
|
| 9 |
+
another file, or if a more specific header might achieve the same goal. \
|
| 10 |
+
See NOTE: [Tensor vs. TensorBase]
|
| 11 |
+
#endif
|
| 12 |
+
|
| 13 |
+
#if defined(AT_PER_OPERATOR_HEADERS) && defined(TORCH_ASSERT_ONLY_METHOD_OPERATORS)
|
| 14 |
+
#error This change adds a dependency on all pytorch operators, meaning the \
|
| 15 |
+
file will need to be re-compiled every time an operator is changed or added. \
|
| 16 |
+
Consider including a specific operator from <ATen/ops/{my_operator}_ops.h> \
|
| 17 |
+
and see NOTE [TORCH_ASSERT_ONLY_METHOD_OPERATORS].
|
| 18 |
+
#endif
|
| 19 |
+
|
| 20 |
+
#include <c10/core/SymInt.h>
|
| 21 |
+
#include <c10/core/SymIntArrayRef.h>
|
| 22 |
+
#include <c10/core/Scalar.h>
|
| 23 |
+
#include <c10/core/TensorOptions.h>
|
| 24 |
+
#include <c10/core/QScheme.h>
|
| 25 |
+
#include <c10/util/OptionalArrayRef.h>
|
| 26 |
+
#include <tuple>
|
| 27 |
+
#include <vector>
|
| 28 |
+
|
| 29 |
+
${Operators_includes}
|
| 30 |
+
|
| 31 |
+
// Extension writers: do you write wrapper functions? Are you frustrated with
|
| 32 |
+
// resolving overloads of operators? Are you frustrated with dealing with
|
| 33 |
+
// pointer-to-methods and resolving overloads of pointer-to-methods?? Look no
|
| 34 |
+
// further, this is the utility for you.
|
| 35 |
+
//
|
| 36 |
+
// Given an operator schema: aten::op.overload(...
|
| 37 |
+
//
|
| 38 |
+
// Use ATEN_FN2(op, overload) to get a *function* version of the operator
|
| 39 |
+
// that is guaranteed to not be overloaded. This means that you can safely
|
| 40 |
+
// decltype(&ATEN_FN2(op, overload)) it. NB: the 2 means this macro takes 2 args.
|
| 41 |
+
//
|
| 42 |
+
// Given an operator schema without an overload name: aten::op(...
|
| 43 |
+
//
|
| 44 |
+
// Use ATEN_FN(op) to get an unambiguous *function* version of the operator.
|
| 45 |
+
//
|
| 46 |
+
// There is some interesting behavior for out= operations.
|
| 47 |
+
// ATEN_FN2(sin, out) gives a function that is *faithful* to the schema;
|
| 48 |
+
// that is, the order of arguments is exactly what it looks like in the schema.
|
| 49 |
+
|
| 50 |
+
#define ATEN_FN2(op_name, overload) at::_ops::op_name##_##overload::call
|
| 51 |
+
#define ATEN_FN(op_name) at::_ops::op_name::call
|
| 52 |
+
|
| 53 |
+
// Separately, ATEN_OP(op) and ATEN_OP2(op, overload) define a class containing compile-time
|
| 54 |
+
// metadata about a given aten operator.
|
| 55 |
+
// Notable data on the class includes:
|
| 56 |
+
// - ATEN_OP2(add, Tensor)::name // returns the string name: "add"
|
| 57 |
+
// - ATEN_OP2(add, Tensor)::overload_name // returns the string overload name: "Tensor"
|
| 58 |
+
// - ATEN_OP2(add, Tensor)::schema // returns the C++ schema type: at::Tensor (const at::Tensor &, const at::Tensor &, const at::Scalar &)
|
| 59 |
+
// - ATEN_OP2(add, Tensor)::schema_str // returns the string jit type: "add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor"
|
| 60 |
+
|
| 61 |
+
#define ATEN_OP2(op_name, overload) at::_ops::op_name##_##overload
|
| 62 |
+
#define ATEN_OP(op_name) at::_ops::op_name
|
| 63 |
+
|
| 64 |
+
// WARNING: Please do not call any of the ops in the _ops namespace directly.
|
| 65 |
+
// Use the ATEN_FN macros. We do not guarantee stability of the naming
|
| 66 |
+
// scheme for the functions in at::_ops
|
| 67 |
+
|
| 68 |
+
// See Note [The ATen Operators API] for details of the at::_ops namespace
|
| 69 |
+
|
| 70 |
+
namespace at {
|
| 71 |
+
namespace _ops {
|
| 72 |
+
${Operators_declarations}
|
| 73 |
+
} // namespace _ops
|
| 74 |
+
} // namespace at
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RedispatchFunctions.cpp
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ${generated_comment}
|
| 2 |
+
|
| 3 |
+
#include <ATen/RedispatchFunctions.h>
|
| 4 |
+
#include <ATen/Functions.h>
|
| 5 |
+
|
| 6 |
+
#include <ATen/core/dispatch/Dispatcher.h>
|
| 7 |
+
#include <ATen/core/op_registration/adaption.h>
|
| 8 |
+
|
| 9 |
+
namespace at {
|
| 10 |
+
|
| 11 |
+
namespace redispatch {
|
| 12 |
+
${function_redispatch_definitions}
|
| 13 |
+
} // namespace redispatch
|
| 14 |
+
|
| 15 |
+
} // namespace at
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RedispatchFunctions.h
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// ${generated_comment}
|
| 4 |
+
|
| 5 |
+
#ifdef TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 6 |
+
#error This change adds a dependency on all pytorch operators, meaning the \
|
| 7 |
+
file will need to be re-compiled every time an operator is changed or added. \
|
| 8 |
+
Consider using the at::_ops::{name}::redispatch() interface by including \
|
| 9 |
+
the specific operator from <ATen/ops/{my_operator}_ops.h>
|
| 10 |
+
#endif
|
| 11 |
+
|
| 12 |
+
#include <c10/core/Scalar.h>
|
| 13 |
+
#include <ATen/Tensor.h>
|
| 14 |
+
#include <c10/core/Storage.h>
|
| 15 |
+
#include <ATen/core/Generator.h>
|
| 16 |
+
#include <c10/util/Deprecated.h>
|
| 17 |
+
#include <ATen/DeviceGuard.h>
|
| 18 |
+
#include <c10/core/TensorOptions.h>
|
| 19 |
+
#include <ATen/core/Reduction.h>
|
| 20 |
+
#include <optional>
|
| 21 |
+
#include <ATen/TensorUtils.h>
|
| 22 |
+
#include <ATen/Context.h>
|
| 23 |
+
#include <ATen/TracerMode.h>
|
| 24 |
+
#include <ATen/Operators.h>
|
| 25 |
+
|
| 26 |
+
namespace at {
|
| 27 |
+
|
| 28 |
+
namespace redispatch {
|
| 29 |
+
${function_redispatch_definitions}
|
| 30 |
+
} // namespace redispatch
|
| 31 |
+
|
| 32 |
+
}
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterBackendSelect.cpp
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// We register ops with a higher priority dispatch key (BackendSelect) than the usual backend-specific keys (e.g. CPU)
|
| 2 |
+
// which makes calls to the factory functions dispatch to here.
|
| 3 |
+
// We then 'manually' compute a lower-priority to re-dispatch to (e.g. CPU) to get to the eventually correct backend.
|
| 4 |
+
// ${generated_comment}
|
| 5 |
+
|
| 6 |
+
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 7 |
+
#include <ATen/core/Tensor.h>
|
| 8 |
+
#include <ATen/core/dispatch/DispatchKeyExtractor.h>
|
| 9 |
+
#include <torch/library.h>
|
| 10 |
+
|
| 11 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 12 |
+
#include <ATen/Operators.h>
|
| 13 |
+
#else
|
| 14 |
+
|
| 15 |
+
${ops_headers}
|
| 16 |
+
#endif
|
| 17 |
+
|
| 18 |
+
namespace at {
|
| 19 |
+
|
| 20 |
+
namespace {
|
| 21 |
+
|
| 22 |
+
${backend_select_method_definitions}
|
| 23 |
+
|
| 24 |
+
TORCH_LIBRARY_IMPL(aten, BackendSelect, m) {
|
| 25 |
+
${backend_select_function_registrations};
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
} // namespace
|
| 29 |
+
} // at
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterCodegenUnboxedKernels.cpp
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <torch/csrc/jit/runtime/operator.h>
|
| 2 |
+
#include <torch/csrc/jit/runtime/custom_operator.h>
|
| 3 |
+
#include <torch/csrc/jit/runtime/register_ops_utils.h>
|
| 4 |
+
|
| 5 |
+
#include <ATen/UnboxingFunctions.h>
|
| 6 |
+
|
| 7 |
+
// ${generated_comment}
|
| 8 |
+
|
| 9 |
+
// NOTE [Sharded File]: This file is generated in a sharded fashion to speed up
|
| 10 |
+
// incremental rebuilds. See the comment at the top of
|
| 11 |
+
// templates/VariableType.cpp for an analogous, in-depth discussion.
|
| 12 |
+
//
|
| 13 |
+
// Generated by tools/jit/gen_unboxing.py. This file registers all ATen ops into JIT op registry instead of c10
|
| 14 |
+
// dispatcher. JIT op registry only takes boxed kernels, so we are calling unboxing functions in UnboxingFunctions.h
|
| 15 |
+
// to cast arguments into C++ types (instead of IValue) and delegate to unboxed kernels.
|
| 16 |
+
|
| 17 |
+
namespace torch { namespace jit {
|
| 18 |
+
|
| 19 |
+
using autograd::Variable;
|
| 20 |
+
using autograd::variable_list;
|
| 21 |
+
using at::Scalar;
|
| 22 |
+
using at::ScalarType;
|
| 23 |
+
using at::Tensor;
|
| 24 |
+
using at::TensorOptions;
|
| 25 |
+
using at::DeviceGuard;
|
| 26 |
+
|
| 27 |
+
using ::c10::fmap;
|
| 28 |
+
using ::c10::filter;
|
| 29 |
+
|
| 30 |
+
namespace {
|
| 31 |
+
|
| 32 |
+
RegisterOperators reg({
|
| 33 |
+
|
| 34 |
+
// Generated operators
|
| 35 |
+
${unboxed_ops}
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
} // anon namespace
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
}} // namespace torch::jit
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterDispatchDefinitions.ini
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
${ns_prologue}
|
| 2 |
+
|
| 3 |
+
// NB: TORCH_LIBRARY_IMPL must be in an anonymous namespace to avoid
|
| 4 |
+
// ambiguity with conflicting identifiers that may have been defined in
|
| 5 |
+
// at namespace already.
|
| 6 |
+
namespace {
|
| 7 |
+
|
| 8 |
+
${dispatch_anonymous_definitions}
|
| 9 |
+
|
| 10 |
+
${static_init_dispatch_registrations}
|
| 11 |
+
|
| 12 |
+
} // anonymous namespace
|
| 13 |
+
|
| 14 |
+
${deferred_dispatch_registrations}
|
| 15 |
+
|
| 16 |
+
namespace ${dispatch_namespace} {
|
| 17 |
+
|
| 18 |
+
${dispatch_namespaced_definitions}
|
| 19 |
+
|
| 20 |
+
} // namespace ${dispatch_namespace}
|
| 21 |
+
|
| 22 |
+
${ns_epilogue}
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterDispatchKey.cpp
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// an external backend might generate file within its code tree
|
| 2 |
+
// and check all the source files within the tree with clang-format.
|
| 3 |
+
// so, disable it since the backend might have a different config.
|
| 4 |
+
// clang-format off
|
| 5 |
+
|
| 6 |
+
// NOTE: This condition is true for all PyTorch internal libraries, it
|
| 7 |
+
// just excludes external projects such as torch_xla which
|
| 8 |
+
// reuse some of the PyTorch codegen machinery.
|
| 9 |
+
#if defined(CAFFE2_BUILD_MAIN_LIB) || \
|
| 10 |
+
defined(TORCH_CUDA_BUILD_MAIN_LIB) || \
|
| 11 |
+
defined(TORCH_HIP_BUILD_MAIN_LIB) || \
|
| 12 |
+
defined(TORCH_XPU_BUILD_MAIN_LIB)
|
| 13 |
+
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 14 |
+
#endif
|
| 15 |
+
|
| 16 |
+
// ${generated_comment}
|
| 17 |
+
|
| 18 |
+
#include <c10/core/TensorImpl.h>
|
| 19 |
+
#include <c10/core/Allocator.h>
|
| 20 |
+
#include <ATen/DeviceGuard.h>
|
| 21 |
+
#include <ATen/NamedTensorUtils.h>
|
| 22 |
+
#include <ATen/Utils.h>
|
| 23 |
+
#include <ATen/WrapDimUtils.h>
|
| 24 |
+
#include <ATen/Dispatch.h>
|
| 25 |
+
#include <c10/util/ExclusivelyOwned.h>
|
| 26 |
+
#include <c10/util/Half.h>
|
| 27 |
+
#include <c10/core/UndefinedTensorImpl.h>
|
| 28 |
+
#include <optional>
|
| 29 |
+
#include <ATen/Tensor.h>
|
| 30 |
+
#include <ATen/native/Resize.h>
|
| 31 |
+
|
| 32 |
+
#include <cstddef>
|
| 33 |
+
#include <functional>
|
| 34 |
+
#include <memory>
|
| 35 |
+
#include <utility>
|
| 36 |
+
|
| 37 |
+
#include <ATen/Config.h>
|
| 38 |
+
#include <ATen/core/op_registration/adaption.h>
|
| 39 |
+
#include <torch/library.h>
|
| 40 |
+
$extra_cuda_headers
|
| 41 |
+
$external_backend_headers
|
| 42 |
+
$dispatch_headers
|
| 43 |
+
$ops_headers
|
| 44 |
+
|
| 45 |
+
namespace at {
|
| 46 |
+
namespace {
|
| 47 |
+
$dispatch_helpers
|
| 48 |
+
} // namespace
|
| 49 |
+
} // namespace at
|
| 50 |
+
|
| 51 |
+
// See template file RegisterDispatchDefinitions.ini
|
| 52 |
+
$dispatch_definitions
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterFunctionalization.cpp
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 2 |
+
// ${generated_comment}
|
| 3 |
+
|
| 4 |
+
#include <ATen/core/LegacyTypeDispatch.h>
|
| 5 |
+
#include <ATen/EmptyTensor.h>
|
| 6 |
+
#include <ATen/FunctionalTensorWrapper.h>
|
| 7 |
+
#include <ATen/ViewMetaClasses.h>
|
| 8 |
+
#include <ATen/MemoryOverlap.h>
|
| 9 |
+
#include <torch/library.h>
|
| 10 |
+
|
| 11 |
+
#include <c10/util/env.h>
|
| 12 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 13 |
+
#include <ATen/Operators.h>
|
| 14 |
+
#include <ATen/NativeFunctions.h>
|
| 15 |
+
#else
|
| 16 |
+
// needed for the meta tensor calls to get stride info in functionalization
|
| 17 |
+
#include <ATen/ops/empty_strided_native.h>
|
| 18 |
+
// needed for special handling of copy_().
|
| 19 |
+
// See Note [functionalizating copy_() and not preserving strides]
|
| 20 |
+
#include <ATen/ops/to_ops.h>
|
| 21 |
+
#include <ATen/ops/expand_copy_ops.h>
|
| 22 |
+
|
| 23 |
+
$ops_headers
|
| 24 |
+
#endif
|
| 25 |
+
|
| 26 |
+
namespace at {
|
| 27 |
+
namespace functionalization {
|
| 28 |
+
|
| 29 |
+
// This keyset is used by functionalization when it calls into meta kernels
|
| 30 |
+
// to accurately propagate stride metadata.
|
| 31 |
+
// Exclude any modes: the purpose of calling into meta kernels is only as an implementation
|
| 32 |
+
// detail to perform shape inference, and we don't want any modal keys to run.
|
| 33 |
+
// Specifically, we want to prevent functionalization and Python modes from running.
|
| 34 |
+
constexpr auto exclude_keys_for_meta_dispatch =
|
| 35 |
+
c10::functorch_transforms_ks |
|
| 36 |
+
c10::DispatchKeySet({
|
| 37 |
+
c10::DispatchKey::FuncTorchDynamicLayerBackMode,
|
| 38 |
+
c10::DispatchKey::FuncTorchDynamicLayerFrontMode,
|
| 39 |
+
c10::DispatchKey::Python,
|
| 40 |
+
c10::DispatchKey::PreDispatch,
|
| 41 |
+
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
// Helper around at::has_internal_overlap.
|
| 45 |
+
// The ATen util is used in hot-path eager mode: it's always fast,
|
| 46 |
+
// but might return TOO_HARD sometimes.
|
| 47 |
+
// During functionalization, we're ok taking a bit longer
|
| 48 |
+
// to detect memory overlap.
|
| 49 |
+
inline bool has_internal_overlap_helper(const at::Tensor t) {
|
| 50 |
+
auto has_overlap = at::has_internal_overlap(t);
|
| 51 |
+
if (has_overlap == at::MemOverlap::Yes) return true;
|
| 52 |
+
if (has_overlap == at::MemOverlap::No) return false;
|
| 53 |
+
return false;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
inline Tensor to_meta(const Tensor& t) {
|
| 58 |
+
if (!t.defined()) return t;
|
| 59 |
+
return at::native::empty_strided_meta_symint(t.sym_sizes(), t.sym_strides(),
|
| 60 |
+
/*dtype=*/t.scalar_type(), /*layout=*/t.layout(),
|
| 61 |
+
/*device=*/c10::Device(kMeta), /*pin_memory=*/std::nullopt);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
inline std::optional<Tensor> to_meta(const std::optional<Tensor>& t) {
|
| 65 |
+
if (t.has_value()) {
|
| 66 |
+
return to_meta(*t);
|
| 67 |
+
}
|
| 68 |
+
return std::nullopt;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
inline std::vector<Tensor> to_meta(at::ITensorListRef t_list) {
|
| 72 |
+
std::vector<Tensor> outputs;
|
| 73 |
+
outputs.reserve(t_list.size());
|
| 74 |
+
for (const auto& tensor : t_list) {
|
| 75 |
+
outputs.push_back(to_meta(tensor));
|
| 76 |
+
}
|
| 77 |
+
return outputs;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
inline c10::List<Tensor> to_meta(const c10::List<Tensor>& t_list) {
|
| 81 |
+
c10::List<Tensor> outputs;
|
| 82 |
+
outputs.reserve(t_list.size());
|
| 83 |
+
for (const auto i : c10::irange(t_list.size())) {
|
| 84 |
+
outputs.push_back(to_meta(t_list[i]));
|
| 85 |
+
}
|
| 86 |
+
return outputs;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
inline c10::List<::std::optional<Tensor>> to_meta(const c10::List<::std::optional<Tensor>>& t_list) {
|
| 90 |
+
c10::List<::std::optional<Tensor>> outputs;
|
| 91 |
+
outputs.reserve(t_list.size());
|
| 92 |
+
for (const auto i : c10::irange(t_list.size())) {
|
| 93 |
+
outputs.push_back(to_meta(t_list[i]));
|
| 94 |
+
}
|
| 95 |
+
return outputs;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
static bool disable_meta_reference() {
|
| 99 |
+
static auto env = c10::utils::get_env("TORCH_DISABLE_FUNCTIONALIZATION_META_REFERENCE");
|
| 100 |
+
return env == "1";
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
${func_definitions}
|
| 105 |
+
|
| 106 |
+
} // namespace functionalization
|
| 107 |
+
|
| 108 |
+
namespace {
|
| 109 |
+
|
| 110 |
+
TORCH_LIBRARY_IMPL(aten, Functionalize, m) {
|
| 111 |
+
${func_registrations};
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
} // namespace
|
| 115 |
+
|
| 116 |
+
} // namespace at
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegisterSchema.cpp
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ${generated_comment}
|
| 2 |
+
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 3 |
+
#include <torch/library.h>
|
| 4 |
+
|
| 5 |
+
namespace at {
|
| 6 |
+
TORCH_LIBRARY(aten, m) {
|
| 7 |
+
${aten_schema_registrations};
|
| 8 |
+
// Distributed Ops
|
| 9 |
+
// Implementations located in torch/csrc/jit/runtime/register_distributed_ops.cpp
|
| 10 |
+
m.def("get_gradients(int context_id) -> Dict(Tensor, Tensor)");
|
| 11 |
+
}
|
| 12 |
+
${schema_registrations}
|
| 13 |
+
} // namespace at
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/RegistrationDeclarations.h
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// This file contains all native_functions that can be registered to
|
| 2 |
+
// and the schema string that they should be registered with
|
| 3 |
+
|
| 4 |
+
${registration_declarations}
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/TensorBody.h
ADDED
|
@@ -0,0 +1,756 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#ifdef TORCH_ASSERT_NO_OPERATORS
|
| 4 |
+
#error This change adds a dependency on native_functions.yaml, \
|
| 5 |
+
meaning the file will need to be re-compiled every time an operator \
|
| 6 |
+
is changed or added. Consider if your change would be better placed in \
|
| 7 |
+
another file, or if a more specific header might achieve the same goal. \
|
| 8 |
+
See NOTE: [Tensor vs. TensorBase]
|
| 9 |
+
#endif
|
| 10 |
+
|
| 11 |
+
#include <c10/core/Device.h>
|
| 12 |
+
#include <c10/core/Layout.h>
|
| 13 |
+
#include <c10/core/MemoryFormat.h>
|
| 14 |
+
#include <c10/core/QScheme.h>
|
| 15 |
+
#include <c10/core/Stream.h>
|
| 16 |
+
#include <c10/core/Scalar.h>
|
| 17 |
+
#include <c10/core/ScalarType.h>
|
| 18 |
+
#include <c10/core/ScalarTypeToTypeMeta.h>
|
| 19 |
+
#include <c10/core/Storage.h>
|
| 20 |
+
#include <c10/core/TensorImpl.h>
|
| 21 |
+
#include <c10/core/UndefinedTensorImpl.h>
|
| 22 |
+
#include <c10/core/WrapDimMinimal.h>
|
| 23 |
+
#include <c10/util/Exception.h>
|
| 24 |
+
#include <c10/util/ExclusivelyOwned.h>
|
| 25 |
+
#include <c10/util/Deprecated.h>
|
| 26 |
+
#include <c10/util/MaybeOwned.h>
|
| 27 |
+
#include <optional>
|
| 28 |
+
#include <c10/util/OptionalArrayRef.h>
|
| 29 |
+
#include <c10/util/intrusive_ptr.h>
|
| 30 |
+
#include <c10/macros/Export.h>
|
| 31 |
+
#include <c10/macros/Macros.h>
|
| 32 |
+
#include <ATen/core/CheckMemoryFormat.h>
|
| 33 |
+
#include <ATen/core/DeprecatedTypePropertiesRegistry.h>
|
| 34 |
+
#include <ATen/core/DeprecatedTypeProperties.h>
|
| 35 |
+
#include <ATen/core/NamedTensor.h>
|
| 36 |
+
#include <ATen/core/QuantizerBase.h>
|
| 37 |
+
#include <c10/core/SymInt.h>
|
| 38 |
+
#include <ATen/core/TensorAccessor.h>
|
| 39 |
+
#include <ATen/core/TensorBase.h>
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
#include <ATen/MethodOperators.h>
|
| 43 |
+
|
| 44 |
+
namespace c10{
|
| 45 |
+
template<class T> class List;
|
| 46 |
+
template<class T> class IListRef;
|
| 47 |
+
}
|
| 48 |
+
namespace at {
|
| 49 |
+
struct Generator;
|
| 50 |
+
struct Type;
|
| 51 |
+
class DeprecatedTypeProperties;
|
| 52 |
+
class Tensor;
|
| 53 |
+
} // namespace at
|
| 54 |
+
namespace at {
|
| 55 |
+
namespace indexing {
|
| 56 |
+
struct TensorIndex;
|
| 57 |
+
} // namespace indexing
|
| 58 |
+
} // namespace at
|
| 59 |
+
|
| 60 |
+
namespace torch { namespace autograd {
|
| 61 |
+
|
| 62 |
+
struct Node;
|
| 63 |
+
|
| 64 |
+
}} // namespace torch::autograd
|
| 65 |
+
|
| 66 |
+
namespace at {
|
| 67 |
+
|
| 68 |
+
class OptionalTensorRef;
|
| 69 |
+
class TensorRef;
|
| 70 |
+
class Tensor;
|
| 71 |
+
using TensorList = ArrayRef<Tensor>;
|
| 72 |
+
using ITensorList = c10::IListRef<Tensor>;
|
| 73 |
+
|
| 74 |
+
using Stream = c10::Stream;
|
| 75 |
+
|
| 76 |
+
// Tensor is a "generic" object holding a pointer to the underlying TensorImpl object, which
|
| 77 |
+
// has an embedded reference count. In this way, Tensor is similar to boost::intrusive_ptr.
|
| 78 |
+
//
|
| 79 |
+
// For example:
|
| 80 |
+
//
|
| 81 |
+
// void func(Tensor a) {
|
| 82 |
+
// Tensor b = a;
|
| 83 |
+
// ...
|
| 84 |
+
// }
|
| 85 |
+
//
|
| 86 |
+
// In this example, when we say Tensor b = a, we are creating a new object that points to the
|
| 87 |
+
// same underlying TensorImpl, and bumps its reference count. When b goes out of scope, the
|
| 88 |
+
// destructor decrements the reference count by calling release() on the TensorImpl it points to.
|
| 89 |
+
// The existing constructors, operator overloads, etc. take care to implement the correct semantics.
|
| 90 |
+
//
|
| 91 |
+
// Note that Tensor can also be NULL, i.e. it is not associated with any underlying TensorImpl, and
|
| 92 |
+
// special care must be taken to handle this.
|
| 93 |
+
class TORCH_API Tensor: public TensorBase {
|
| 94 |
+
protected:
|
| 95 |
+
// Create a Tensor with a +0 reference count. Special care must be
|
| 96 |
+
// taken to avoid decrementing this reference count at destruction
|
| 97 |
+
// time. Intended to support MaybeOwnedTraits<Tensor>.
|
| 98 |
+
explicit Tensor(unsafe_borrow_t, const TensorBase& rhs): TensorBase(unsafe_borrow_t{}, rhs) {}
|
| 99 |
+
friend MaybeOwnedTraits<Tensor>;
|
| 100 |
+
friend OptionalTensorRef;
|
| 101 |
+
friend TensorRef;
|
| 102 |
+
|
| 103 |
+
public:
|
| 104 |
+
Tensor() = default;
|
| 105 |
+
// This constructor should not be used by end users and is an implementation
|
| 106 |
+
// detail invoked by autogenerated code.
|
| 107 |
+
explicit Tensor(
|
| 108 |
+
c10::intrusive_ptr<TensorImpl, UndefinedTensorImpl> tensor_impl)
|
| 109 |
+
: TensorBase(std::move(tensor_impl)) {}
|
| 110 |
+
Tensor(const Tensor &tensor) = default;
|
| 111 |
+
Tensor(Tensor &&tensor) = default;
|
| 112 |
+
|
| 113 |
+
// Implicitly move-constructible from TensorBase, but must be explicit to increase refcount
|
| 114 |
+
explicit Tensor(const TensorBase &base): TensorBase(base) {}
|
| 115 |
+
/*implicit*/ Tensor(TensorBase &&base): TensorBase(std::move(base)) {}
|
| 116 |
+
|
| 117 |
+
// Creates a new wrapper from TensorImpl. Intentionally a free method because
|
| 118 |
+
// it should be used with care. Checks necessary invariants
|
| 119 |
+
static Tensor wrap_tensor_impl(
|
| 120 |
+
c10::intrusive_ptr<TensorImpl, UndefinedTensorImpl> tensor_impl) {
|
| 121 |
+
return TensorBase::wrap_tensor_impl(std::move(tensor_impl));
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
Tensor contiguous(MemoryFormat memory_format=MemoryFormat::Contiguous) const {
|
| 125 |
+
return TensorBase::contiguous(memory_format);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
Tensor conj() const {
|
| 129 |
+
if (!this->is_complex()) {
|
| 130 |
+
return *this;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wswitch-enum")
|
| 134 |
+
switch (this->layout()) {
|
| 135 |
+
case at::kSparse:
|
| 136 |
+
case at::kSparseCsr:
|
| 137 |
+
case at::kSparseCsc:
|
| 138 |
+
case at::kSparseBsr:
|
| 139 |
+
case at::kSparseBsc:
|
| 140 |
+
return this->conj_physical();
|
| 141 |
+
default:
|
| 142 |
+
return this->_conj();
|
| 143 |
+
}
|
| 144 |
+
C10_DIAGNOSTIC_POP()
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
// Aliased by Dimname overloads, so need explicit using
|
| 148 |
+
using TensorBase::size;
|
| 149 |
+
using TensorBase::sym_size;
|
| 150 |
+
using TensorBase::stride;
|
| 151 |
+
|
| 152 |
+
/// Should be used if *this can reasonably be expected to be contiguous and
|
| 153 |
+
/// performance is important.
|
| 154 |
+
/// Compared to contiguous, it saves a reference count
|
| 155 |
+
/// increment/decrement if *this is already contiguous, at the cost
|
| 156 |
+
/// in all cases of an extra pointer of stack usage, an extra branch
|
| 157 |
+
/// to access, and an extra branch at destruction time.
|
| 158 |
+
c10::MaybeOwned<Tensor> expect_contiguous(MemoryFormat memory_format=MemoryFormat::Contiguous) const &;
|
| 159 |
+
|
| 160 |
+
// Use .contiguous() instead. Trying to borrow from a prvalue Tensor
|
| 161 |
+
// will only lead to trouble and dangling references.
|
| 162 |
+
c10::MaybeOwned<Tensor> expect_contiguous(MemoryFormat memory_format=MemoryFormat::Contiguous) && = delete;
|
| 163 |
+
|
| 164 |
+
// The following overloads are very intriguing. Consider the following
|
| 165 |
+
// program:
|
| 166 |
+
//
|
| 167 |
+
// x[1] = 3;
|
| 168 |
+
//
|
| 169 |
+
// We would expect that the first entry of x is written to 3. But how can we
|
| 170 |
+
// actually achieve this? x[1] evaluates to a tensor...
|
| 171 |
+
//
|
| 172 |
+
// The answer is, using a ref-qualifier. x[1] is an rvalue, which cannot be
|
| 173 |
+
// (profitably) assigned to in the traditional sense, so we overload
|
| 174 |
+
// assignment to mean, "Actually, copy 3 into the tensor data." This is done
|
| 175 |
+
// with an rvalue-reference ref-qualified overload (the methods with && at the
|
| 176 |
+
// end of their type.)
|
| 177 |
+
//
|
| 178 |
+
// There's one more fly in the ointment: We also want
|
| 179 |
+
//
|
| 180 |
+
// Tensor x = y;
|
| 181 |
+
//
|
| 182 |
+
// to work, and we want it NOT to copy. So we need a traditional operator=
|
| 183 |
+
// overload. But we MUST specify a mutable lvalue ref-qualifier, to
|
| 184 |
+
// disambiguate the traditional overload from the rvalue-reference
|
| 185 |
+
// ref-qualified overload. Otherwise, it will be ambiguous, because
|
| 186 |
+
// a non ref-qualified method is eligible for all situations.
|
| 187 |
+
|
| 188 |
+
// Unfortunately, we have to write these constructors out manually
|
| 189 |
+
// to work around an MSVC bug:
|
| 190 |
+
// error C2580: 'at::Tensor &at::Tensor::operator =(const at::Tensor &) &':
|
| 191 |
+
// multiple versions of a defaulted special member functions are not allowed
|
| 192 |
+
// Tensor& operator=(const Tensor&) & = default;
|
| 193 |
+
// Tensor& operator=(Tensor&&) & = default;
|
| 194 |
+
|
| 195 |
+
// Also MSVC will wrongly issue the following warning with the aforementioned fix
|
| 196 |
+
// warning C4522: 'at::Tensor': multiple assignment operators specified
|
| 197 |
+
// Let's just skip the warning.
|
| 198 |
+
//
|
| 199 |
+
// TODO: temporarily disabled
|
| 200 |
+
|
| 201 |
+
Tensor& operator=(const TensorBase& x) & noexcept {
|
| 202 |
+
impl_ = x.getIntrusivePtr();
|
| 203 |
+
return *this;
|
| 204 |
+
}
|
| 205 |
+
Tensor& operator=(TensorBase&& x) & noexcept {
|
| 206 |
+
impl_ = x.unsafeReleaseIntrusivePtr();
|
| 207 |
+
return *this;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
Tensor& operator=(const Tensor &x) & noexcept {
|
| 211 |
+
return operator=(static_cast<const TensorBase&>(x));
|
| 212 |
+
}
|
| 213 |
+
Tensor& operator=(Tensor &&x) & noexcept {
|
| 214 |
+
return operator=(static_cast<TensorBase&&>(x));
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
Tensor& operator=(const Scalar &v) && {
|
| 218 |
+
return fill_(v);
|
| 219 |
+
}
|
| 220 |
+
Tensor& operator=(const Tensor &rhs) && {
|
| 221 |
+
return copy_(rhs);
|
| 222 |
+
}
|
| 223 |
+
Tensor& operator=(Tensor&& rhs) && {
|
| 224 |
+
return copy_(rhs);
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
C10_DEPRECATED_MESSAGE("Tensor.type() is deprecated. Instead use Tensor.options(), which in many cases (e.g. in a constructor) is a drop-in replacement. If you were using data from type(), that is now available from Tensor itself, so instead of tensor.type().scalar_type(), use tensor.scalar_type() instead and instead of tensor.type().backend() use tensor.device().")
|
| 228 |
+
DeprecatedTypeProperties & type() const {
|
| 229 |
+
return globalDeprecatedTypePropertiesRegistry().getDeprecatedTypeProperties(
|
| 230 |
+
dispatchKeyToBackend(legacyExtractDispatchKey(key_set())),
|
| 231 |
+
scalar_type());
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
Tensor toType(ScalarType t) const {
|
| 235 |
+
return to(options().dtype(t), /*non_blocking*/ false, /*copy*/ false);
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
// TODO: Deprecate me
|
| 239 |
+
Tensor toBackend(Backend b) const {
|
| 240 |
+
return to(options().device(backendToDeviceType(b)).layout(layout_from_backend(b)), /*non_blocking*/ false, /*copy*/ false);
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
C10_DEPRECATED_MESSAGE("Tensor.is_variable() is deprecated; everything is a variable now. (If you want to assert that variable has been appropriately handled already, use at::impl::variable_excluded_from_dispatch())")
|
| 244 |
+
bool is_variable() const noexcept {
|
| 245 |
+
return !at::impl::variable_excluded_from_dispatch();
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
template<typename T>
|
| 249 |
+
C10_DEPRECATED_MESSAGE("Tensor.data<T>() is deprecated. Please use Tensor.data_ptr<T>() instead.")
|
| 250 |
+
T * data() const {
|
| 251 |
+
return data_ptr<T>();
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
template <typename T>
|
| 255 |
+
T item() const;
|
| 256 |
+
|
| 257 |
+
template<typename T, size_t N, template <typename U> class PtrTraits = DefaultPtrTraits, typename index_t = int64_t>
|
| 258 |
+
C10_DEPRECATED_MESSAGE("packed_accessor is deprecated, use packed_accessor32 or packed_accessor64 instead")
|
| 259 |
+
GenericPackedTensorAccessor<T,N,PtrTraits,index_t> packed_accessor() const & {
|
| 260 |
+
return generic_packed_accessor<T,N,PtrTraits,index_t>();
|
| 261 |
+
}
|
| 262 |
+
template<typename T, size_t N, template <typename U> class PtrTraits = DefaultPtrTraits, typename index_t = int64_t>
|
| 263 |
+
C10_DEPRECATED_MESSAGE("packed_accessor is deprecated, use packed_accessor32 or packed_accessor64 instead")
|
| 264 |
+
GenericPackedTensorAccessor<T,N,PtrTraits,index_t> packed_accessor() && = delete;
|
| 265 |
+
|
| 266 |
+
Tensor operator~() const {
|
| 267 |
+
return bitwise_not();
|
| 268 |
+
}
|
| 269 |
+
Tensor operator-() const {
|
| 270 |
+
return neg();
|
| 271 |
+
}
|
| 272 |
+
Tensor& operator+=(const Tensor & other) {
|
| 273 |
+
return add_(other);
|
| 274 |
+
}
|
| 275 |
+
Tensor& operator+=(const Scalar & other) {
|
| 276 |
+
return add_(other);
|
| 277 |
+
}
|
| 278 |
+
Tensor& operator-=(const Tensor & other) {
|
| 279 |
+
return sub_(other);
|
| 280 |
+
}
|
| 281 |
+
Tensor& operator-=(const Scalar & other) {
|
| 282 |
+
return sub_(other);
|
| 283 |
+
}
|
| 284 |
+
Tensor& operator*=(const Tensor & other) {
|
| 285 |
+
return mul_(other);
|
| 286 |
+
}
|
| 287 |
+
Tensor& operator*=(const Scalar & other) {
|
| 288 |
+
return mul_(other);
|
| 289 |
+
}
|
| 290 |
+
Tensor& operator/=(const Tensor & other) {
|
| 291 |
+
return div_(other);
|
| 292 |
+
}
|
| 293 |
+
Tensor& operator/=(const Scalar & other) {
|
| 294 |
+
return div_(other);
|
| 295 |
+
}
|
| 296 |
+
Tensor& operator&=(const Tensor & other) {
|
| 297 |
+
return bitwise_and_(other);
|
| 298 |
+
}
|
| 299 |
+
Tensor& operator|=(const Tensor & other) {
|
| 300 |
+
return bitwise_or_(other);
|
| 301 |
+
}
|
| 302 |
+
Tensor& operator^=(const Tensor & other) {
|
| 303 |
+
return bitwise_xor_(other);
|
| 304 |
+
}
|
| 305 |
+
Tensor operator[](const Scalar & index) const {
|
| 306 |
+
if (!index.isIntegral(false)) {
|
| 307 |
+
TORCH_CHECK_INDEX(false, "Can only index tensors with integral scalars");
|
| 308 |
+
}
|
| 309 |
+
return this->operator[](index.toLong());
|
| 310 |
+
}
|
| 311 |
+
Tensor operator[](const Tensor & index) const {
|
| 312 |
+
// These properties are checked in the Scalar constructor, but we already
|
| 313 |
+
// check them here to provide more useful diagnostics for the user.
|
| 314 |
+
if (!index.defined()) {
|
| 315 |
+
TORCH_CHECK_INDEX(false, "Can only index with tensors that are defined");
|
| 316 |
+
}
|
| 317 |
+
if (index.dim() != 0) {
|
| 318 |
+
TORCH_CHECK_INDEX(false,
|
| 319 |
+
"Can only index with tensors that are scalars (zero-dim)");
|
| 320 |
+
}
|
| 321 |
+
// The Scalar(Tensor) constructor is explicit, so we need to call it.
|
| 322 |
+
return this->operator[](index.item());
|
| 323 |
+
}
|
| 324 |
+
Tensor operator[](int64_t index) const {
|
| 325 |
+
return select(0, index);
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
Tensor index(ArrayRef<at::indexing::TensorIndex> indices) const;
|
| 329 |
+
Tensor index(std::initializer_list<at::indexing::TensorIndex> indices) const;
|
| 330 |
+
|
| 331 |
+
Tensor & index_put_(ArrayRef<at::indexing::TensorIndex> indices, Tensor const & rhs);
|
| 332 |
+
Tensor & index_put_(ArrayRef<at::indexing::TensorIndex> indices, const Scalar& v);
|
| 333 |
+
Tensor & index_put_(std::initializer_list<at::indexing::TensorIndex> indices, Tensor const & rhs);
|
| 334 |
+
Tensor & index_put_(std::initializer_list<at::indexing::TensorIndex> indices, const Scalar& v);
|
| 335 |
+
|
| 336 |
+
Tensor cpu() const {
|
| 337 |
+
return to(options().device(c10::DeviceType::CPU), /*non_blocking*/ false, /*copy*/ false);
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
// TODO: The Python version also accepts arguments
|
| 341 |
+
Tensor cuda() const {
|
| 342 |
+
return to(options().device(c10::DeviceType::CUDA), /*non_blocking*/ false, /*copy*/ false);
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
Tensor hip() const {
|
| 346 |
+
return to(options().device(c10::DeviceType::HIP), /*non_blocking*/ false, /*copy*/ false);
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
Tensor ve() const {
|
| 350 |
+
return to(options().device(c10::DeviceType::VE), /*non_blocking*/ false, /*copy*/ false);
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
Tensor vulkan() const {
|
| 354 |
+
return to(options().device(c10::DeviceType::Vulkan), /*non_blocking*/ false, /*copy*/ false);
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
Tensor metal() const {
|
| 358 |
+
return to(options().device(c10::DeviceType::Metal), /*non_blocking*/ false, /*copy*/ false);
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
Tensor meta() const {
|
| 362 |
+
return to(options().device(c10::DeviceType::Meta), /*non_blocking*/ false, /*copy*/ false);
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
// ~~~~~ Autograd API ~~~~~
|
| 366 |
+
|
| 367 |
+
/// \fn bool is_leaf() const;
|
| 368 |
+
///
|
| 369 |
+
/// All Tensors that have `requires_grad()` which is ``false`` will be leaf Tensors by convention.
|
| 370 |
+
///
|
| 371 |
+
/// For Tensors that have `requires_grad()` which is ``true``, they will be leaf Tensors if they were
|
| 372 |
+
/// created by the user. This means that they are not the result of an operation and so
|
| 373 |
+
/// `grad_fn()` is `nullptr`.
|
| 374 |
+
///
|
| 375 |
+
/// Only leaf Tensors will have their `grad()` populated during a call to `backward()`.
|
| 376 |
+
/// To get `grad()` populated for non-leaf Tensors, you can use `retain_grad()`.
|
| 377 |
+
///
|
| 378 |
+
/// Example:
|
| 379 |
+
/// @code
|
| 380 |
+
/// auto a = torch::rand(10, torch::requires_grad());
|
| 381 |
+
/// std::cout << a.is_leaf() << std::endl; // prints `true`
|
| 382 |
+
///
|
| 383 |
+
/// auto b = torch::rand(10, torch::requires_grad()).to(torch::kCUDA);
|
| 384 |
+
/// std::cout << b.is_leaf() << std::endl; // prints `false`
|
| 385 |
+
/// // b was created by the operation that cast a cpu Tensor into a cuda Tensor
|
| 386 |
+
///
|
| 387 |
+
/// auto c = torch::rand(10, torch::requires_grad()) + 2;
|
| 388 |
+
/// std::cout << c.is_leaf() << std::endl; // prints `false`
|
| 389 |
+
/// // c was created by the addition operation
|
| 390 |
+
///
|
| 391 |
+
/// auto d = torch::rand(10).cuda();
|
| 392 |
+
/// std::cout << d.is_leaf() << std::endl; // prints `true`
|
| 393 |
+
/// // d does not require gradients and so has no operation creating it (that is tracked by the autograd engine)
|
| 394 |
+
///
|
| 395 |
+
/// auto e = torch::rand(10).cuda().requires_grad_();
|
| 396 |
+
/// std::cout << e.is_leaf() << std::endl; // prints `true`
|
| 397 |
+
/// // e requires gradients and has no operations creating it
|
| 398 |
+
///
|
| 399 |
+
/// auto f = torch::rand(10, torch::device(torch::kCUDA).requires_grad(true));
|
| 400 |
+
/// std::cout << f.is_leaf() << std::endl; // prints `true`
|
| 401 |
+
/// // f requires grad, has no operation creating it
|
| 402 |
+
/// @endcode
|
| 403 |
+
|
| 404 |
+
/// \fn void backward(const Tensor & gradient={}, std::optional<bool> retain_graph=std::nullopt, bool create_graph=false, std::optional<TensorList> inputs=std::nullopt) const;
|
| 405 |
+
///
|
| 406 |
+
/// Computes the gradient of current tensor with respect to graph leaves.
|
| 407 |
+
///
|
| 408 |
+
/// The graph is differentiated using the chain rule. If the tensor is
|
| 409 |
+
/// non-scalar (i.e. its data has more than one element) and requires
|
| 410 |
+
/// gradient, the function additionally requires specifying ``gradient``.
|
| 411 |
+
/// It should be a tensor of matching type and location, that contains
|
| 412 |
+
/// the gradient of the differentiated function w.r.t. this Tensor.
|
| 413 |
+
///
|
| 414 |
+
/// This function accumulates gradients in the leaves - you might need to
|
| 415 |
+
/// zero them before calling it.
|
| 416 |
+
///
|
| 417 |
+
/// \param gradient Gradient w.r.t. the
|
| 418 |
+
/// tensor. If it is a tensor, it will be automatically converted
|
| 419 |
+
/// to a Tensor that does not require grad unless ``create_graph`` is True.
|
| 420 |
+
/// None values can be specified for scalar Tensors or ones that
|
| 421 |
+
/// don't require grad. If a None value would be acceptable then
|
| 422 |
+
/// this argument is optional.
|
| 423 |
+
/// \param retain_graph If ``false``, the graph used to compute
|
| 424 |
+
/// the grads will be freed. Note that in nearly all cases setting
|
| 425 |
+
/// this option to True is not needed and often can be worked around
|
| 426 |
+
/// in a much more efficient way. Defaults to the value of
|
| 427 |
+
/// ``create_graph``.
|
| 428 |
+
/// \param create_graph If ``true``, graph of the derivative will
|
| 429 |
+
/// be constructed, allowing to compute higher order derivative
|
| 430 |
+
/// products. Defaults to ``false``.
|
| 431 |
+
/// \param inputs Inputs w.r.t. which the gradient will be accumulated into
|
| 432 |
+
/// ``at::Tensor::grad``. All other Tensors will be ignored. If not
|
| 433 |
+
/// provided, the gradient is accumulated into all the leaf Tensors
|
| 434 |
+
/// that were used to compute the current tensor.
|
| 435 |
+
/// When inputs are provided and a given input is not a leaf,
|
| 436 |
+
/// the current implementation will call its grad_fn (even though it is not strictly needed to get this gradients).
|
| 437 |
+
/// It is an implementation detail on which the user should not rely.
|
| 438 |
+
/// See https://github.com/pytorch/pytorch/pull/60521#issuecomment-867061780 for more details.
|
| 439 |
+
void backward(const Tensor & gradient={}, std::optional<bool> retain_graph=std::nullopt, bool create_graph=false, std::optional<TensorList> inputs=std::nullopt) const {
|
| 440 |
+
// NB: Adding this wrapper to _backward here because we'd like our
|
| 441 |
+
// 'backwards' api to accept the 'inputs' argument optionally. Since code gen
|
| 442 |
+
// currently does not support optional of TensorList our approach is to replace
|
| 443 |
+
// backward in native_functions.yaml with _backward and call it here instead.
|
| 444 |
+
if (inputs.has_value()) {
|
| 445 |
+
TORCH_CHECK(inputs.value().size() > 0, "'inputs' argument to backward cannot be empty")
|
| 446 |
+
this->_backward(inputs.value(), gradient, retain_graph, create_graph);
|
| 447 |
+
} else {
|
| 448 |
+
this->_backward({}, gradient, retain_graph, create_graph);
|
| 449 |
+
}
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
/// \fn Tensor detach() const;
|
| 453 |
+
///
|
| 454 |
+
/// Returns a new Tensor, detached from the current graph.
|
| 455 |
+
/// The result will never require gradient.
|
| 456 |
+
|
| 457 |
+
/// \fn Tensor & detach_() const;
|
| 458 |
+
///
|
| 459 |
+
/// Detaches the Tensor from the graph that created it, making it a leaf.
|
| 460 |
+
/// Views cannot be detached in-place.
|
| 461 |
+
|
| 462 |
+
/// \fn void retain_grad() const;
|
| 463 |
+
///
|
| 464 |
+
/// Enables this Tensor to have their :attr:`grad` populated during
|
| 465 |
+
/// :func:`backward`. This is a no-op for leaf tensors.
|
| 466 |
+
|
| 467 |
+
/// \fn bool retains_grad() const;
|
| 468 |
+
///
|
| 469 |
+
/// Is ``true`` if this Tensor is non-leaf and its :attr:`grad` is enabled to be
|
| 470 |
+
/// populated during :func:`backward`, ``false`` otherwise.
|
| 471 |
+
|
| 472 |
+
const Tensor& set_requires_grad(bool requires_grad) const {
|
| 473 |
+
TensorBase::set_requires_grad(requires_grad);
|
| 474 |
+
return *this;
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
/// Return a mutable reference to the gradient. This is conventionally
|
| 478 |
+
/// used as `t.grad() = x` to set a gradient to a completely new tensor.
|
| 479 |
+
/// Note that this function work with a non-const Tensor and is not
|
| 480 |
+
/// thread safe.
|
| 481 |
+
Tensor& mutable_grad() const {
|
| 482 |
+
return impl_->mutable_grad();
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
/// This function returns an undefined tensor by default and returns a defined tensor
|
| 486 |
+
/// the first time a call to `backward()` computes gradients for this Tensor.
|
| 487 |
+
/// The attribute will then contain the gradients computed and future calls
|
| 488 |
+
/// to `backward()` will accumulate (add) gradients into it.
|
| 489 |
+
const Tensor& grad() const {
|
| 490 |
+
const Tensor& maybe_grad = impl_->grad();
|
| 491 |
+
if (!is_leaf() && !retains_grad() && !maybe_grad.defined()) {
|
| 492 |
+
TORCH_WARN(
|
| 493 |
+
"The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad "
|
| 494 |
+
"attribute won't be populated during autograd.backward(). If you indeed want the .grad "
|
| 495 |
+
"field to be populated for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor. "
|
| 496 |
+
"If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor "
|
| 497 |
+
"instead. See github.com/pytorch/pytorch/pull/30531 for more information.");
|
| 498 |
+
}
|
| 499 |
+
return maybe_grad;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
// The Forward AD API functions below are low level and are not to be used by end
|
| 503 |
+
// users who should use the API provided in torch/csrc/autograd.h
|
| 504 |
+
|
| 505 |
+
/// This function returns the forward gradient for this Tensor at the given level.
|
| 506 |
+
const Tensor& _fw_grad(uint64_t level) const {
|
| 507 |
+
return impl_->_fw_grad(level, *this);
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
/// This function can be used to set the value of the forward grad.
|
| 511 |
+
/// Note that the given new_grad might not be used directly if it has different
|
| 512 |
+
/// metadata (size/stride/storage offset) compared to this Tensor. In that case,
|
| 513 |
+
/// new_grad content will be copied into a new Tensor
|
| 514 |
+
void _set_fw_grad(const TensorBase& new_grad, uint64_t level, bool is_inplace_op) const {
|
| 515 |
+
impl_->_set_fw_grad(new_grad, *this, level, is_inplace_op);
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
// STOP. Thinking of adding a method here, which only makes use
|
| 520 |
+
// of other ATen methods? Define it in native_functions.yaml.
|
| 521 |
+
|
| 522 |
+
//example
|
| 523 |
+
//Tensor * add(Tensor & b);
|
| 524 |
+
${tensor_method_declarations}
|
| 525 |
+
|
| 526 |
+
// Special C++ only overloads for std()-like functions (See gh-40287)
|
| 527 |
+
// These are needed because int -> bool conversion takes precedence over int -> IntArrayRef
|
| 528 |
+
// So, for example std(0) would select the std(unbiased=False) overload
|
| 529 |
+
|
| 530 |
+
Tensor var(int dim) const {
|
| 531 |
+
return var(IntArrayRef{dim});
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
Tensor std(int dim) const {
|
| 535 |
+
return std(IntArrayRef{dim});
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
// We changed .dtype() to return a TypeMeta in #12766. Ideally, we want the
|
| 539 |
+
// at::kDouble and its friends to be TypeMeta's, but that hasn't happened yet.
|
| 540 |
+
// Before that change, we make this method to maintain BC for C++ usage like
|
| 541 |
+
// `x.to(y.dtype)`.
|
| 542 |
+
// TODO: remove following two after at::kDouble and its friends are TypeMeta's.
|
| 543 |
+
inline Tensor to(caffe2::TypeMeta type_meta, bool non_blocking=false, bool copy=false) const {
|
| 544 |
+
return this->to(/*scalar_type=*/typeMetaToScalarType(type_meta), non_blocking, copy);
|
| 545 |
+
}
|
| 546 |
+
inline Tensor to(Device device, caffe2::TypeMeta type_meta, bool non_blocking=false, bool copy=false) const {
|
| 547 |
+
return this->to(device, /*scalar_type=*/typeMetaToScalarType(type_meta), non_blocking, copy);
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
template <typename F, typename... Args>
|
| 551 |
+
decltype(auto) m(F func, Args&&... params) const {
|
| 552 |
+
return func(*this, std::forward<Args>(params)...);
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
/// NOTE: This is similar to the legacy `.data()` function on `Variable`, and is intended
|
| 556 |
+
/// to be used from functions that need to access the `Variable`'s equivalent `Tensor`
|
| 557 |
+
/// (i.e. `Tensor` that shares the same storage and tensor metadata with the `Variable`).
|
| 558 |
+
///
|
| 559 |
+
/// One notable difference with the legacy `.data()` function is that changes to the
|
| 560 |
+
/// returned `Tensor`'s tensor metadata (e.g. sizes / strides / storage / storage_offset)
|
| 561 |
+
/// will not update the original `Variable`, due to the fact that this function
|
| 562 |
+
/// shallow-copies the `Variable`'s underlying TensorImpl.
|
| 563 |
+
at::Tensor tensor_data() const {
|
| 564 |
+
return TensorBase::tensor_data();
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
/// NOTE: `var.variable_data()` in C++ has the same semantics as `tensor.data`
|
| 568 |
+
/// in Python, which create a new `Variable` that shares the same storage and
|
| 569 |
+
/// tensor metadata with the original `Variable`, but with a completely new
|
| 570 |
+
/// autograd history.
|
| 571 |
+
///
|
| 572 |
+
/// NOTE: If we change the tensor metadata (e.g. sizes / strides /
|
| 573 |
+
/// storage / storage_offset) of a variable created from `var.variable_data()`, those
|
| 574 |
+
/// changes will not update the original variable `var`. In `.variable_data()`, we set
|
| 575 |
+
/// `allow_tensor_metadata_change_` to false to make such changes explicitly illegal,
|
| 576 |
+
/// in order to prevent users from changing metadata of `var.variable_data()`
|
| 577 |
+
/// and expecting the original variable `var` to also be updated.
|
| 578 |
+
at::Tensor variable_data() const {
|
| 579 |
+
return TensorBase::variable_data();
|
| 580 |
+
}
|
| 581 |
+
|
| 582 |
+
// Hooks
|
| 583 |
+
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 584 |
+
|
| 585 |
+
template <typename T>
|
| 586 |
+
using hook_return_void_t = std::enable_if_t<std::is_void<typename std::invoke_result_t<T&, Tensor>>::value, unsigned>;
|
| 587 |
+
template <typename T>
|
| 588 |
+
using hook_return_var_t = std::enable_if_t<std::is_same_v<typename std::invoke_result_t<T&, Tensor>, Tensor>, unsigned>;
|
| 589 |
+
|
| 590 |
+
/// Registers a backward hook.
|
| 591 |
+
///
|
| 592 |
+
/// The hook will be called every time a gradient with respect to the Tensor is computed.
|
| 593 |
+
/// The hook should have one of the following signature:
|
| 594 |
+
/// ```
|
| 595 |
+
/// hook(Tensor grad) -> Tensor
|
| 596 |
+
/// ```
|
| 597 |
+
/// ```
|
| 598 |
+
/// hook(Tensor grad) -> void
|
| 599 |
+
/// ```
|
| 600 |
+
/// The hook should not modify its argument, but it can optionally return a new gradient
|
| 601 |
+
/// which will be used in place of `grad`.
|
| 602 |
+
///
|
| 603 |
+
/// This function returns the index of the hook in the list which can be used to remove hook.
|
| 604 |
+
///
|
| 605 |
+
/// Example:
|
| 606 |
+
/// @code
|
| 607 |
+
/// auto v = torch::tensor({0., 0., 0.}, torch::requires_grad());
|
| 608 |
+
/// auto h = v.register_hook([](torch::Tensor grad){ return grad * 2; }); // double the gradient
|
| 609 |
+
/// v.backward(torch::tensor({1., 2., 3.}));
|
| 610 |
+
/// // This prints:
|
| 611 |
+
/// // ```
|
| 612 |
+
/// // 2
|
| 613 |
+
/// // 4
|
| 614 |
+
/// // 6
|
| 615 |
+
/// // [ CPUFloatType{3} ]
|
| 616 |
+
/// // ```
|
| 617 |
+
/// std::cout << v.grad() << std::endl;
|
| 618 |
+
/// v.remove_hook(h); // removes the hook
|
| 619 |
+
/// @endcode
|
| 620 |
+
template <typename T>
|
| 621 |
+
hook_return_void_t<T> register_hook(T&& hook) const;
|
| 622 |
+
template <typename T>
|
| 623 |
+
hook_return_var_t<T> register_hook(T&& hook) const;
|
| 624 |
+
|
| 625 |
+
// Variable methods
|
| 626 |
+
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 627 |
+
|
| 628 |
+
Tensor data() const {
|
| 629 |
+
return TensorBase::data();
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
void _backward(TensorList inputs, const std::optional<Tensor>& gradient, std::optional<bool> keep_graph, bool create_graph) const;
|
| 633 |
+
|
| 634 |
+
const Tensor& requires_grad_(bool _requires_grad=true) const {
|
| 635 |
+
TensorBase::requires_grad_(_requires_grad);
|
| 636 |
+
return *this;
|
| 637 |
+
}
|
| 638 |
+
};
|
| 639 |
+
|
| 640 |
+
namespace detail {
|
| 641 |
+
// Helper creator for Tensor class which doesn't requires the users to pass
|
| 642 |
+
// in an intrusive_ptr instead it just converts the argument passed to
|
| 643 |
+
// requested intrusive_ptr type.
|
| 644 |
+
template <typename T, typename... Args>
|
| 645 |
+
Tensor make_tensor(Args&&... args) {
|
| 646 |
+
return Tensor(c10::make_intrusive<T>(std::forward<Args>(args)...));
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
} // namespace detail
|
| 650 |
+
|
| 651 |
+
} // namespace at
|
| 652 |
+
|
| 653 |
+
|
| 654 |
+
namespace at {
|
| 655 |
+
${tensor_method_definitions}
|
| 656 |
+
} // namespace at
|
| 657 |
+
|
| 658 |
+
|
| 659 |
+
namespace c10 {
|
| 660 |
+
template <>
|
| 661 |
+
struct MaybeOwnedTraits<at::Tensor> {
|
| 662 |
+
using owned_type = at::Tensor;
|
| 663 |
+
using borrow_type = at::Tensor;
|
| 664 |
+
|
| 665 |
+
static borrow_type createBorrow(const owned_type& from) {
|
| 666 |
+
// NOTE: this can be implemented without the special
|
| 667 |
+
// unsafe_borrow_t Tensor constructor as
|
| 668 |
+
//
|
| 669 |
+
// return borrow_type(c10::intrusive_ptr<at::TensorImpl, at::UndefinedTensorImpl>::reclaim(from.unsafeGetTensorImpl()));
|
| 670 |
+
//
|
| 671 |
+
// but that hurts inlining due to the nullptr check in the
|
| 672 |
+
// Tensor(c10::intrusive_ptr<...>) constructor. We already know
|
| 673 |
+
// that from.impl_ isn't null because from is a valid Tensor, so
|
| 674 |
+
// we needn't do the check again. (using __builtin_assume can
|
| 675 |
+
// avoid this, but wouldn't be portable to MSVC.)
|
| 676 |
+
return borrow_type(borrow_type::unsafe_borrow_t{}, from);
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
static void assignBorrow(borrow_type& lhs, const borrow_type& rhs) {
|
| 680 |
+
lhs.unsafeReleaseTensorImpl();
|
| 681 |
+
// See above note: this can be implemented with public API
|
| 682 |
+
// similarly to createBorrow(), but that would hurt inlining.
|
| 683 |
+
lhs = borrow_type(borrow_type::unsafe_borrow_t{}, rhs);
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
static void destroyBorrow(borrow_type& toDestroy) {
|
| 687 |
+
toDestroy.unsafeReleaseTensorImpl(); // "leak" it, but it was already +0.
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
static const owned_type& referenceFromBorrow(const borrow_type& borrow) {
|
| 691 |
+
return borrow;
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
static const owned_type* pointerFromBorrow(const borrow_type& borrow) {
|
| 695 |
+
return &borrow;
|
| 696 |
+
}
|
| 697 |
+
|
| 698 |
+
static bool debugBorrowIsValid(const borrow_type& /*borrow*/) {
|
| 699 |
+
return true;
|
| 700 |
+
}
|
| 701 |
+
};
|
| 702 |
+
|
| 703 |
+
template <>
|
| 704 |
+
struct ExclusivelyOwnedTraits<at::Tensor> {
|
| 705 |
+
using repr_type = at::Tensor;
|
| 706 |
+
using pointer_type = at::Tensor*;
|
| 707 |
+
using const_pointer_type = const at::Tensor*;
|
| 708 |
+
|
| 709 |
+
static repr_type nullRepr() {
|
| 710 |
+
return at::Tensor();
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
template <class... Args>
|
| 714 |
+
static repr_type createInPlace(Args&&... args) {
|
| 715 |
+
return at::Tensor(std::forward<Args>(args)...);
|
| 716 |
+
}
|
| 717 |
+
|
| 718 |
+
static repr_type moveToRepr(at::Tensor&& x) {
|
| 719 |
+
return std::move(x);
|
| 720 |
+
}
|
| 721 |
+
|
| 722 |
+
static void destroyOwned(at::Tensor& x) {
|
| 723 |
+
return ExclusivelyOwnedTraits<at::TensorBase>::destroyOwned(x);
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
static at::Tensor take(at::Tensor& x) {
|
| 727 |
+
return std::move(x);
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
static pointer_type getImpl(repr_type& x) {
|
| 731 |
+
return &x;
|
| 732 |
+
}
|
| 733 |
+
|
| 734 |
+
static const_pointer_type getImpl(const repr_type& x) {
|
| 735 |
+
return &x;
|
| 736 |
+
}
|
| 737 |
+
};
|
| 738 |
+
} // namespace c10
|
| 739 |
+
|
| 740 |
+
namespace at {
|
| 741 |
+
|
| 742 |
+
inline c10::MaybeOwned<Tensor> borrow_from_optional_tensor(
|
| 743 |
+
const std::optional<Tensor>& opt) {
|
| 744 |
+
return opt.has_value()
|
| 745 |
+
? c10::MaybeOwned<Tensor>::borrowed(*opt)
|
| 746 |
+
: c10::MaybeOwned<Tensor>::owned(std::in_place);
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
+
inline c10::MaybeOwned<Tensor> Tensor::expect_contiguous(MemoryFormat memory_format) const & {
|
| 750 |
+
if (is_contiguous(memory_format)) {
|
| 751 |
+
return c10::MaybeOwned<Tensor>::borrowed(*this);
|
| 752 |
+
} else {
|
| 753 |
+
return c10::MaybeOwned<Tensor>::owned(__dispatch_contiguous(memory_format));
|
| 754 |
+
}
|
| 755 |
+
}
|
| 756 |
+
} // namespace at
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/TensorMethods.cpp
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <c10/core/Scalar.h>
|
| 2 |
+
#include <ATen/core/TensorBody.h>
|
| 3 |
+
|
| 4 |
+
#include <string_view>
|
| 5 |
+
|
| 6 |
+
namespace at {
|
| 7 |
+
|
| 8 |
+
namespace {
|
| 9 |
+
|
| 10 |
+
// Verifies the requested type is the same as the Tensor's type.
|
| 11 |
+
void check_type(const TensorBase& tensor, ScalarType type, std::string_view type_name) {
|
| 12 |
+
TORCH_CHECK(
|
| 13 |
+
tensor.scalar_type() == type
|
| 14 |
+
|| (isQIntType(tensor.scalar_type())
|
| 15 |
+
&& toUnderlying(tensor.scalar_type()) == type),
|
| 16 |
+
"expected scalar type ", type_name, " but found ", tensor.scalar_type());
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
} // namespace
|
| 20 |
+
|
| 21 |
+
#define DEFINE_CAST(T, name) \
|
| 22 |
+
template <> \
|
| 23 |
+
TORCH_API const T* TensorBase::const_data_ptr() const { \
|
| 24 |
+
check_type(*this, ScalarType::name, #name); \
|
| 25 |
+
return this->unsafeGetTensorImpl()->data_ptr_impl<T>(); \
|
| 26 |
+
} \
|
| 27 |
+
\
|
| 28 |
+
template <> \
|
| 29 |
+
TORCH_API const T* TensorBase::const_data_ptr<const T>() const { \
|
| 30 |
+
check_type(*this, ScalarType::name, #name); \
|
| 31 |
+
return this->unsafeGetTensorImpl()->data_ptr_impl<std::remove_const_t<T>>(); \
|
| 32 |
+
} \
|
| 33 |
+
\
|
| 34 |
+
template <> \
|
| 35 |
+
TORCH_API T* TensorBase::mutable_data_ptr() const { \
|
| 36 |
+
check_type(*this, ScalarType::name, #name); \
|
| 37 |
+
return this->unsafeGetTensorImpl()->mutable_data_ptr_impl<T>(); \
|
| 38 |
+
} \
|
| 39 |
+
\
|
| 40 |
+
template <> \
|
| 41 |
+
TORCH_API T* TensorBase::data_ptr() const { \
|
| 42 |
+
return mutable_data_ptr<T>(); \
|
| 43 |
+
} \
|
| 44 |
+
|
| 45 |
+
AT_FORALL_SCALAR_TYPES_WITH_COMPLEX(DEFINE_CAST)
|
| 46 |
+
AT_FORALL_QINT_TYPES(DEFINE_CAST)
|
| 47 |
+
DEFINE_CAST(uint16_t, UInt16)
|
| 48 |
+
DEFINE_CAST(uint32_t, UInt32)
|
| 49 |
+
DEFINE_CAST(uint64_t, UInt64)
|
| 50 |
+
#undef DEFINE_CAST
|
| 51 |
+
|
| 52 |
+
#define DEFINE_ITEM(T, name) \
|
| 53 |
+
template <> \
|
| 54 |
+
TORCH_API T Tensor::item() const { \
|
| 55 |
+
return item().to##name(); \
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
AT_FORALL_SCALAR_TYPES_WITH_COMPLEX(DEFINE_ITEM)
|
| 59 |
+
#undef DEFINE_ITEM
|
| 60 |
+
|
| 61 |
+
} //namespace at
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/UfuncCPU.cpp
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define TORCH_ASSERT_NO_OPERATORS
|
| 2 |
+
|
| 3 |
+
#include <ATen/native/DispatchStub.h>
|
| 4 |
+
#include <ATen/TensorIterator.h>
|
| 5 |
+
#include <ATen/TensorMeta.h>
|
| 6 |
+
|
| 7 |
+
namespace at {
|
| 8 |
+
|
| 9 |
+
// NB: this is explicitly copied here (via codegen) rather than
|
| 10 |
+
// included via NativeFunctions.h to avoid recompiling this file when
|
| 11 |
+
// NativeFunctions.h changes
|
| 12 |
+
namespace meta {
|
| 13 |
+
${meta_declaration}
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
namespace native {
|
| 17 |
+
${native_declaration}
|
| 18 |
+
${native_definitions}
|
| 19 |
+
}} // namespace at::native
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/UfuncCPUKernel.cpp
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define TORCH_ASSERT_NO_OPERATORS
|
| 2 |
+
|
| 3 |
+
#include <ATen/native/ufunc/${name}.h>
|
| 4 |
+
#include <ATen/native/DispatchStub.h>
|
| 5 |
+
#include <ATen/TensorIterator.h>
|
| 6 |
+
#include <ATen/native/cpu/Loops.h>
|
| 7 |
+
#include <ATen/cpu/vec/vec.h>
|
| 8 |
+
#include <ATen/Dispatch.h>
|
| 9 |
+
#include <c10/core/Scalar.h>
|
| 10 |
+
|
| 11 |
+
namespace at {
|
| 12 |
+
namespace native {
|
| 13 |
+
${native_definitions}
|
| 14 |
+
}} // namespace at::native
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/UfuncCUDA.cu
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define TORCH_ASSERT_NO_OPERATORS
|
| 2 |
+
|
| 3 |
+
#include <ATen/native/ufunc/${name}.h>
|
| 4 |
+
#include <ATen/Dispatch.h>
|
| 5 |
+
#include <ATen/native/DispatchStub.h>
|
| 6 |
+
#include <c10/core/Scalar.h>
|
| 7 |
+
${cuda_headers}
|
| 8 |
+
|
| 9 |
+
namespace at {
|
| 10 |
+
|
| 11 |
+
// NB: this is explicitly copied here (via codegen) rather than
|
| 12 |
+
// included via NativeFunctions.h to avoid recompiling this file when
|
| 13 |
+
// NativeFunctions.h changes
|
| 14 |
+
namespace meta {
|
| 15 |
+
${meta_declaration}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
namespace native {
|
| 19 |
+
${native_declaration}
|
| 20 |
+
${native_definitions}
|
| 21 |
+
}} // namespace at::native
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/UnboxingFunctions.cpp
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <ATen/UnboxingFunctions.h>
|
| 2 |
+
#include <ATen/Functions.h>
|
| 3 |
+
|
| 4 |
+
#include <ATen/Tensor.h>
|
| 5 |
+
#include <ATen/core/functional.h>
|
| 6 |
+
#include <ATen/core/interned_strings.h>
|
| 7 |
+
#include <ATen/core/ivalue.h>
|
| 8 |
+
#include <ATen/core/stack.h>
|
| 9 |
+
|
| 10 |
+
#include <algorithm>
|
| 11 |
+
#include <array>
|
| 12 |
+
#include <cstddef>
|
| 13 |
+
#include <cstring>
|
| 14 |
+
#include <sstream>
|
| 15 |
+
#include <stdexcept>
|
| 16 |
+
#include <tuple>
|
| 17 |
+
#include <unordered_map>
|
| 18 |
+
#include <unordered_set>
|
| 19 |
+
#include <utility>
|
| 20 |
+
#include <vector>
|
| 21 |
+
namespace at {
|
| 22 |
+
namespace unboxing {
|
| 23 |
+
|
| 24 |
+
using ::c10::fmap;
|
| 25 |
+
using ::c10::filter;
|
| 26 |
+
using torch::jit::peek;
|
| 27 |
+
using torch::jit::drop;
|
| 28 |
+
using torch::jit::pack;
|
| 29 |
+
using torch::jit::pop;
|
| 30 |
+
|
| 31 |
+
// Generated function declaration
|
| 32 |
+
${definitions}
|
| 33 |
+
|
| 34 |
+
} // namespace unboxing
|
| 35 |
+
} // namespace at
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/UnboxingFunctions.h
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ${generated_comment}
|
| 2 |
+
|
| 3 |
+
// Generated by tools/jit/gen_unboxing.py. This file declares code generated boxed C++ functions for operators,
|
| 4 |
+
// base off of native_functions.yaml (or similar yaml file with the same syntax). The definition of such a boxed
|
| 5 |
+
// function will pop out IValues from the stack then convert them into the correct C++ types based on given schema. This
|
| 6 |
+
// unboxing logic is an alternative to template-based metaprogramming unboxing.
|
| 7 |
+
|
| 8 |
+
#pragma once
|
| 9 |
+
|
| 10 |
+
#include <ATen/ATen.h>
|
| 11 |
+
namespace at {
|
| 12 |
+
namespace unboxing {
|
| 13 |
+
namespace {
|
| 14 |
+
|
| 15 |
+
template<typename T, size_t N>
|
| 16 |
+
std::array<T, N> as_array(const c10::List<c10::IValue>& list) {
|
| 17 |
+
std::array<T, N> res;
|
| 18 |
+
AT_ASSERT(list.size() == N);
|
| 19 |
+
std::vector<T> vec;
|
| 20 |
+
for (c10::IValue elem : list) {
|
| 21 |
+
vec.push_back(elem.to<T>());
|
| 22 |
+
}
|
| 23 |
+
std::copy(vec.begin(), vec.end(), res.begin());
|
| 24 |
+
return res;
|
| 25 |
+
}
|
| 26 |
+
} // namespace <anonymous>
|
| 27 |
+
using Stack = std::vector<c10::IValue>;
|
| 28 |
+
// Generated function declaration
|
| 29 |
+
${declarations}
|
| 30 |
+
|
| 31 |
+
} // namespace unboxing
|
| 32 |
+
} // namespace at
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/ViewMetaClasses.cpp
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ${generated_comment}
|
| 2 |
+
|
| 3 |
+
#include <ATen/FunctionalInverses.h>
|
| 4 |
+
#include <ATen/ViewMetaClasses.h>
|
| 5 |
+
|
| 6 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 7 |
+
#include <ATen/Operators.h>
|
| 8 |
+
#include <ATen/NativeFunctions.h>
|
| 9 |
+
#else
|
| 10 |
+
${op_headers}
|
| 11 |
+
#endif
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace functionalization {
|
| 15 |
+
|
| 16 |
+
${view_meta_implementations}
|
| 17 |
+
|
| 18 |
+
} // namespace functionalization
|
| 19 |
+
} // namespace at
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/ViewMetaClasses.h
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 2 |
+
// ${generated_comment}
|
| 3 |
+
|
| 4 |
+
#include <ATen/FunctionalStorageImpl.h>
|
| 5 |
+
|
| 6 |
+
namespace at {
|
| 7 |
+
namespace functionalization {
|
| 8 |
+
|
| 9 |
+
${view_meta_declarations}
|
| 10 |
+
|
| 11 |
+
} // namespace functionalization
|
| 12 |
+
} // namespace at
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/ATen/templates/ViewMetaClassesPythonBinding.cpp
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <ATen/ViewMetaClasses.h>
|
| 2 |
+
#include <torch/csrc/functionalization/Module.h>
|
| 3 |
+
|
| 4 |
+
namespace torch::functionalization {
|
| 5 |
+
|
| 6 |
+
void initGenerated(PyObject* module) {
|
| 7 |
+
auto functionalization = py::handle(module).cast<py::module>();
|
| 8 |
+
$view_meta_bindings
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
} // namespace torch::functionalization
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (215 Bytes). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/context.cpython-312.pyc
ADDED
|
Binary file (1.93 kB). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_annotated_fn_args.cpython-312.pyc
ADDED
|
Binary file (6.29 kB). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_autograd.cpython-312.pyc
ADDED
|
Binary file (4.84 kB). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_autograd_functions.cpython-312.pyc
ADDED
|
Binary file (35 kB). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_inplace_or_view_type.cpython-312.pyc
ADDED
|
Binary file (22.5 kB). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_python_functions.cpython-312.pyc
ADDED
|
Binary file (43 kB). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_trace_type.cpython-312.pyc
ADDED
|
Binary file (19.8 kB). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_variable_factories.cpython-312.pyc
ADDED
|
Binary file (5.88 kB). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_variable_type.cpython-312.pyc
ADDED
|
Binary file (70.8 kB). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/gen_view_funcs.cpython-312.pyc
ADDED
|
Binary file (13.9 kB). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/__pycache__/load_derivatives.cpython-312.pyc
ADDED
|
Binary file (38.1 kB). View file
|
|
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/ADInplaceOrViewType.cpp
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 2 |
+
#include "torch/csrc/autograd/VariableTypeUtils.h"
|
| 3 |
+
#include "torch/csrc/autograd/generated/ViewFuncs.h"
|
| 4 |
+
|
| 5 |
+
#include <torch/library.h>
|
| 6 |
+
#include <ATen/FunctionalInverses.h>
|
| 7 |
+
#include <ATen/FunctionalTensorWrapper.h>
|
| 8 |
+
|
| 9 |
+
// ${generated_comment}
|
| 10 |
+
|
| 11 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 12 |
+
#include <ATen/Operators.h>
|
| 13 |
+
#else
|
| 14 |
+
$ops_headers
|
| 15 |
+
#endif
|
| 16 |
+
|
| 17 |
+
using namespace at;
|
| 18 |
+
using torch::autograd::CreationMeta;
|
| 19 |
+
using torch::autograd::as_view;
|
| 20 |
+
using torch::autograd::increment_version;
|
| 21 |
+
|
| 22 |
+
namespace torch {
|
| 23 |
+
|
| 24 |
+
namespace ADInplaceOrView {
|
| 25 |
+
|
| 26 |
+
namespace {
|
| 27 |
+
${inplace_or_view_method_definitions}
|
| 28 |
+
} // namespace
|
| 29 |
+
} // namespace ADInplaceOrView
|
| 30 |
+
|
| 31 |
+
namespace {
|
| 32 |
+
|
| 33 |
+
TORCH_LIBRARY_IMPL(aten, ADInplaceOrView, m) {
|
| 34 |
+
${inplace_or_view_wrapper_registrations};
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
} // namespace
|
| 38 |
+
} // namespace torch
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/Functions.cpp
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "torch/csrc/autograd/FunctionsManual.h"
|
| 2 |
+
#include "torch/csrc/dynamo/compiled_autograd.h"
|
| 3 |
+
|
| 4 |
+
// ${generated_comment}
|
| 5 |
+
|
| 6 |
+
// The manual function definitions that used to be here are now in torch/csrc/autograd/FunctionsManual.cpp
|
| 7 |
+
// This speeds up re-compilation and allow to share these implementations so that they can be
|
| 8 |
+
// used for forward mode AD formulas as well.
|
| 9 |
+
|
| 10 |
+
using namespace torch::autograd::generated::details;
|
| 11 |
+
using at::Tensor;
|
| 12 |
+
using at::Scalar;
|
| 13 |
+
using at::IntArrayRef;
|
| 14 |
+
using at::TensorList;
|
| 15 |
+
|
| 16 |
+
namespace torch::autograd::generated {
|
| 17 |
+
|
| 18 |
+
static at::IValue compute_output_metadata(const torch::autograd::edge_list& next_edges) {
|
| 19 |
+
auto output_metadata = torch::dynamo::autograd::IValuePacker<
|
| 20 |
+
std::vector<std::optional<InputMetadata>>>::pack(
|
| 21 |
+
torch::dynamo::autograd::get_input_metadata(next_edges));
|
| 22 |
+
return output_metadata;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
static C10_NOINLINE variable_list compiled_autograd_apply_functional(
|
| 26 |
+
const PackedArgs& packed_args,
|
| 27 |
+
const edge_list& next_edges,
|
| 28 |
+
SwapSavedVariables& saved,
|
| 29 |
+
const variable_list& grads,
|
| 30 |
+
const std::string& name) {
|
| 31 |
+
auto output_metadata = compute_output_metadata(next_edges);
|
| 32 |
+
const auto& pyinterface = torch::dynamo::autograd::getPyCompilerInterface();
|
| 33 |
+
return pyinterface->call_function(
|
| 34 |
+
saved.get_py_compiler(),
|
| 35 |
+
"apply_functional",
|
| 36 |
+
name,
|
| 37 |
+
grads,
|
| 38 |
+
packed_args.vec(),
|
| 39 |
+
output_metadata);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
${autograd_function_definitions}
|
| 43 |
+
|
| 44 |
+
} // namespace torch::autograd::generated
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/Functions.h
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// ${generated_comment}
|
| 4 |
+
|
| 5 |
+
#include <ATen/ATen.h>
|
| 6 |
+
#include <ATen/core/functional.h>
|
| 7 |
+
#include <ATen/TensorGeometry.h>
|
| 8 |
+
|
| 9 |
+
#include "torch/csrc/autograd/function.h"
|
| 10 |
+
#include "torch/csrc/autograd/variable.h"
|
| 11 |
+
#include "torch/csrc/autograd/saved_variable.h"
|
| 12 |
+
#include <torch/csrc/Export.h>
|
| 13 |
+
|
| 14 |
+
#include <c10/core/SymIntArrayRef.h>
|
| 15 |
+
|
| 16 |
+
namespace torch { namespace autograd { namespace generated {
|
| 17 |
+
|
| 18 |
+
using at::Scalar;
|
| 19 |
+
using at::Tensor;
|
| 20 |
+
using at::IntArrayRef;
|
| 21 |
+
using at::ArrayRef;
|
| 22 |
+
using at::Type;
|
| 23 |
+
using at::TensorGeometry;
|
| 24 |
+
using at::ScalarType;
|
| 25 |
+
using std::optional;
|
| 26 |
+
using c10::fmap;
|
| 27 |
+
|
| 28 |
+
inline std::vector<Tensor> unpack_list(at::ArrayRef<SavedVariable> xs, std::shared_ptr<Node> saved_for = nullptr) {
|
| 29 |
+
// NB: we must explicitly do the conversion in the lambda, otherwise template
|
| 30 |
+
// deduction will give a Tensor of Variable which is not convertible
|
| 31 |
+
return fmap(xs, [&saved_for](const SavedVariable& x) {
|
| 32 |
+
// TODO(crcrpar): Use `std::move(saved_for)` to avoid incrementing refcount, which would need refactoring.
|
| 33 |
+
return static_cast<Tensor>(x.unpack(saved_for));
|
| 34 |
+
});
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
inline c10::List<std::optional<Tensor>> unpack_opt_list(at::ArrayRef<SavedVariable> xs, std::shared_ptr<Node> saved_for = nullptr) {
|
| 38 |
+
torch::List<std::optional<Tensor>> result;
|
| 39 |
+
result.reserve(xs.size());
|
| 40 |
+
for (const SavedVariable& v : xs) {
|
| 41 |
+
auto var = v.unpack(saved_for);
|
| 42 |
+
result.push_back(var.defined() ? std::optional<Tensor>(var) : ::std::nullopt);
|
| 43 |
+
}
|
| 44 |
+
return result;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
using torch::autograd::TypeAndSize;
|
| 48 |
+
|
| 49 |
+
${autograd_function_declarations}
|
| 50 |
+
|
| 51 |
+
}}} // namespace torch::autograd::generated
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/TraceType.cpp
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 2 |
+
#include "torch/csrc/jit/frontend/tracer.h"
|
| 3 |
+
|
| 4 |
+
#include <torch/library.h>
|
| 5 |
+
|
| 6 |
+
#include "torch/csrc/autograd/function.h"
|
| 7 |
+
|
| 8 |
+
#include "ATen/quantized/Quantizer.h"
|
| 9 |
+
|
| 10 |
+
// ${generated_comment}
|
| 11 |
+
|
| 12 |
+
// See the `Tracer` section in `torch/csrc/jit/OVERVIEW.md`.
|
| 13 |
+
// NOTE See [Sharded File] comment in VariableType
|
| 14 |
+
|
| 15 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 16 |
+
#include <ATen/Operators.h>
|
| 17 |
+
#else
|
| 18 |
+
$ops_headers
|
| 19 |
+
#endif
|
| 20 |
+
|
| 21 |
+
using namespace at;
|
| 22 |
+
|
| 23 |
+
namespace torch {
|
| 24 |
+
|
| 25 |
+
namespace TraceType {
|
| 26 |
+
|
| 27 |
+
namespace {
|
| 28 |
+
${trace_method_definitions}
|
| 29 |
+
} // namespace
|
| 30 |
+
} // namespace TraceType
|
| 31 |
+
|
| 32 |
+
namespace {
|
| 33 |
+
|
| 34 |
+
TORCH_LIBRARY_IMPL(aten, Tracer, m) {
|
| 35 |
+
${trace_wrapper_registrations};
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
} // namespace
|
| 39 |
+
|
| 40 |
+
} // namespace torch
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/VariableType.cpp
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "torch/csrc/autograd/VariableTypeUtils.h"
|
| 2 |
+
#include "torch/csrc/autograd/generated/VariableType.h"
|
| 3 |
+
#include "torch/csrc/autograd/FunctionsManual.h"
|
| 4 |
+
|
| 5 |
+
#include <ATen/RedispatchFunctions.h>
|
| 6 |
+
#include <c10/core/impl/TorchDispatchModeTLS.h>
|
| 7 |
+
#include <ATen/core/TorchDispatchUtils.h>
|
| 8 |
+
#include <torch/library.h>
|
| 9 |
+
|
| 10 |
+
#include <ATen/SparseCsrTensorUtils.h>
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
// ${generated_comment}
|
| 14 |
+
|
| 15 |
+
// NOTE [Sharded File]: on this file's split-into-shards state
|
| 16 |
+
//
|
| 17 |
+
// Back in the good old days, VariableType.cpp was generated as one
|
| 18 |
+
// file with every function in it, and everything was great and
|
| 19 |
+
// simple.
|
| 20 |
+
//
|
| 21 |
+
// However, this file was also very large (over 36,000 lines), and
|
| 22 |
+
// compiling it was very slow, and in fact was a significant
|
| 23 |
+
// bottleneck for incremental rebuilds. To address this, we now
|
| 24 |
+
// generate the file split across multiple shards, named
|
| 25 |
+
// VariableType_0.cpp and so on, which can be compiled in parallel.
|
| 26 |
+
//
|
| 27 |
+
// For ease of inspection and debugging, so that it's not necessary to
|
| 28 |
+
// go rooting around in multiple files, we also generate all the
|
| 29 |
+
// functions together in VariableTypeEverything.cpp. This generated
|
| 30 |
+
// file is only for convenience; it's not actually used in the
|
| 31 |
+
// build. If the file you're looking at now is one of the shards, you
|
| 32 |
+
// may want to switch over to the Everything variant to make you
|
| 33 |
+
// grepping smoother.
|
| 34 |
+
|
| 35 |
+
using namespace at;
|
| 36 |
+
using namespace torch::autograd::generated;
|
| 37 |
+
using namespace torch::autograd::generated::details;
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
namespace torch::autograd {
|
| 41 |
+
|
| 42 |
+
namespace VariableType {
|
| 43 |
+
namespace{
|
| 44 |
+
[[maybe_unused]] void reset_grad_accumulator(Variable& self) {
|
| 45 |
+
AutogradMeta* meta = torch::autograd::impl::get_autograd_meta(self);
|
| 46 |
+
if (meta != nullptr) {
|
| 47 |
+
meta->grad_accumulator_.reset();
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
[[maybe_unused]] size_t expected_fresh_use_count(const Variable& self) {
|
| 51 |
+
if (!self.defined()) {
|
| 52 |
+
// An UndefinedTensorImpl always has a use count of 0
|
| 53 |
+
return 0;
|
| 54 |
+
}
|
| 55 |
+
if (self.unsafeGetTensorImpl()->pyobj_slot()->load_pyobj() != nullptr) {
|
| 56 |
+
// A TensorImpl with a Python object has a use count of 2
|
| 57 |
+
return 2;
|
| 58 |
+
}
|
| 59 |
+
// A fresh TensorImpl (with no PyObject) has a use count of 1
|
| 60 |
+
return 1;
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
namespace {
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
${type_derived_method_definitions}
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
namespace {
|
| 72 |
+
|
| 73 |
+
${wrapper_registrations}
|
| 74 |
+
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
} // namespace torch::autograd
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/VariableType.h
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// ${generated_comment}
|
| 4 |
+
|
| 5 |
+
#include <ATen/core/Tensor.h>
|
| 6 |
+
#include <ATen/Context.h>
|
| 7 |
+
|
| 8 |
+
#include <c10/util/intrusive_ptr.h>
|
| 9 |
+
|
| 10 |
+
#include <torch/csrc/Export.h>
|
| 11 |
+
#include <torch/csrc/autograd/autograd_not_implemented_fallback.h>
|
| 12 |
+
|
| 13 |
+
#include <cstdint> // for size_t
|
| 14 |
+
#include <functional> // for function
|
| 15 |
+
#include <memory> // for unique_ptr
|
| 16 |
+
#include <string>
|
| 17 |
+
#include <vector>
|
| 18 |
+
|
| 19 |
+
namespace at {
|
| 20 |
+
struct Quantizer;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
namespace torch { namespace autograd {
|
| 24 |
+
|
| 25 |
+
using Variable = at::Tensor;
|
| 26 |
+
using at::Context;
|
| 27 |
+
using at::Device;
|
| 28 |
+
using at::Dimname;
|
| 29 |
+
using at::DimnameList;
|
| 30 |
+
using at::Generator;
|
| 31 |
+
using at::IntArrayRef;
|
| 32 |
+
using at::MemoryFormat;
|
| 33 |
+
using at::QScheme;
|
| 34 |
+
using at::Scalar;
|
| 35 |
+
using at::ScalarType;
|
| 36 |
+
using at::Storage;
|
| 37 |
+
using at::Tensor;
|
| 38 |
+
using at::TensorList;
|
| 39 |
+
using at::TensorOptions;
|
| 40 |
+
using at::Quantizer;
|
| 41 |
+
using std::optional;
|
| 42 |
+
|
| 43 |
+
namespace VariableType {
|
| 44 |
+
TORCH_API std::vector<at::DeprecatedTypeProperties*> allCUDATypes();
|
| 45 |
+
TORCH_API std::vector<at::DeprecatedTypeProperties*> allXPUTypes();
|
| 46 |
+
TORCH_API std::vector<at::DeprecatedTypeProperties*> allCPUTypes();
|
| 47 |
+
TORCH_API std::vector<at::DeprecatedTypeProperties*> allPrivateUser1Types();
|
| 48 |
+
|
| 49 |
+
at::Tensor & unpack(Tensor & t, const char * name, int pos);
|
| 50 |
+
const at::Tensor & unpack(const Tensor & t, const char * name, int pos);
|
| 51 |
+
at::Tensor unpack_opt(const Tensor & t, const char * name, int pos);
|
| 52 |
+
std::vector<at::Tensor> unpack(const at::ITensorListRef& tl, const char *name, int pos);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
}} // namespace torch::autograd
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/ViewFuncs.cpp
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <torch/csrc/autograd/generated/ViewFuncs.h>
|
| 2 |
+
|
| 3 |
+
// ${generated_comment}
|
| 4 |
+
|
| 5 |
+
using at::Tensor;
|
| 6 |
+
using at::Scalar;
|
| 7 |
+
using at::IntArrayRef;
|
| 8 |
+
using at::TensorList;
|
| 9 |
+
|
| 10 |
+
namespace torch::autograd::generated {
|
| 11 |
+
|
| 12 |
+
${view_func_definitions}
|
| 13 |
+
|
| 14 |
+
} // namespace torch::autograd::generated
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/ViewFuncs.h
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// ${generated_comment}
|
| 4 |
+
|
| 5 |
+
#include <torch/library.h>
|
| 6 |
+
#include <torch/csrc/autograd/variable.h>
|
| 7 |
+
#include <c10/core/SymIntArrayRef.h>
|
| 8 |
+
|
| 9 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 10 |
+
#include <ATen/Operators.h>
|
| 11 |
+
#else
|
| 12 |
+
$ops_headers
|
| 13 |
+
#endif
|
| 14 |
+
|
| 15 |
+
namespace torch::autograd::generated {
|
| 16 |
+
|
| 17 |
+
using at::Scalar;
|
| 18 |
+
using at::Tensor;
|
| 19 |
+
using at::IntArrayRef;
|
| 20 |
+
using at::ArrayRef;
|
| 21 |
+
using at::Type;
|
| 22 |
+
using at::ScalarType;
|
| 23 |
+
using std::optional;
|
| 24 |
+
using c10::fmap;
|
| 25 |
+
|
| 26 |
+
${view_func_declarations}
|
| 27 |
+
|
| 28 |
+
} // namespace torch::autograd::generated
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/annotated_fn_args.py.in
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This file is needed for generating procedural tests required for
|
| 3 |
+
testing __torch_function__. See tests/test_overrides.py.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
# flake8: noqa
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
annotated_args = {
|
| 10 |
+
${annotated_args}
|
| 11 |
+
}
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_enum_tag.cpp
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <torch/csrc/autograd/python_enum_tag.h>
|
| 2 |
+
#include <torch/csrc/utils/pybind.h>
|
| 3 |
+
#include <pybind11/pybind11.h>
|
| 4 |
+
#include <ATen/core/enum_tag.h>
|
| 5 |
+
|
| 6 |
+
namespace py = pybind11;
|
| 7 |
+
namespace torch {
|
| 8 |
+
namespace autograd {
|
| 9 |
+
void initEnumTag(PyObject* module) {
|
| 10 |
+
auto m = py::handle(module).cast<py::module>();
|
| 11 |
+
py::enum_<at::Tag>(m, "Tag")
|
| 12 |
+
${enum_of_valid_tags};
|
| 13 |
+
m.doc() = "An Enum that contains tags that can be assigned to an operator registered in C++.";
|
| 14 |
+
}
|
| 15 |
+
}}
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_fft_functions.cpp
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 2 |
+
// ${generated_comment}
|
| 3 |
+
|
| 4 |
+
#include "torch/csrc/Device.h"
|
| 5 |
+
#include "torch/csrc/DynamicTypes.h"
|
| 6 |
+
#include "torch/csrc/Exceptions.h"
|
| 7 |
+
#include "torch/csrc/autograd/python_fft_functions.h"
|
| 8 |
+
#include "torch/csrc/autograd/generated/python_return_types.h"
|
| 9 |
+
#include "torch/csrc/autograd/python_variable.h"
|
| 10 |
+
#include "torch/csrc/autograd/utils/wrap_outputs.h"
|
| 11 |
+
#include "torch/csrc/autograd/utils/python_arg_parsing.h"
|
| 12 |
+
#include "torch/csrc/autograd/generated/variable_factories.h"
|
| 13 |
+
#include "torch/csrc/utils/out_types.h"
|
| 14 |
+
#include "torch/csrc/utils/pycfunction_helpers.h"
|
| 15 |
+
#include "torch/csrc/utils/python_arg_parser.h"
|
| 16 |
+
#include "torch/csrc/utils/structseq.h"
|
| 17 |
+
#include "torch/csrc/utils/device_lazy_init.h"
|
| 18 |
+
|
| 19 |
+
#include <ATen/core/Tensor.h>
|
| 20 |
+
|
| 21 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 22 |
+
#include <ATen/Functions.h>
|
| 23 |
+
#else
|
| 24 |
+
$ops_headers
|
| 25 |
+
#endif
|
| 26 |
+
|
| 27 |
+
using at::Tensor;
|
| 28 |
+
using at::Device;
|
| 29 |
+
using at::Layout;
|
| 30 |
+
using at::Scalar;
|
| 31 |
+
using at::ScalarType;
|
| 32 |
+
using at::Backend;
|
| 33 |
+
using at::OptionalDeviceGuard;
|
| 34 |
+
using at::DeviceGuard;
|
| 35 |
+
using at::TensorOptions;
|
| 36 |
+
using at::IntArrayRef;
|
| 37 |
+
using at::Generator;
|
| 38 |
+
using at::TensorList;
|
| 39 |
+
using at::Dimname;
|
| 40 |
+
using at::DimnameList;
|
| 41 |
+
|
| 42 |
+
using torch::utils::check_out_type_matches;
|
| 43 |
+
using namespace torch::autograd::utils;
|
| 44 |
+
|
| 45 |
+
namespace torch::autograd {
|
| 46 |
+
|
| 47 |
+
// generated forward declarations start here
|
| 48 |
+
|
| 49 |
+
${py_forwards}
|
| 50 |
+
|
| 51 |
+
static PyMethodDef fft_functions[] = {
|
| 52 |
+
${py_method_defs}
|
| 53 |
+
{NULL}
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
static PyObject* THPFFTVariableFunctionsModule = NULL;
|
| 57 |
+
|
| 58 |
+
void initFFTFunctions(PyObject* module) {
|
| 59 |
+
static struct PyModuleDef def = {
|
| 60 |
+
PyModuleDef_HEAD_INIT,
|
| 61 |
+
"torch._C._fft",
|
| 62 |
+
NULL,
|
| 63 |
+
-1,
|
| 64 |
+
fft_functions
|
| 65 |
+
};
|
| 66 |
+
PyObject* fft = PyModule_Create(&def);
|
| 67 |
+
THPFFTVariableFunctionsModule = fft;
|
| 68 |
+
if (!fft) {
|
| 69 |
+
throw python_error();
|
| 70 |
+
}
|
| 71 |
+
// steals a reference to fft
|
| 72 |
+
if (PyModule_AddObject(module, "_fft", fft) != 0) {
|
| 73 |
+
throw python_error();
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
// generated methods start here
|
| 78 |
+
|
| 79 |
+
${py_methods}
|
| 80 |
+
|
| 81 |
+
} // namespace torch::autograd
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_functions.cpp
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <torch/csrc/autograd/generated/python_functions.h>
|
| 2 |
+
|
| 3 |
+
// ${generated_comment}
|
| 4 |
+
|
| 5 |
+
#include <Python.h>
|
| 6 |
+
#include <ATen/ATen.h>
|
| 7 |
+
|
| 8 |
+
#include <c10/core/SymNodeImpl.h>
|
| 9 |
+
#include "torch/csrc/autograd/generated/Functions.h"
|
| 10 |
+
#include "torch/csrc/autograd/python_cpp_function.h"
|
| 11 |
+
#include <torch/csrc/autograd/python_variable.h>
|
| 12 |
+
#include <torch/csrc/autograd/saved_variable.h>
|
| 13 |
+
#include <torch/csrc/utils/pybind.h>
|
| 14 |
+
#include <pybind11/pybind11.h>
|
| 15 |
+
#include <torch/csrc/utils/pybind.h>
|
| 16 |
+
|
| 17 |
+
// NOTE: See [Sharded File] comment in VariableType
|
| 18 |
+
|
| 19 |
+
namespace torch::autograd::generated {
|
| 20 |
+
|
| 21 |
+
template<typename C>
|
| 22 |
+
static void addClass(PyObject* module, PyTypeObject& type, const char* name,
|
| 23 |
+
PyGetSetDef* function_properties=NULL, PyMethodDef* function_methods=NULL)
|
| 24 |
+
{
|
| 25 |
+
_initFunctionPyTypeObject(type, name, function_properties, function_methods);
|
| 26 |
+
Py_INCREF(&type);
|
| 27 |
+
PyModule_AddObject(module, name, (PyObject*)&type);
|
| 28 |
+
registerCppFunction(typeid(C), &type);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
${py_function_props_and_getters}
|
| 32 |
+
|
| 33 |
+
void initialize_autogenerated_functions${shard_id}(PyObject* module) {
|
| 34 |
+
${py_function_initializers}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
} // namespace torch::autograd::generated
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_functions.h
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <Python.h>
|
| 4 |
+
|
| 5 |
+
// ${generated_comment}
|
| 6 |
+
|
| 7 |
+
// Python bindings for automatically generated autograd functions
|
| 8 |
+
|
| 9 |
+
namespace torch { namespace autograd { namespace generated {
|
| 10 |
+
|
| 11 |
+
${shard_forward_declare}
|
| 12 |
+
|
| 13 |
+
inline void initialize_autogenerated_functions(PyObject* module) {
|
| 14 |
+
${shard_call}
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
}}} // namespace torch::autograd::generated
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_linalg_functions.cpp
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 2 |
+
// ${generated_comment}
|
| 3 |
+
|
| 4 |
+
#include "torch/csrc/Device.h"
|
| 5 |
+
#include "torch/csrc/DynamicTypes.h"
|
| 6 |
+
#include "torch/csrc/Exceptions.h"
|
| 7 |
+
#include "torch/csrc/autograd/python_linalg_functions.h"
|
| 8 |
+
#include "torch/csrc/autograd/generated/python_return_types.h"
|
| 9 |
+
#include "torch/csrc/autograd/python_variable.h"
|
| 10 |
+
#include "torch/csrc/autograd/utils/wrap_outputs.h"
|
| 11 |
+
#include "torch/csrc/autograd/utils/python_arg_parsing.h"
|
| 12 |
+
#include "torch/csrc/utils/pycfunction_helpers.h"
|
| 13 |
+
#include "torch/csrc/utils/python_arg_parser.h"
|
| 14 |
+
#include "torch/csrc/utils/structseq.h"
|
| 15 |
+
|
| 16 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 17 |
+
#include <ATen/Functions.h>
|
| 18 |
+
#else
|
| 19 |
+
$ops_headers
|
| 20 |
+
#endif
|
| 21 |
+
|
| 22 |
+
using at::Tensor;
|
| 23 |
+
using at::Scalar;
|
| 24 |
+
using at::ScalarType;
|
| 25 |
+
using at::MemoryFormat;
|
| 26 |
+
using at::Generator;
|
| 27 |
+
using at::IntArrayRef;
|
| 28 |
+
using at::TensorList;
|
| 29 |
+
|
| 30 |
+
using namespace torch::autograd::utils;
|
| 31 |
+
|
| 32 |
+
namespace torch::autograd {
|
| 33 |
+
|
| 34 |
+
// generated forward declarations start here
|
| 35 |
+
|
| 36 |
+
${py_forwards}
|
| 37 |
+
|
| 38 |
+
static PyMethodDef linalg_functions[] = {
|
| 39 |
+
${py_method_defs}
|
| 40 |
+
{NULL}
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
static PyObject* THPLinalgVariableFunctionsModule = NULL;
|
| 44 |
+
|
| 45 |
+
void initLinalgFunctions(PyObject* module) {
|
| 46 |
+
static struct PyModuleDef def = {
|
| 47 |
+
PyModuleDef_HEAD_INIT,
|
| 48 |
+
"torch._C._linalg",
|
| 49 |
+
NULL,
|
| 50 |
+
-1,
|
| 51 |
+
linalg_functions
|
| 52 |
+
};
|
| 53 |
+
PyObject* linalg = PyModule_Create(&def);
|
| 54 |
+
THPLinalgVariableFunctionsModule = linalg;
|
| 55 |
+
if (!linalg) {
|
| 56 |
+
throw python_error();
|
| 57 |
+
}
|
| 58 |
+
// steals a reference to linalg
|
| 59 |
+
if (PyModule_AddObject(module, "_linalg", linalg) != 0) {
|
| 60 |
+
throw python_error();
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// generated methods start here
|
| 65 |
+
|
| 66 |
+
${py_methods}
|
| 67 |
+
|
| 68 |
+
} // namespace torch::autograd
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_nested_functions.cpp
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 2 |
+
// ${generated_comment}
|
| 3 |
+
|
| 4 |
+
#include "torch/csrc/Device.h"
|
| 5 |
+
#include "torch/csrc/DynamicTypes.h"
|
| 6 |
+
#include "torch/csrc/Exceptions.h"
|
| 7 |
+
#include "torch/csrc/autograd/python_nested_functions.h"
|
| 8 |
+
#include "torch/csrc/autograd/generated/python_return_types.h"
|
| 9 |
+
#include "torch/csrc/autograd/python_variable.h"
|
| 10 |
+
#include "torch/csrc/autograd/utils/wrap_outputs.h"
|
| 11 |
+
#include "torch/csrc/autograd/utils/python_arg_parsing.h"
|
| 12 |
+
#include "torch/csrc/autograd/generated/variable_factories.h"
|
| 13 |
+
#include "torch/csrc/utils/out_types.h"
|
| 14 |
+
#include "torch/csrc/utils/pycfunction_helpers.h"
|
| 15 |
+
#include "torch/csrc/utils/python_arg_parser.h"
|
| 16 |
+
#include "torch/csrc/utils/structseq.h"
|
| 17 |
+
#include "torch/csrc/utils/device_lazy_init.h"
|
| 18 |
+
|
| 19 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 20 |
+
#include <ATen/Functions.h>
|
| 21 |
+
#else
|
| 22 |
+
$ops_headers
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
using at::Tensor;
|
| 26 |
+
using at::Device;
|
| 27 |
+
using at::Layout;
|
| 28 |
+
using at::Scalar;
|
| 29 |
+
using at::ScalarType;
|
| 30 |
+
using at::Backend;
|
| 31 |
+
using at::OptionalDeviceGuard;
|
| 32 |
+
using at::DeviceGuard;
|
| 33 |
+
using at::TensorOptions;
|
| 34 |
+
using at::IntArrayRef;
|
| 35 |
+
using at::OptionalIntArrayRef;
|
| 36 |
+
using at::Generator;
|
| 37 |
+
using at::TensorList;
|
| 38 |
+
using at::Dimname;
|
| 39 |
+
using at::DimnameList;
|
| 40 |
+
|
| 41 |
+
using namespace torch::autograd::utils;
|
| 42 |
+
|
| 43 |
+
namespace torch::autograd {
|
| 44 |
+
|
| 45 |
+
// generated forward declarations start here
|
| 46 |
+
|
| 47 |
+
${py_forwards}
|
| 48 |
+
|
| 49 |
+
static PyMethodDef nested_functions[] = {
|
| 50 |
+
{NULL, NULL, 0, NULL},
|
| 51 |
+
${py_method_defs}
|
| 52 |
+
{NULL}
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
static PyObject* THPNestedVariableFunctionsModule = NULL;
|
| 56 |
+
|
| 57 |
+
void initNestedFunctions(PyObject* module) {
|
| 58 |
+
nested_functions[0] = get_nested_functions_manual()[0];
|
| 59 |
+
static struct PyModuleDef def = {
|
| 60 |
+
PyModuleDef_HEAD_INIT,
|
| 61 |
+
"torch._C._nested",
|
| 62 |
+
NULL,
|
| 63 |
+
-1,
|
| 64 |
+
nested_functions
|
| 65 |
+
};
|
| 66 |
+
PyObject* nested = PyModule_Create(&def);
|
| 67 |
+
THPNestedVariableFunctionsModule = nested;
|
| 68 |
+
if (!nested) {
|
| 69 |
+
throw python_error();
|
| 70 |
+
}
|
| 71 |
+
// steals a reference to nested
|
| 72 |
+
if (PyModule_AddObject(module, "_nested", nested) != 0) {
|
| 73 |
+
throw python_error();
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
// generated methods start here
|
| 78 |
+
|
| 79 |
+
${py_methods}
|
| 80 |
+
|
| 81 |
+
} // namespace torch::autograd
|
TTS/Kokoro/.venv/Lib/site-packages/torchgen/packaged/autograd/templates/python_nn_functions.cpp
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
|
| 2 |
+
// ${generated_comment}
|
| 3 |
+
|
| 4 |
+
#include "torch/csrc/Device.h"
|
| 5 |
+
#include "torch/csrc/DynamicTypes.h"
|
| 6 |
+
#include "torch/csrc/Exceptions.h"
|
| 7 |
+
#include "torch/csrc/autograd/python_nn_functions.h"
|
| 8 |
+
#include "torch/csrc/autograd/generated/python_return_types.h"
|
| 9 |
+
#include "torch/csrc/autograd/python_variable.h"
|
| 10 |
+
#include "torch/csrc/autograd/utils/wrap_outputs.h"
|
| 11 |
+
#include "torch/csrc/autograd/utils/python_arg_parsing.h"
|
| 12 |
+
#include "torch/csrc/utils/pycfunction_helpers.h"
|
| 13 |
+
#include "torch/csrc/utils/python_arg_parser.h"
|
| 14 |
+
#include "torch/csrc/utils/structseq.h"
|
| 15 |
+
#include "torch/csrc/utils/tensor_memoryformats.h"
|
| 16 |
+
|
| 17 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 18 |
+
#include <ATen/Functions.h>
|
| 19 |
+
#else
|
| 20 |
+
$ops_headers
|
| 21 |
+
#endif
|
| 22 |
+
|
| 23 |
+
using at::Tensor;
|
| 24 |
+
using at::Scalar;
|
| 25 |
+
using at::MemoryFormat;
|
| 26 |
+
using at::Generator;
|
| 27 |
+
using at::IntArrayRef;
|
| 28 |
+
using at::ArrayRef;
|
| 29 |
+
|
| 30 |
+
using namespace torch::autograd::utils;
|
| 31 |
+
|
| 32 |
+
namespace torch::autograd {
|
| 33 |
+
|
| 34 |
+
static PyObject* THPNNVariableFunctionsModule = nullptr;
|
| 35 |
+
|
| 36 |
+
static PyObject * THPVariable__parse_to(PyObject* module, PyObject* args, PyObject* kwargs)
|
| 37 |
+
{
|
| 38 |
+
HANDLE_TH_ERRORS
|
| 39 |
+
static PythonArgParser parser({
|
| 40 |
+
"to(Device device=None, ScalarType dtype=None, bool non_blocking=False, bool copy=False, *, MemoryFormat? memory_format=None)",
|
| 41 |
+
"to(ScalarType dtype, bool non_blocking=False, bool copy=False, *, MemoryFormat? memory_format=None)",
|
| 42 |
+
"to(Tensor tensor, bool non_blocking=False, bool copy=False, *, MemoryFormat? memory_format=None)",
|
| 43 |
+
});
|
| 44 |
+
ParsedArgs<5> parsed_args;
|
| 45 |
+
auto r = parser.parse(args, kwargs, parsed_args);
|
| 46 |
+
if (r.has_torch_function()) {
|
| 47 |
+
return handle_torch_function(r, args, kwargs, THPNNVariableFunctionsModule, "torch.nn", "_parse_to");
|
| 48 |
+
}
|
| 49 |
+
auto parsed = parse_to_conversion(r, /*allow_copy*/ false); // we don't want copy for nn.Module.to
|
| 50 |
+
auto& device = std::get<0>(parsed);
|
| 51 |
+
auto& scalarType = std::get<1>(parsed);
|
| 52 |
+
auto non_blocking = std::get<2>(parsed);
|
| 53 |
+
auto opt_memory_format = std::get<4>(parsed);
|
| 54 |
+
auto tuple = THPObjectPtr{PyTuple_New(4)};
|
| 55 |
+
if (!tuple) throw python_error();
|
| 56 |
+
if (device) {
|
| 57 |
+
PyTuple_SET_ITEM(tuple.get(), 0, THPDevice_New(*device));
|
| 58 |
+
} else {
|
| 59 |
+
Py_INCREF(Py_None);
|
| 60 |
+
PyTuple_SET_ITEM(tuple.get(), 0, Py_None);
|
| 61 |
+
}
|
| 62 |
+
if (scalarType) {
|
| 63 |
+
PyTuple_SET_ITEM(tuple.get(), 1, Py_NewRef(torch::getTHPDtype(*scalarType)));
|
| 64 |
+
} else {
|
| 65 |
+
Py_INCREF(Py_None);
|
| 66 |
+
PyTuple_SET_ITEM(tuple.get(), 1, Py_None);
|
| 67 |
+
}
|
| 68 |
+
PyTuple_SET_ITEM(tuple.get(), 2, torch::autograd::utils::wrap(non_blocking));
|
| 69 |
+
if (opt_memory_format.has_value()) {
|
| 70 |
+
PyTuple_SET_ITEM(tuple.get(), 3, Py_NewRef(torch::utils::getTHPMemoryFormat(opt_memory_format.value())));
|
| 71 |
+
} else {
|
| 72 |
+
Py_INCREF(Py_None);
|
| 73 |
+
PyTuple_SET_ITEM(tuple.get(), 3, Py_None);
|
| 74 |
+
}
|
| 75 |
+
return tuple.release();
|
| 76 |
+
END_HANDLE_TH_ERRORS
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// generated forward declarations start here
|
| 80 |
+
|
| 81 |
+
${py_forwards}
|
| 82 |
+
|
| 83 |
+
static PyMethodDef nn_functions[] = {
|
| 84 |
+
{"_parse_to", castPyCFunctionWithKeywords(THPVariable__parse_to),
|
| 85 |
+
METH_VARARGS | METH_KEYWORDS, nullptr},
|
| 86 |
+
${py_method_defs}
|
| 87 |
+
{nullptr}
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
void initNNFunctions(PyObject* module) {
|
| 91 |
+
static struct PyModuleDef def = {
|
| 92 |
+
PyModuleDef_HEAD_INIT,
|
| 93 |
+
"torch._C._nn",
|
| 94 |
+
nullptr,
|
| 95 |
+
-1,
|
| 96 |
+
nn_functions
|
| 97 |
+
};
|
| 98 |
+
PyObject* nn = PyModule_Create(&def);
|
| 99 |
+
THPNNVariableFunctionsModule = nn;
|
| 100 |
+
if (!nn) {
|
| 101 |
+
throw python_error();
|
| 102 |
+
}
|
| 103 |
+
// steals a reference to nn
|
| 104 |
+
if (PyModule_AddObject(module, "_nn", nn) != 0) {
|
| 105 |
+
throw python_error();
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
// generated methods start here
|
| 110 |
+
|
| 111 |
+
${py_methods}
|
| 112 |
+
|
| 113 |
+
} // namespace torch::autograd
|