Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/BatchLinearAlgebra.h +321 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/CompositeRandomAccessorCommon.h +263 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/ConvolutionMM3d.h +14 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/DilatedConvolutionUtils.h +229 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/Fill.h +21 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/Lerp.h +46 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/LossMulti.h +72 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/Repeat.h +48 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/ScatterGatherChecks.h +128 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/SegmentReduce.h +50 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/TensorIteratorDynamicCasting.h +53 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/TensorShape.h +58 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/TransposeType.h +23 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/UnfoldBackward.h +112 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/group_norm.h +42 -0
- videollama2/lib/python3.10/site-packages/torch/include/ATen/native/im2col.h +149 -0
- vllm/lib/python3.10/site-packages/sympy/printing/__pycache__/defaults.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_aesaracode.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_c.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_codeprinter.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_conventions.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_cupy.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_cxx.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_dot.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_fortran.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_glsl.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_gtk.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_jax.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_jscode.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_julia.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_llvmjit.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_maple.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_mathematica.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_mathml.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_numpy.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_octave.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_precedence.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_preview.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_pycode.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_python.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_rcode.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_repr.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_smtlib.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_str.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_tableform.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_tensorflow.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_theanocode.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_tree.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/sympy/printing/tests/test_aesaracode.py +626 -0
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/BatchLinearAlgebra.h
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <c10/util/Optional.h>
|
| 4 |
+
#include <c10/util/string_view.h>
|
| 5 |
+
#include <ATen/Config.h>
|
| 6 |
+
#include <ATen/native/DispatchStub.h>
|
| 7 |
+
|
| 8 |
+
// Forward declare TI
|
| 9 |
+
namespace at {
|
| 10 |
+
class Tensor;
|
| 11 |
+
struct TensorIterator;
|
| 12 |
+
|
| 13 |
+
namespace native {
|
| 14 |
+
enum class TransposeType;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
namespace at::native {
|
| 20 |
+
|
| 21 |
+
enum class LapackLstsqDriverType : int64_t { Gels, Gelsd, Gelsy, Gelss};
|
| 22 |
+
|
| 23 |
+
#if AT_BUILD_WITH_LAPACK()
|
| 24 |
+
// Define per-batch functions to be used in the implementation of batched
|
| 25 |
+
// linear algebra operations
|
| 26 |
+
|
| 27 |
+
template <class scalar_t>
|
| 28 |
+
void lapackCholesky(char uplo, int n, scalar_t *a, int lda, int *info);
|
| 29 |
+
|
| 30 |
+
template <class scalar_t>
|
| 31 |
+
void lapackCholeskyInverse(char uplo, int n, scalar_t *a, int lda, int *info);
|
| 32 |
+
|
| 33 |
+
template <class scalar_t, class value_t=scalar_t>
|
| 34 |
+
void lapackEig(char jobvl, char jobvr, int n, scalar_t *a, int lda, scalar_t *w, scalar_t* vl, int ldvl, scalar_t *vr, int ldvr, scalar_t *work, int lwork, value_t *rwork, int *info);
|
| 35 |
+
|
| 36 |
+
template <class scalar_t>
|
| 37 |
+
void lapackGeqrf(int m, int n, scalar_t *a, int lda, scalar_t *tau, scalar_t *work, int lwork, int *info);
|
| 38 |
+
|
| 39 |
+
template <class scalar_t>
|
| 40 |
+
void lapackOrgqr(int m, int n, int k, scalar_t *a, int lda, scalar_t *tau, scalar_t *work, int lwork, int *info);
|
| 41 |
+
|
| 42 |
+
template <class scalar_t>
|
| 43 |
+
void lapackOrmqr(char side, char trans, int m, int n, int k, scalar_t *a, int lda, scalar_t *tau, scalar_t *c, int ldc, scalar_t *work, int lwork, int *info);
|
| 44 |
+
|
| 45 |
+
template <class scalar_t, class value_t = scalar_t>
|
| 46 |
+
void lapackSyevd(char jobz, char uplo, int n, scalar_t* a, int lda, value_t* w, scalar_t* work, int lwork, value_t* rwork, int lrwork, int* iwork, int liwork, int* info);
|
| 47 |
+
|
| 48 |
+
template <class scalar_t>
|
| 49 |
+
void lapackGels(char trans, int m, int n, int nrhs,
|
| 50 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 51 |
+
scalar_t *work, int lwork, int *info);
|
| 52 |
+
|
| 53 |
+
template <class scalar_t, class value_t = scalar_t>
|
| 54 |
+
void lapackGelsd(int m, int n, int nrhs,
|
| 55 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 56 |
+
value_t *s, value_t rcond, int *rank,
|
| 57 |
+
scalar_t* work, int lwork,
|
| 58 |
+
value_t *rwork, int* iwork, int *info);
|
| 59 |
+
|
| 60 |
+
template <class scalar_t, class value_t = scalar_t>
|
| 61 |
+
void lapackGelsy(int m, int n, int nrhs,
|
| 62 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 63 |
+
int *jpvt, value_t rcond, int *rank,
|
| 64 |
+
scalar_t *work, int lwork, value_t* rwork, int *info);
|
| 65 |
+
|
| 66 |
+
template <class scalar_t, class value_t = scalar_t>
|
| 67 |
+
void lapackGelss(int m, int n, int nrhs,
|
| 68 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 69 |
+
value_t *s, value_t rcond, int *rank,
|
| 70 |
+
scalar_t *work, int lwork,
|
| 71 |
+
value_t *rwork, int *info);
|
| 72 |
+
|
| 73 |
+
template <LapackLstsqDriverType, class scalar_t, class value_t = scalar_t>
|
| 74 |
+
struct lapackLstsq_impl;
|
| 75 |
+
|
| 76 |
+
template <class scalar_t, class value_t>
|
| 77 |
+
struct lapackLstsq_impl<LapackLstsqDriverType::Gels, scalar_t, value_t> {
|
| 78 |
+
static void call(
|
| 79 |
+
char trans, int m, int n, int nrhs,
|
| 80 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 81 |
+
scalar_t *work, int lwork, int *info, // Gels flavor
|
| 82 |
+
int *jpvt, value_t rcond, int *rank, value_t* rwork, // Gelsy flavor
|
| 83 |
+
value_t *s, // Gelss flavor
|
| 84 |
+
int *iwork // Gelsd flavor
|
| 85 |
+
) {
|
| 86 |
+
lapackGels<scalar_t>(
|
| 87 |
+
trans, m, n, nrhs,
|
| 88 |
+
a, lda, b, ldb,
|
| 89 |
+
work, lwork, info);
|
| 90 |
+
}
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
template <class scalar_t, class value_t>
|
| 94 |
+
struct lapackLstsq_impl<LapackLstsqDriverType::Gelsy, scalar_t, value_t> {
|
| 95 |
+
static void call(
|
| 96 |
+
char trans, int m, int n, int nrhs,
|
| 97 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 98 |
+
scalar_t *work, int lwork, int *info, // Gels flavor
|
| 99 |
+
int *jpvt, value_t rcond, int *rank, value_t* rwork, // Gelsy flavor
|
| 100 |
+
value_t *s, // Gelss flavor
|
| 101 |
+
int *iwork // Gelsd flavor
|
| 102 |
+
) {
|
| 103 |
+
lapackGelsy<scalar_t, value_t>(
|
| 104 |
+
m, n, nrhs,
|
| 105 |
+
a, lda, b, ldb,
|
| 106 |
+
jpvt, rcond, rank,
|
| 107 |
+
work, lwork, rwork, info);
|
| 108 |
+
}
|
| 109 |
+
};
|
| 110 |
+
|
| 111 |
+
template <class scalar_t, class value_t>
|
| 112 |
+
struct lapackLstsq_impl<LapackLstsqDriverType::Gelsd, scalar_t, value_t> {
|
| 113 |
+
static void call(
|
| 114 |
+
char trans, int m, int n, int nrhs,
|
| 115 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 116 |
+
scalar_t *work, int lwork, int *info, // Gels flavor
|
| 117 |
+
int *jpvt, value_t rcond, int *rank, value_t* rwork, // Gelsy flavor
|
| 118 |
+
value_t *s, // Gelss flavor
|
| 119 |
+
int *iwork // Gelsd flavor
|
| 120 |
+
) {
|
| 121 |
+
lapackGelsd<scalar_t, value_t>(
|
| 122 |
+
m, n, nrhs,
|
| 123 |
+
a, lda, b, ldb,
|
| 124 |
+
s, rcond, rank,
|
| 125 |
+
work, lwork,
|
| 126 |
+
rwork, iwork, info);
|
| 127 |
+
}
|
| 128 |
+
};
|
| 129 |
+
|
| 130 |
+
template <class scalar_t, class value_t>
|
| 131 |
+
struct lapackLstsq_impl<LapackLstsqDriverType::Gelss, scalar_t, value_t> {
|
| 132 |
+
static void call(
|
| 133 |
+
char trans, int m, int n, int nrhs,
|
| 134 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 135 |
+
scalar_t *work, int lwork, int *info, // Gels flavor
|
| 136 |
+
int *jpvt, value_t rcond, int *rank, value_t* rwork, // Gelsy flavor
|
| 137 |
+
value_t *s, // Gelss flavor
|
| 138 |
+
int *iwork // Gelsd flavor
|
| 139 |
+
) {
|
| 140 |
+
lapackGelss<scalar_t, value_t>(
|
| 141 |
+
m, n, nrhs,
|
| 142 |
+
a, lda, b, ldb,
|
| 143 |
+
s, rcond, rank,
|
| 144 |
+
work, lwork,
|
| 145 |
+
rwork, info);
|
| 146 |
+
}
|
| 147 |
+
};
|
| 148 |
+
|
| 149 |
+
template <LapackLstsqDriverType driver_type, class scalar_t, class value_t = scalar_t>
|
| 150 |
+
void lapackLstsq(
|
| 151 |
+
char trans, int m, int n, int nrhs,
|
| 152 |
+
scalar_t *a, int lda, scalar_t *b, int ldb,
|
| 153 |
+
scalar_t *work, int lwork, int *info, // Gels flavor
|
| 154 |
+
int *jpvt, value_t rcond, int *rank, value_t* rwork, // Gelsy flavor
|
| 155 |
+
value_t *s, // Gelss flavor
|
| 156 |
+
int *iwork // Gelsd flavor
|
| 157 |
+
) {
|
| 158 |
+
lapackLstsq_impl<driver_type, scalar_t, value_t>::call(
|
| 159 |
+
trans, m, n, nrhs,
|
| 160 |
+
a, lda, b, ldb,
|
| 161 |
+
work, lwork, info,
|
| 162 |
+
jpvt, rcond, rank, rwork,
|
| 163 |
+
s,
|
| 164 |
+
iwork);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
template <class scalar_t>
|
| 168 |
+
void lapackLuSolve(char trans, int n, int nrhs, scalar_t *a, int lda, int *ipiv, scalar_t *b, int ldb, int *info);
|
| 169 |
+
|
| 170 |
+
template <class scalar_t>
|
| 171 |
+
void lapackLu(int m, int n, scalar_t *a, int lda, int *ipiv, int *info);
|
| 172 |
+
|
| 173 |
+
template <class scalar_t>
|
| 174 |
+
void lapackLdlHermitian(
|
| 175 |
+
char uplo,
|
| 176 |
+
int n,
|
| 177 |
+
scalar_t* a,
|
| 178 |
+
int lda,
|
| 179 |
+
int* ipiv,
|
| 180 |
+
scalar_t* work,
|
| 181 |
+
int lwork,
|
| 182 |
+
int* info);
|
| 183 |
+
|
| 184 |
+
template <class scalar_t>
|
| 185 |
+
void lapackLdlSymmetric(
|
| 186 |
+
char uplo,
|
| 187 |
+
int n,
|
| 188 |
+
scalar_t* a,
|
| 189 |
+
int lda,
|
| 190 |
+
int* ipiv,
|
| 191 |
+
scalar_t* work,
|
| 192 |
+
int lwork,
|
| 193 |
+
int* info);
|
| 194 |
+
|
| 195 |
+
template <class scalar_t>
|
| 196 |
+
void lapackLdlSolveHermitian(
|
| 197 |
+
char uplo,
|
| 198 |
+
int n,
|
| 199 |
+
int nrhs,
|
| 200 |
+
scalar_t* a,
|
| 201 |
+
int lda,
|
| 202 |
+
int* ipiv,
|
| 203 |
+
scalar_t* b,
|
| 204 |
+
int ldb,
|
| 205 |
+
int* info);
|
| 206 |
+
|
| 207 |
+
template <class scalar_t>
|
| 208 |
+
void lapackLdlSolveSymmetric(
|
| 209 |
+
char uplo,
|
| 210 |
+
int n,
|
| 211 |
+
int nrhs,
|
| 212 |
+
scalar_t* a,
|
| 213 |
+
int lda,
|
| 214 |
+
int* ipiv,
|
| 215 |
+
scalar_t* b,
|
| 216 |
+
int ldb,
|
| 217 |
+
int* info);
|
| 218 |
+
|
| 219 |
+
template<class scalar_t, class value_t=scalar_t>
|
| 220 |
+
void lapackSvd(char jobz, int m, int n, scalar_t *a, int lda, value_t *s, scalar_t *u, int ldu, scalar_t *vt, int ldvt, scalar_t *work, int lwork, value_t *rwork, int *iwork, int *info);
|
| 221 |
+
#endif
|
| 222 |
+
|
| 223 |
+
#if AT_BUILD_WITH_BLAS()
|
| 224 |
+
template <class scalar_t>
|
| 225 |
+
void blasTriangularSolve(char side, char uplo, char trans, char diag, int n, int nrhs, scalar_t* a, int lda, scalar_t* b, int ldb);
|
| 226 |
+
#endif
|
| 227 |
+
|
| 228 |
+
using cholesky_fn = void (*)(const Tensor& /*input*/, const Tensor& /*info*/, bool /*upper*/);
|
| 229 |
+
DECLARE_DISPATCH(cholesky_fn, cholesky_stub);
|
| 230 |
+
|
| 231 |
+
using cholesky_inverse_fn = Tensor& (*)(Tensor& /*result*/, Tensor& /*infos*/, bool /*upper*/);
|
| 232 |
+
|
| 233 |
+
DECLARE_DISPATCH(cholesky_inverse_fn, cholesky_inverse_stub);
|
| 234 |
+
|
| 235 |
+
using linalg_eig_fn = void (*)(Tensor& /*eigenvalues*/, Tensor& /*eigenvectors*/, Tensor& /*infos*/, const Tensor& /*input*/, bool /*compute_eigenvectors*/);
|
| 236 |
+
|
| 237 |
+
DECLARE_DISPATCH(linalg_eig_fn, linalg_eig_stub);
|
| 238 |
+
|
| 239 |
+
using geqrf_fn = void (*)(const Tensor& /*input*/, const Tensor& /*tau*/);
|
| 240 |
+
DECLARE_DISPATCH(geqrf_fn, geqrf_stub);
|
| 241 |
+
|
| 242 |
+
using orgqr_fn = Tensor& (*)(Tensor& /*result*/, const Tensor& /*tau*/);
|
| 243 |
+
DECLARE_DISPATCH(orgqr_fn, orgqr_stub);
|
| 244 |
+
|
| 245 |
+
using ormqr_fn = void (*)(const Tensor& /*input*/, const Tensor& /*tau*/, const Tensor& /*other*/, bool /*left*/, bool /*transpose*/);
|
| 246 |
+
DECLARE_DISPATCH(ormqr_fn, ormqr_stub);
|
| 247 |
+
|
| 248 |
+
using linalg_eigh_fn = void (*)(
|
| 249 |
+
const Tensor& /*eigenvalues*/,
|
| 250 |
+
const Tensor& /*eigenvectors*/,
|
| 251 |
+
const Tensor& /*infos*/,
|
| 252 |
+
bool /*upper*/,
|
| 253 |
+
bool /*compute_eigenvectors*/);
|
| 254 |
+
DECLARE_DISPATCH(linalg_eigh_fn, linalg_eigh_stub);
|
| 255 |
+
|
| 256 |
+
using lstsq_fn = void (*)(
|
| 257 |
+
const Tensor& /*a*/,
|
| 258 |
+
Tensor& /*b*/,
|
| 259 |
+
Tensor& /*rank*/,
|
| 260 |
+
Tensor& /*singular_values*/,
|
| 261 |
+
Tensor& /*infos*/,
|
| 262 |
+
double /*rcond*/,
|
| 263 |
+
std::string /*driver_name*/);
|
| 264 |
+
DECLARE_DISPATCH(lstsq_fn, lstsq_stub);
|
| 265 |
+
|
| 266 |
+
using triangular_solve_fn = void (*)(
|
| 267 |
+
const Tensor& /*A*/,
|
| 268 |
+
const Tensor& /*B*/,
|
| 269 |
+
bool /*left*/,
|
| 270 |
+
bool /*upper*/,
|
| 271 |
+
TransposeType /*transpose*/,
|
| 272 |
+
bool /*unitriangular*/);
|
| 273 |
+
DECLARE_DISPATCH(triangular_solve_fn, triangular_solve_stub);
|
| 274 |
+
|
| 275 |
+
using lu_factor_fn = void (*)(
|
| 276 |
+
const Tensor& /*input*/,
|
| 277 |
+
const Tensor& /*pivots*/,
|
| 278 |
+
const Tensor& /*infos*/,
|
| 279 |
+
bool /*compute_pivots*/);
|
| 280 |
+
DECLARE_DISPATCH(lu_factor_fn, lu_factor_stub);
|
| 281 |
+
|
| 282 |
+
using unpack_pivots_fn = void(*)(
|
| 283 |
+
TensorIterator& iter,
|
| 284 |
+
const int64_t dim_size,
|
| 285 |
+
const int64_t max_pivot);
|
| 286 |
+
DECLARE_DISPATCH(unpack_pivots_fn, unpack_pivots_stub);
|
| 287 |
+
|
| 288 |
+
using lu_solve_fn = void (*)(
|
| 289 |
+
const Tensor& /*LU*/,
|
| 290 |
+
const Tensor& /*pivots*/,
|
| 291 |
+
const Tensor& /*B*/,
|
| 292 |
+
TransposeType /*trans*/);
|
| 293 |
+
DECLARE_DISPATCH(lu_solve_fn, lu_solve_stub);
|
| 294 |
+
|
| 295 |
+
using ldl_factor_fn = void (*)(
|
| 296 |
+
const Tensor& /*LD*/,
|
| 297 |
+
const Tensor& /*pivots*/,
|
| 298 |
+
const Tensor& /*info*/,
|
| 299 |
+
bool /*upper*/,
|
| 300 |
+
bool /*hermitian*/);
|
| 301 |
+
DECLARE_DISPATCH(ldl_factor_fn, ldl_factor_stub);
|
| 302 |
+
|
| 303 |
+
using svd_fn = void (*)(
|
| 304 |
+
const Tensor& /*A*/,
|
| 305 |
+
const bool /*full_matrices*/,
|
| 306 |
+
const bool /*compute_uv*/,
|
| 307 |
+
const c10::optional<c10::string_view>& /*driver*/,
|
| 308 |
+
const Tensor& /*U*/,
|
| 309 |
+
const Tensor& /*S*/,
|
| 310 |
+
const Tensor& /*Vh*/,
|
| 311 |
+
const Tensor& /*info*/);
|
| 312 |
+
DECLARE_DISPATCH(svd_fn, svd_stub);
|
| 313 |
+
|
| 314 |
+
using ldl_solve_fn = void (*)(
|
| 315 |
+
const Tensor& /*LD*/,
|
| 316 |
+
const Tensor& /*pivots*/,
|
| 317 |
+
const Tensor& /*result*/,
|
| 318 |
+
bool /*upper*/,
|
| 319 |
+
bool /*hermitian*/);
|
| 320 |
+
DECLARE_DISPATCH(ldl_solve_fn, ldl_solve_stub);
|
| 321 |
+
} // namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/CompositeRandomAccessorCommon.h
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <utility>
|
| 2 |
+
|
| 3 |
+
#pragma once
|
| 4 |
+
|
| 5 |
+
namespace at::native {
|
| 6 |
+
|
| 7 |
+
namespace {
|
| 8 |
+
|
| 9 |
+
// operator_brackets_proxy is used in
|
| 10 |
+
// CompositeRandomAccessor in place of operator[].
|
| 11 |
+
// For some iterators, references returned by operator[]
|
| 12 |
+
// could become invalid, operator_brackets_proxy tries to
|
| 13 |
+
// resolve that by making accessor[n] to be equivalent to
|
| 14 |
+
// *(accessor + n).
|
| 15 |
+
template <typename Accessor>
|
| 16 |
+
class operator_brackets_proxy {
|
| 17 |
+
using reference = typename std::iterator_traits<Accessor>::reference;
|
| 18 |
+
using value_type = typename std::iterator_traits<Accessor>::value_type;
|
| 19 |
+
|
| 20 |
+
public:
|
| 21 |
+
C10_HOST_DEVICE
|
| 22 |
+
operator_brackets_proxy(Accessor const& accessor)
|
| 23 |
+
: accessor(accessor)
|
| 24 |
+
{}
|
| 25 |
+
|
| 26 |
+
C10_HOST_DEVICE
|
| 27 |
+
operator reference() {
|
| 28 |
+
return *accessor;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
C10_HOST_DEVICE
|
| 32 |
+
reference operator*() {
|
| 33 |
+
return *accessor;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
C10_HOST_DEVICE
|
| 37 |
+
operator_brackets_proxy& operator=(value_type const& val) {
|
| 38 |
+
*accessor = val;
|
| 39 |
+
return *this;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
private:
|
| 43 |
+
Accessor accessor;
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
// references_holder is used as a surrogate for the
|
| 49 |
+
// references type from std::iterator_traits in CompositeRandomAccessor.
|
| 50 |
+
// It is assumed in CompositeRandomAccessor that
|
| 51 |
+
// References = tuple<Types&...>,
|
| 52 |
+
// Values = tuple<Types...> by default,
|
| 53 |
+
// but they could be anything as long as References could be
|
| 54 |
+
// cast to Values.
|
| 55 |
+
// If you plan to use it with STL, for example, you will need to
|
| 56 |
+
// define 'swap` and `get`(aka std::get) methods.
|
| 57 |
+
template <typename Values, typename References>
|
| 58 |
+
class references_holder {
|
| 59 |
+
public:
|
| 60 |
+
using values = Values;
|
| 61 |
+
using references = References;
|
| 62 |
+
|
| 63 |
+
C10_HOST_DEVICE
|
| 64 |
+
references_holder(references refs)
|
| 65 |
+
: refs{std::move(refs)}
|
| 66 |
+
{}
|
| 67 |
+
|
| 68 |
+
C10_HOST_DEVICE
|
| 69 |
+
operator references() {
|
| 70 |
+
return refs;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
C10_HOST_DEVICE
|
| 74 |
+
operator values() {
|
| 75 |
+
return refs;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
C10_HOST_DEVICE
|
| 79 |
+
references_holder& operator=(values vals) {
|
| 80 |
+
refs = vals;
|
| 81 |
+
return *this;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
C10_HOST_DEVICE
|
| 85 |
+
references& data() {
|
| 86 |
+
return refs;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
protected:
|
| 90 |
+
references refs;
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
// CompositeRandomAccessor is essentially a simplified version of
|
| 94 |
+
// a random access iterator over two random access iterators.
|
| 95 |
+
// TupleInfo should contain a variadic type `tuple`, and a method `tie`,
|
| 96 |
+
// which constructs a tuple of references from a variadic list of arguments.
|
| 97 |
+
template <typename KeyAccessor, typename ValueAccessor, typename TupleInfo>
|
| 98 |
+
class CompositeRandomAccessor {
|
| 99 |
+
using self_type = CompositeRandomAccessor<KeyAccessor, ValueAccessor, TupleInfo>;
|
| 100 |
+
|
| 101 |
+
using key_accessor_value_type =
|
| 102 |
+
typename std::iterator_traits<KeyAccessor>::value_type;
|
| 103 |
+
using value_accessor_value_type =
|
| 104 |
+
typename std::iterator_traits<ValueAccessor>::value_type;
|
| 105 |
+
using key_accessor_reference_type =
|
| 106 |
+
typename std::iterator_traits<KeyAccessor>::reference;
|
| 107 |
+
using value_accessor_reference_type =
|
| 108 |
+
typename std::iterator_traits<ValueAccessor>::reference;
|
| 109 |
+
|
| 110 |
+
using composite_value_type = typename TupleInfo::template tuple<
|
| 111 |
+
key_accessor_value_type,
|
| 112 |
+
value_accessor_value_type>;
|
| 113 |
+
using composite_reference = typename TupleInfo::template tuple<
|
| 114 |
+
key_accessor_reference_type,
|
| 115 |
+
value_accessor_reference_type>;
|
| 116 |
+
|
| 117 |
+
public:
|
| 118 |
+
using value_type = composite_value_type;
|
| 119 |
+
using reference = references_holder<composite_value_type, composite_reference>;
|
| 120 |
+
// Note that CompositeRandomAccessor does not hold key and values
|
| 121 |
+
// in a specific datastrcture, which means that a pointer to a (key, value)
|
| 122 |
+
// is not defined. Hence we just use a pointer type of the KeyAccessor.
|
| 123 |
+
using pointer = typename std::iterator_traits<KeyAccessor>::pointer;
|
| 124 |
+
using difference_type = typename std::iterator_traits<KeyAccessor>::difference_type;
|
| 125 |
+
using iterator_category = std::random_access_iterator_tag;
|
| 126 |
+
|
| 127 |
+
C10_HOST_DEVICE
|
| 128 |
+
CompositeRandomAccessor() = default;
|
| 129 |
+
|
| 130 |
+
C10_HOST_DEVICE
|
| 131 |
+
CompositeRandomAccessor(KeyAccessor keys, ValueAccessor values)
|
| 132 |
+
: keys(keys), values(values)
|
| 133 |
+
{}
|
| 134 |
+
|
| 135 |
+
// Pointer-like operations {
|
| 136 |
+
C10_HOST_DEVICE
|
| 137 |
+
reference operator*() const {
|
| 138 |
+
return TupleInfo::tie(*keys, *values);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// operator->() is supposed to return a pointer type.
|
| 142 |
+
// Since CompositeRandomAccessor does not hold pointers to pairs,
|
| 143 |
+
// we just return a pointer to a key.
|
| 144 |
+
C10_HOST_DEVICE
|
| 145 |
+
auto* operator->() const {
|
| 146 |
+
return keys.operator->();
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
C10_HOST_DEVICE
|
| 150 |
+
reference operator[](difference_type idx) {
|
| 151 |
+
return operator_brackets_proxy<self_type>(
|
| 152 |
+
CompositeRandomAccessor(keys + idx, values + idx)
|
| 153 |
+
);
|
| 154 |
+
}
|
| 155 |
+
// }
|
| 156 |
+
|
| 157 |
+
// Prefix/postfix increment/decrement {
|
| 158 |
+
C10_HOST_DEVICE
|
| 159 |
+
CompositeRandomAccessor& operator++() {
|
| 160 |
+
++keys;
|
| 161 |
+
++values;
|
| 162 |
+
return *this;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
C10_HOST_DEVICE
|
| 166 |
+
CompositeRandomAccessor operator++(int) {
|
| 167 |
+
CompositeRandomAccessor copy(*this);
|
| 168 |
+
++*this;
|
| 169 |
+
return copy;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
C10_HOST_DEVICE
|
| 173 |
+
CompositeRandomAccessor& operator--() {
|
| 174 |
+
--keys;
|
| 175 |
+
--values;
|
| 176 |
+
return *this;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
C10_HOST_DEVICE
|
| 180 |
+
CompositeRandomAccessor operator--(int) {
|
| 181 |
+
CompositeRandomAccessor copy(*this);
|
| 182 |
+
--*this;
|
| 183 |
+
return copy;
|
| 184 |
+
}
|
| 185 |
+
// }
|
| 186 |
+
|
| 187 |
+
// Arithmetic operations {
|
| 188 |
+
C10_HOST_DEVICE
|
| 189 |
+
CompositeRandomAccessor& operator+=(difference_type offset) {
|
| 190 |
+
keys += offset;
|
| 191 |
+
values += offset;
|
| 192 |
+
return *this;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
C10_HOST_DEVICE
|
| 196 |
+
CompositeRandomAccessor operator+(difference_type offset) const {
|
| 197 |
+
return CompositeRandomAccessor(keys + offset, values + offset);
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
C10_HOST_DEVICE
|
| 201 |
+
friend CompositeRandomAccessor operator+(
|
| 202 |
+
difference_type offset,
|
| 203 |
+
const CompositeRandomAccessor& accessor
|
| 204 |
+
) {
|
| 205 |
+
return accessor + offset;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
C10_HOST_DEVICE
|
| 209 |
+
CompositeRandomAccessor& operator-=(difference_type offset) {
|
| 210 |
+
keys -= offset;
|
| 211 |
+
values -= offset;
|
| 212 |
+
return *this;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
C10_HOST_DEVICE
|
| 216 |
+
CompositeRandomAccessor operator-(difference_type offset) const {
|
| 217 |
+
return CompositeRandomAccessor(keys - offset, values - offset);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
C10_HOST_DEVICE
|
| 221 |
+
difference_type operator-(const CompositeRandomAccessor& other) const {
|
| 222 |
+
return keys - other.keys;
|
| 223 |
+
}
|
| 224 |
+
// }
|
| 225 |
+
|
| 226 |
+
// Comparison operators {
|
| 227 |
+
C10_HOST_DEVICE
|
| 228 |
+
bool operator==(const CompositeRandomAccessor& other) const {
|
| 229 |
+
return keys == other.keys;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
C10_HOST_DEVICE
|
| 233 |
+
bool operator!=(const CompositeRandomAccessor& other) const {
|
| 234 |
+
return keys != other.keys;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
C10_HOST_DEVICE
|
| 238 |
+
bool operator<(const CompositeRandomAccessor& other) const {
|
| 239 |
+
return keys < other.keys;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
C10_HOST_DEVICE
|
| 243 |
+
bool operator<=(const CompositeRandomAccessor& other) const {
|
| 244 |
+
return keys <= other.keys;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
C10_HOST_DEVICE
|
| 248 |
+
bool operator>(const CompositeRandomAccessor& other) const {
|
| 249 |
+
return keys > other.keys;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
C10_HOST_DEVICE
|
| 253 |
+
bool operator>=(const CompositeRandomAccessor& other) const {
|
| 254 |
+
return keys >= other.keys;
|
| 255 |
+
}
|
| 256 |
+
// }
|
| 257 |
+
|
| 258 |
+
protected:
|
| 259 |
+
KeyAccessor keys;
|
| 260 |
+
ValueAccessor values;
|
| 261 |
+
};
|
| 262 |
+
|
| 263 |
+
} // namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/ConvolutionMM3d.h
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <ATen/core/Tensor.h>
|
| 2 |
+
|
| 3 |
+
namespace at::native {
|
| 4 |
+
|
| 5 |
+
std::tuple<Tensor, Tensor, Tensor> slow_conv3d_backward_cpu(
|
| 6 |
+
const Tensor& grad_output,
|
| 7 |
+
const Tensor& self,
|
| 8 |
+
const Tensor& weight,
|
| 9 |
+
IntArrayRef kernel_size,
|
| 10 |
+
IntArrayRef stride,
|
| 11 |
+
IntArrayRef padding,
|
| 12 |
+
std::array<bool, 3> output_mask);
|
| 13 |
+
|
| 14 |
+
} // namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/DilatedConvolutionUtils.h
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <algorithm>
|
| 4 |
+
#include <vector>
|
| 5 |
+
|
| 6 |
+
#include <ATen/div_rtn.h>
|
| 7 |
+
#include <ATen/core/Tensor.h>
|
| 8 |
+
#include <c10/util/irange.h>
|
| 9 |
+
|
| 10 |
+
#define TORCH_CHECK_DIM_SIZE(T, DIM, DIM_SIZE, SIZE) \
|
| 11 |
+
TORCH_CHECK( \
|
| 12 |
+
T.dim() == DIM && T.size(DIM_SIZE) == SIZE, \
|
| 13 |
+
"Need " #T " of dimension ", \
|
| 14 |
+
DIM, \
|
| 15 |
+
" and " #T ".size[", \
|
| 16 |
+
DIM_SIZE, \
|
| 17 |
+
"] == ", \
|
| 18 |
+
SIZE, \
|
| 19 |
+
" but got input to be of shape ", \
|
| 20 |
+
T.sizes())
|
| 21 |
+
|
| 22 |
+
namespace at::native::internal {
|
| 23 |
+
namespace {
|
| 24 |
+
inline bool all_positive(IntArrayRef& arr) {
|
| 25 |
+
return std::all_of(
|
| 26 |
+
arr.begin(), arr.end(), [](int64_t item) { return item > 0; });
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
inline bool all_nonnegative(std::vector<int64_t>& arr) {
|
| 30 |
+
return std::all_of(
|
| 31 |
+
arr.begin(), arr.end(), [](int64_t item) { return item >= 0; });
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
} // namespace
|
| 35 |
+
|
| 36 |
+
// calculate the rear part of output tensor sizes
|
| 37 |
+
template <int64_t dim>
|
| 38 |
+
std::vector<int64_t> get_output_size(
|
| 39 |
+
const Tensor& input,
|
| 40 |
+
IntArrayRef kernel_size,
|
| 41 |
+
IntArrayRef stride_size,
|
| 42 |
+
IntArrayRef pad_size,
|
| 43 |
+
IntArrayRef dilation_size) {
|
| 44 |
+
std::vector<int64_t> sizes;
|
| 45 |
+
for (const auto index : c10::irange(dim)) {
|
| 46 |
+
sizes.push_back(
|
| 47 |
+
div_rtn<int64_t>(
|
| 48 |
+
input.size(index + input.dim() - dim) + 2 * pad_size[index] -
|
| 49 |
+
(dilation_size[index] * (kernel_size[index] - 1) + 1),
|
| 50 |
+
stride_size[index]) +
|
| 51 |
+
1);
|
| 52 |
+
}
|
| 53 |
+
return sizes;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// calculate the sizes of output tensor
|
| 57 |
+
template <int64_t dim>
|
| 58 |
+
std::vector<int64_t> get_output_size(
|
| 59 |
+
const Tensor& input,
|
| 60 |
+
const Tensor& weight,
|
| 61 |
+
IntArrayRef kernel_size,
|
| 62 |
+
IntArrayRef stride_size,
|
| 63 |
+
IntArrayRef pad_size,
|
| 64 |
+
IntArrayRef dilation_size) {
|
| 65 |
+
auto output_size = get_output_size<dim>(
|
| 66 |
+
input, kernel_size, stride_size, pad_size, dilation_size);
|
| 67 |
+
output_size.insert(output_size.begin(), weight.size(0));
|
| 68 |
+
if (input.dim() == dim + 2) {
|
| 69 |
+
output_size.insert(output_size.begin(), input.size(0));
|
| 70 |
+
}
|
| 71 |
+
return output_size;
|
| 72 |
+
}
|
| 73 |
+
/*
|
| 74 |
+
slow_conv_dilated_shape_check - check user-input to dilated convolution
|
| 75 |
+
forward and backward functions.
|
| 76 |
+
*/
|
| 77 |
+
template <int64_t dim>
|
| 78 |
+
void slow_conv_dilated_shape_check(
|
| 79 |
+
const Tensor& input,
|
| 80 |
+
const Tensor& weight,
|
| 81 |
+
const Tensor& bias,
|
| 82 |
+
const Tensor& grad_output,
|
| 83 |
+
IntArrayRef kernel_size,
|
| 84 |
+
IntArrayRef stride_size,
|
| 85 |
+
IntArrayRef pad_size,
|
| 86 |
+
IntArrayRef dilation_size) {
|
| 87 |
+
/*
|
| 88 |
+
When the following tensors are defined:
|
| 89 |
+
|
| 90 |
+
bias, grad_weight, grad_output
|
| 91 |
+
|
| 92 |
+
then these are assumed to be contiguous without checking
|
| 93 |
+
because of these tensors are made contiguous by calling
|
| 94 |
+
.contiguous() method or by resizing of zero-sized tensors in
|
| 95 |
+
forward/backward functions.
|
| 96 |
+
|
| 97 |
+
When grad_weight is defined then it is assumed without
|
| 98 |
+
checking to have the same shape as weight, see backward
|
| 99 |
+
functions.
|
| 100 |
+
*/
|
| 101 |
+
// Check size arguments
|
| 102 |
+
TORCH_CHECK(
|
| 103 |
+
kernel_size.size() == dim,
|
| 104 |
+
"kernel sizes length should be ",
|
| 105 |
+
dim,
|
| 106 |
+
", but got ",
|
| 107 |
+
kernel_size.size());
|
| 108 |
+
TORCH_CHECK(
|
| 109 |
+
stride_size.size() == dim,
|
| 110 |
+
"strides length should be ",
|
| 111 |
+
dim,
|
| 112 |
+
", but got ",
|
| 113 |
+
stride_size.size());
|
| 114 |
+
TORCH_CHECK(
|
| 115 |
+
dilation_size.size() == dim,
|
| 116 |
+
"dilations length should be ",
|
| 117 |
+
dim,
|
| 118 |
+
", but got ",
|
| 119 |
+
dilation_size.size());
|
| 120 |
+
TORCH_CHECK(
|
| 121 |
+
pad_size.size() == dim,
|
| 122 |
+
"pads length should be ",
|
| 123 |
+
dim,
|
| 124 |
+
", but got ",
|
| 125 |
+
pad_size.size());
|
| 126 |
+
|
| 127 |
+
TORCH_CHECK(
|
| 128 |
+
all_positive(kernel_size),
|
| 129 |
+
"kernel size should be greater than zero, but got ",
|
| 130 |
+
kernel_size);
|
| 131 |
+
TORCH_CHECK(
|
| 132 |
+
all_positive(stride_size),
|
| 133 |
+
"stride should be greater than zero, but got ",
|
| 134 |
+
stride_size);
|
| 135 |
+
TORCH_CHECK(
|
| 136 |
+
all_positive(dilation_size),
|
| 137 |
+
"dilation should be greater than zero, but got ",
|
| 138 |
+
dilation_size);
|
| 139 |
+
|
| 140 |
+
// check input
|
| 141 |
+
TORCH_CHECK(input.defined(), "input must be defined");
|
| 142 |
+
bool is_batch = input.dim() == dim + 2;
|
| 143 |
+
int64_t n = (is_batch ? 2 : 1);
|
| 144 |
+
int64_t ndim = n + dim;
|
| 145 |
+
if (!is_batch) {
|
| 146 |
+
// input dim has to be dim + 1 if not batched
|
| 147 |
+
TORCH_CHECK(
|
| 148 |
+
input.dim() == dim + 1,
|
| 149 |
+
"input must be 4D or 5D tensor but got ",
|
| 150 |
+
input.dim(),
|
| 151 |
+
"D tensor");
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
// check output sizes
|
| 155 |
+
auto output_size = get_output_size<dim>(
|
| 156 |
+
input, kernel_size, stride_size, pad_size, dilation_size);
|
| 157 |
+
|
| 158 |
+
TORCH_CHECK(
|
| 159 |
+
all_nonnegative(output_size),
|
| 160 |
+
"calculated output size ",
|
| 161 |
+
output_size,
|
| 162 |
+
" is too small (all sizes must be non-negative)");
|
| 163 |
+
|
| 164 |
+
// check weight
|
| 165 |
+
TORCH_CHECK(weight.defined(), "weight must be defined");
|
| 166 |
+
TORCH_CHECK(
|
| 167 |
+
weight.dim() == dim + 2,
|
| 168 |
+
"weight must be ",
|
| 169 |
+
dim + 2,
|
| 170 |
+
"D tensor but got ",
|
| 171 |
+
weight.dim(),
|
| 172 |
+
"D tensor dim=",
|
| 173 |
+
dim);
|
| 174 |
+
TORCH_CHECK(
|
| 175 |
+
weight.sizes().slice(2) == kernel_size,
|
| 176 |
+
"weight[2:] shape ",
|
| 177 |
+
weight.sizes().slice(2),
|
| 178 |
+
" must be equal to kernel_size ",
|
| 179 |
+
kernel_size);
|
| 180 |
+
|
| 181 |
+
TORCH_CHECK_DIM_SIZE(input, input.dim(), (is_batch ? 1 : 0), weight.size(1));
|
| 182 |
+
|
| 183 |
+
// check bias when present
|
| 184 |
+
if (bias.defined()) {
|
| 185 |
+
TORCH_CHECK(
|
| 186 |
+
bias.dim() == 1,
|
| 187 |
+
"bias must be 1D tensor but got ",
|
| 188 |
+
bias.dim(),
|
| 189 |
+
"D tensor");
|
| 190 |
+
TORCH_CHECK_DIM_SIZE(bias, 1, 0, weight.size(0));
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// check grad_output when present
|
| 194 |
+
if (grad_output.defined()) {
|
| 195 |
+
TORCH_CHECK(
|
| 196 |
+
grad_output.dim() == ndim,
|
| 197 |
+
"grad_output must be ",
|
| 198 |
+
ndim,
|
| 199 |
+
"D tensor but got ",
|
| 200 |
+
grad_output.dim(),
|
| 201 |
+
"D tensor");
|
| 202 |
+
if (is_batch) {
|
| 203 |
+
TORCH_CHECK(
|
| 204 |
+
grad_output.size(0) == input.size(0),
|
| 205 |
+
"grad_output.size(0)=",
|
| 206 |
+
grad_output.size(0),
|
| 207 |
+
" must be input.size(0)=",
|
| 208 |
+
input.size(0));
|
| 209 |
+
}
|
| 210 |
+
TORCH_CHECK(
|
| 211 |
+
grad_output.size(n - 1) == weight.size(0),
|
| 212 |
+
"grad_output.size(",
|
| 213 |
+
n - 1,
|
| 214 |
+
")=",
|
| 215 |
+
grad_output.size(n - 1),
|
| 216 |
+
" must be weight.size(0)=",
|
| 217 |
+
weight.size(0));
|
| 218 |
+
TORCH_CHECK(
|
| 219 |
+
grad_output.sizes().slice(n) == output_size,
|
| 220 |
+
"grad_output[",
|
| 221 |
+
n,
|
| 222 |
+
":] shape",
|
| 223 |
+
grad_output.sizes().slice(n),
|
| 224 |
+
" must be equal to output size ",
|
| 225 |
+
output_size);
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
} // namespace at::native::internal
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/Fill.h
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Functions that fill Tensors with constants. Implementations are in Fill.cpp.
|
| 2 |
+
|
| 3 |
+
#pragma once
|
| 4 |
+
|
| 5 |
+
#include <ATen/native/DispatchStub.h>
|
| 6 |
+
|
| 7 |
+
namespace c10 {
|
| 8 |
+
class Scalar;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
namespace at {
|
| 12 |
+
class Tensor;
|
| 13 |
+
struct TensorIterator;
|
| 14 |
+
|
| 15 |
+
namespace native {
|
| 16 |
+
|
| 17 |
+
DECLARE_DISPATCH(void(*)(TensorIterator&, const c10::Scalar&), fill_stub);
|
| 18 |
+
|
| 19 |
+
Tensor& fill_out(Tensor& self, const Scalar& value);
|
| 20 |
+
|
| 21 |
+
}} // namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/Lerp.h
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/native/DispatchStub.h>
|
| 4 |
+
#include <ATen/OpMathType.h>
|
| 5 |
+
#include <ATen/TensorIterator.h>
|
| 6 |
+
#include <c10/core/Scalar.h>
|
| 7 |
+
|
| 8 |
+
namespace at::native {
|
| 9 |
+
|
| 10 |
+
template <typename scalar_t>
|
| 11 |
+
C10_HOST_DEVICE C10_ALWAYS_INLINE bool is_lerp_weight_small(scalar_t weight) {
|
| 12 |
+
return std::abs(weight) < scalar_t(0.5);
|
| 13 |
+
}
|
| 14 |
+
template <typename scalar_t>
|
| 15 |
+
C10_HOST_DEVICE C10_ALWAYS_INLINE bool is_lerp_weight_small(c10::complex<scalar_t> weight) {
|
| 16 |
+
// Avoid the sqrt in abs(weight)
|
| 17 |
+
return (weight.real() * weight.real() + weight.imag() * weight.imag()) < scalar_t(0.25);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
template <typename scalar_t, typename weight_t>
|
| 21 |
+
C10_HOST_DEVICE C10_ALWAYS_INLINE scalar_t lerp(scalar_t self_, scalar_t end_, weight_t weight_) {
|
| 22 |
+
using opmath_t = at::opmath_type<scalar_t>;
|
| 23 |
+
using opmath_weight_t = at::opmath_type<weight_t>;
|
| 24 |
+
|
| 25 |
+
opmath_t self = self_;
|
| 26 |
+
opmath_t end = end_;
|
| 27 |
+
opmath_weight_t weight = weight_;
|
| 28 |
+
|
| 29 |
+
// Conditional for better numeric. This has been discussed in
|
| 30 |
+
// https://github.com/pytorch/pytorch/pull/18871
|
| 31 |
+
return is_lerp_weight_small(weight)
|
| 32 |
+
? self + weight * (end - self)
|
| 33 |
+
: end - (end - self) * (opmath_t(1) - weight);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
using lerp_fn_scalar = void (*)(
|
| 37 |
+
at::TensorIteratorBase& iter,
|
| 38 |
+
const Scalar& weight);
|
| 39 |
+
|
| 40 |
+
using lerp_fn_tensor = void (*)(
|
| 41 |
+
at::TensorIteratorBase& iter);
|
| 42 |
+
|
| 43 |
+
DECLARE_DISPATCH(lerp_fn_scalar, lerp_kernel_scalar_weight);
|
| 44 |
+
DECLARE_DISPATCH(lerp_fn_tensor, lerp_kernel_tensor_weight);
|
| 45 |
+
|
| 46 |
+
} // namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/LossMulti.h
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
#include <ATen/core/Tensor.h>
|
| 3 |
+
#include <ATen/AccumulateType.h>
|
| 4 |
+
#include <ATen/Dispatch.h>
|
| 5 |
+
#include <ATen/TensorUtils.h>
|
| 6 |
+
|
| 7 |
+
namespace at::native {
|
| 8 |
+
namespace {
|
| 9 |
+
static C10_UNUSED void multilabel_margin_loss_shape_check(
|
| 10 |
+
int64_t& nframe,
|
| 11 |
+
int64_t& dim,
|
| 12 |
+
const int64_t& ndims,
|
| 13 |
+
const Tensor& input,
|
| 14 |
+
const Tensor& target) {
|
| 15 |
+
TORCH_CHECK(
|
| 16 |
+
(ndims == 2 && input.size(1) != 0) || (ndims == 1 && input.size(0) != 0) || ndims == 0,
|
| 17 |
+
"Expected non-empty vector or matrix with optional 0-dim batch size, but got: ",
|
| 18 |
+
input.sizes());
|
| 19 |
+
|
| 20 |
+
if (ndims <= 1) {
|
| 21 |
+
nframe = 1;
|
| 22 |
+
dim = ndims == 0 ? 1 : input.size(0);
|
| 23 |
+
TORCH_CHECK(
|
| 24 |
+
target.dim() <= 1 && target.numel() == dim,
|
| 25 |
+
"inconsistent target size: ", target.sizes(), " for input of size: ",
|
| 26 |
+
input.sizes());
|
| 27 |
+
} else {
|
| 28 |
+
nframe = input.size(0);
|
| 29 |
+
dim = input.size(1);
|
| 30 |
+
TORCH_CHECK(
|
| 31 |
+
target.dim() == 2 && target.size(0) == nframe &&
|
| 32 |
+
target.size(1) == dim,
|
| 33 |
+
"inconsistent target size: ", target.sizes(), " for input of size: ",
|
| 34 |
+
input.sizes());
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
static C10_UNUSED void multi_margin_loss_shape_check(
|
| 39 |
+
int64_t& nframe,
|
| 40 |
+
int64_t& dim,
|
| 41 |
+
const int64_t& ndims,
|
| 42 |
+
const Tensor& input,
|
| 43 |
+
const Tensor& target,
|
| 44 |
+
const c10::optional<Tensor>& weight) {
|
| 45 |
+
TORCH_CHECK(
|
| 46 |
+
(ndims == 2 && input.size(1) != 0) || (ndims == 1 && input.size(0) != 0) || ndims == 0,
|
| 47 |
+
"Expected non-empty vector or matrix with optional 0-dim batch size, but got: ",
|
| 48 |
+
input.sizes());
|
| 49 |
+
|
| 50 |
+
if (ndims <= 1) {
|
| 51 |
+
nframe = 1;
|
| 52 |
+
dim = ndims == 0 ? 1 : input.size(0);
|
| 53 |
+
} else {
|
| 54 |
+
nframe = input.size(0);
|
| 55 |
+
dim = input.size(1);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
TORCH_CHECK(
|
| 59 |
+
target.dim() <= 1 && target.numel() == nframe,
|
| 60 |
+
"inconsistent target size, expected ", nframe, " but got ",
|
| 61 |
+
target.sizes());
|
| 62 |
+
if (weight && weight->defined()) {
|
| 63 |
+
TORCH_CHECK(
|
| 64 |
+
weight->dim() <= 1 && weight->numel() == dim,
|
| 65 |
+
"inconsistent weight size, expected ", dim, " but got ",
|
| 66 |
+
weight->sizes());
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
} // anonymous namespace
|
| 72 |
+
} // namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/Repeat.h
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/core/Tensor.h>
|
| 4 |
+
#include <ATen/TensorOperators.h>
|
| 5 |
+
|
| 6 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 7 |
+
#include <ATen/Functions.h>
|
| 8 |
+
#else
|
| 9 |
+
#include <ATen/ops/empty.h>
|
| 10 |
+
#include <ATen/ops/empty_like.h>
|
| 11 |
+
#endif
|
| 12 |
+
|
| 13 |
+
namespace at::native {
|
| 14 |
+
|
| 15 |
+
template <
|
| 16 |
+
typename index_t,
|
| 17 |
+
void compute(index_t*, int64_t*, index_t*, int64_t, int64_t)>
|
| 18 |
+
static inline Tensor repeat_interleave_common(
|
| 19 |
+
const Tensor& repeats,
|
| 20 |
+
c10::optional<int64_t> output_size) {
|
| 21 |
+
TORCH_CHECK(
|
| 22 |
+
repeats.dim() == 1, "repeat_interleave only accept 1D vector as repeat");
|
| 23 |
+
TORCH_CHECK(
|
| 24 |
+
repeats.scalar_type() == at::kLong || repeats.scalar_type() == at::kInt,
|
| 25 |
+
"repeats has to be Long or Int tensor");
|
| 26 |
+
if (repeats.size(0) == 0) {
|
| 27 |
+
return at::empty_like(repeats, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
|
| 28 |
+
}
|
| 29 |
+
Tensor repeats_ = repeats.contiguous();
|
| 30 |
+
Tensor cumsum = repeats.cumsum(0);
|
| 31 |
+
int64_t total;
|
| 32 |
+
if (output_size.has_value()) {
|
| 33 |
+
total = output_size.value();
|
| 34 |
+
} else {
|
| 35 |
+
total = cumsum[-1].item<int64_t>();
|
| 36 |
+
TORCH_CHECK(
|
| 37 |
+
(repeats >= 0).all().item<uint8_t>(), "repeats can not be negative");
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
Tensor result = at::empty({total}, repeats.options());
|
| 41 |
+
index_t* repeat_ptr = repeats_.data_ptr<index_t>();
|
| 42 |
+
int64_t* cumsum_ptr = cumsum.data_ptr<int64_t>();
|
| 43 |
+
index_t* result_ptr = result.data_ptr<index_t>();
|
| 44 |
+
compute(repeat_ptr, cumsum_ptr, result_ptr, repeats.size(0), total);
|
| 45 |
+
return result;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
} // namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/ScatterGatherChecks.h
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <vector>
|
| 4 |
+
#include <ATen/core/Tensor.h>
|
| 5 |
+
#include <ATen/native/ReduceOpsUtils.h>
|
| 6 |
+
#include <c10/util/irange.h>
|
| 7 |
+
|
| 8 |
+
namespace at::native {
|
| 9 |
+
|
| 10 |
+
namespace {
|
| 11 |
+
|
| 12 |
+
// checks whether index.dtype == int64
|
| 13 |
+
// and self.dtype == src.dtype if src is a Tensor
|
| 14 |
+
static void scatter_gather_dtype_check(
|
| 15 |
+
const std::string& method_name,
|
| 16 |
+
const Tensor& self,
|
| 17 |
+
const Tensor& index,
|
| 18 |
+
const c10::optional<Tensor>& src_opt = c10::nullopt
|
| 19 |
+
) {
|
| 20 |
+
if (index.numel() != 0) {
|
| 21 |
+
TORCH_CHECK(
|
| 22 |
+
index.scalar_type() == at::ScalarType::Long,
|
| 23 |
+
method_name, "(): Expected dtype int64 for index"
|
| 24 |
+
);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
if (src_opt.has_value()) {
|
| 28 |
+
const auto& src = src_opt.value();
|
| 29 |
+
TORCH_CHECK(
|
| 30 |
+
self.scalar_type() == src.scalar_type(),
|
| 31 |
+
method_name, "(): Expected self.dtype to be equal to src.dtype"
|
| 32 |
+
);
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// Used for `gather`-like methods
|
| 37 |
+
// Note: self means the input tensor here
|
| 38 |
+
// Test:
|
| 39 |
+
// 1. index.size(d) <= self.size(d) for all d != dim
|
| 40 |
+
// 2. index.dim() == self.dim()
|
| 41 |
+
static C10_UNUSED void gather_shape_check(const Tensor& self, int64_t dim,
|
| 42 |
+
const Tensor& index
|
| 43 |
+
) {
|
| 44 |
+
auto self_dims = ensure_nonempty_dim(self.dim());
|
| 45 |
+
TORCH_CHECK(self_dims == ensure_nonempty_dim(index.dim()),
|
| 46 |
+
"Index tensor must have the same number of dimensions as input tensor"
|
| 47 |
+
);
|
| 48 |
+
|
| 49 |
+
for (const auto i : c10::irange(self_dims)) {
|
| 50 |
+
if (i != dim) {
|
| 51 |
+
TORCH_CHECK(
|
| 52 |
+
ensure_nonempty_size(index, i) <= ensure_nonempty_size(self, i),
|
| 53 |
+
"Size does not match at dimension ", i,
|
| 54 |
+
" expected index ", index.sizes(),
|
| 55 |
+
" to be smaller than self ", self.sizes(),
|
| 56 |
+
" apart from dimension ", dim
|
| 57 |
+
);
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// Used for `scatter` and `scatter_add`
|
| 63 |
+
// Tests:
|
| 64 |
+
// 1. index.size(d) <= self.size(d) for all d != dim
|
| 65 |
+
// 2. index.size(d) <= src.size(d) for all d if src is a Tensor
|
| 66 |
+
// 3. index.dim() == self.dim() == src.dim()
|
| 67 |
+
static C10_UNUSED void scatter_shape_check(
|
| 68 |
+
const Tensor& self, int64_t dim, const Tensor& index,
|
| 69 |
+
const c10::optional<Tensor>& src_opt = c10::nullopt
|
| 70 |
+
) {
|
| 71 |
+
if (index.numel() == 0) return;
|
| 72 |
+
TORCH_CHECK(
|
| 73 |
+
ensure_nonempty_dim(self.dim()) == ensure_nonempty_dim(index.dim()),
|
| 74 |
+
"Index tensor must have the same number of dimensions as self tensor"
|
| 75 |
+
);
|
| 76 |
+
|
| 77 |
+
bool is_wrong_shape = false;
|
| 78 |
+
int64_t self_dims = ensure_nonempty_dim(self.dim());
|
| 79 |
+
|
| 80 |
+
// Check: index.size(d) <= self.size(d) for all d != dim
|
| 81 |
+
for (const auto d : c10::irange(self_dims)) {
|
| 82 |
+
int64_t index_d_size = ensure_nonempty_size(index, d);
|
| 83 |
+
if (d == dim) continue;
|
| 84 |
+
if (index_d_size > ensure_nonempty_size(self, d)) {
|
| 85 |
+
is_wrong_shape = true;
|
| 86 |
+
break;
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
// Check: index.size(d) <= src.size(d) for all d if src is Tensor
|
| 91 |
+
if (!is_wrong_shape && src_opt.has_value()) {
|
| 92 |
+
const auto& src = src_opt.value();
|
| 93 |
+
for (const auto d : c10::irange(self_dims)) {
|
| 94 |
+
int64_t index_d_size = ensure_nonempty_size(index, d);
|
| 95 |
+
if (index_d_size > ensure_nonempty_size(src, d)) {
|
| 96 |
+
is_wrong_shape = true;
|
| 97 |
+
break;
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
if (src_opt.has_value()) {
|
| 103 |
+
const auto& src = src_opt.value();
|
| 104 |
+
|
| 105 |
+
TORCH_CHECK(
|
| 106 |
+
ensure_nonempty_dim(src.dim()) == ensure_nonempty_dim(index.dim()),
|
| 107 |
+
"Index tensor must have the same number of dimensions as src tensor"
|
| 108 |
+
);
|
| 109 |
+
|
| 110 |
+
TORCH_CHECK(!is_wrong_shape,
|
| 111 |
+
"Expected index ", index.sizes(),
|
| 112 |
+
" to be smaller than self ", self.sizes(),
|
| 113 |
+
" apart from dimension ", dim,
|
| 114 |
+
" and to be smaller size than src ", src.sizes()
|
| 115 |
+
);
|
| 116 |
+
}
|
| 117 |
+
else {
|
| 118 |
+
TORCH_CHECK(!is_wrong_shape,
|
| 119 |
+
"Expected index ", index.sizes(),
|
| 120 |
+
" to be smaller than self ", self.sizes(),
|
| 121 |
+
" apart from dimension ", dim
|
| 122 |
+
);
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
} // anonymous namespace
|
| 127 |
+
|
| 128 |
+
} // namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/SegmentReduce.h
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/native/DispatchStub.h>
|
| 4 |
+
#include <ATen/native/ReductionType.h>
|
| 5 |
+
#include <c10/core/Scalar.h>
|
| 6 |
+
#include <c10/util/Optional.h>
|
| 7 |
+
|
| 8 |
+
namespace at {
|
| 9 |
+
class Tensor;
|
| 10 |
+
|
| 11 |
+
namespace native {
|
| 12 |
+
|
| 13 |
+
using segment_reduce_lengths_fn = Tensor (*)(
|
| 14 |
+
ReductionType,
|
| 15 |
+
const Tensor&,
|
| 16 |
+
const Tensor&,
|
| 17 |
+
int64_t,
|
| 18 |
+
const c10::optional<Scalar>&);
|
| 19 |
+
DECLARE_DISPATCH(segment_reduce_lengths_fn, _segment_reduce_lengths_stub);
|
| 20 |
+
|
| 21 |
+
using segment_reduce_offsets_fn = Tensor (*)(
|
| 22 |
+
ReductionType,
|
| 23 |
+
const Tensor&,
|
| 24 |
+
const Tensor&,
|
| 25 |
+
int64_t,
|
| 26 |
+
const c10::optional<Scalar>&);
|
| 27 |
+
DECLARE_DISPATCH(segment_reduce_offsets_fn, _segment_reduce_offsets_stub);
|
| 28 |
+
|
| 29 |
+
using segment_reduce_lengths_backward_fn = Tensor (*)(
|
| 30 |
+
const Tensor&,
|
| 31 |
+
const Tensor&,
|
| 32 |
+
const Tensor&,
|
| 33 |
+
ReductionType,
|
| 34 |
+
const Tensor&,
|
| 35 |
+
int64_t,
|
| 36 |
+
const c10::optional<Scalar>&);
|
| 37 |
+
DECLARE_DISPATCH(segment_reduce_lengths_backward_fn, _segment_reduce_lengths_backward_stub);
|
| 38 |
+
|
| 39 |
+
using segment_reduce_offsets_backward_fn = Tensor (*)(
|
| 40 |
+
const Tensor&,
|
| 41 |
+
const Tensor&,
|
| 42 |
+
const Tensor&,
|
| 43 |
+
ReductionType,
|
| 44 |
+
const Tensor&,
|
| 45 |
+
int64_t,
|
| 46 |
+
const c10::optional<Scalar>&);
|
| 47 |
+
DECLARE_DISPATCH(segment_reduce_offsets_backward_fn, _segment_reduce_offsets_backward_stub);
|
| 48 |
+
|
| 49 |
+
} // namespace native
|
| 50 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/TensorIteratorDynamicCasting.h
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <complex>
|
| 4 |
+
#include <type_traits>
|
| 5 |
+
#include <c10/core/ScalarType.h>
|
| 6 |
+
#include <c10/util/C++17.h>
|
| 7 |
+
#include <ATen/detail/FunctionTraits.h>
|
| 8 |
+
#include <ATen/native/TensorIterator.h>
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
// This file includes utilties for dynamic_casting done by TensorIterator, see CUDALoops.cuh and Loops.h.
|
| 12 |
+
|
| 13 |
+
// dynamic_casting handles when the types expected by the iterator do not match the types of the arguments
|
| 14 |
+
// to the function that is being called.
|
| 15 |
+
// On CUDA, the cast is currently pushed down into the kernel (for performance reasons).
|
| 16 |
+
// On CPU, there is currently an internal assert that a dynamic_cast is not needed.
|
| 17 |
+
|
| 18 |
+
namespace at::native {
|
| 19 |
+
|
| 20 |
+
// `needs_dynamic_casting` compares the types expected by iterator
|
| 21 |
+
// (i.e. dtypes of the operands) with the actual type of the arguments
|
| 22 |
+
// (and returns) of func_t
|
| 23 |
+
template<typename func_t, int nargs=function_traits<func_t>::arity>
|
| 24 |
+
struct needs_dynamic_casting {
|
| 25 |
+
static bool check(TensorIteratorBase& iter) {
|
| 26 |
+
using traits = function_traits<func_t>;
|
| 27 |
+
using cpp_type = typename traits::template arg<nargs - 1>::type;
|
| 28 |
+
using cpp_map = c10::CppTypeToScalarType<cpp_type>;
|
| 29 |
+
|
| 30 |
+
if (iter.input_dtype(nargs-1) != cpp_map::value) {
|
| 31 |
+
return true;
|
| 32 |
+
}
|
| 33 |
+
return needs_dynamic_casting<func_t, nargs - 1>::check(iter);
|
| 34 |
+
}
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
template<typename func_t>
|
| 38 |
+
struct needs_dynamic_casting<func_t, 0> {
|
| 39 |
+
static bool check(TensorIteratorBase& iter) {
|
| 40 |
+
using traits = function_traits<func_t>;
|
| 41 |
+
using cpp_type = typename traits::result_type;
|
| 42 |
+
|
| 43 |
+
// we could assert output numbers are correct here, but checks
|
| 44 |
+
// (including arity) are currently pushed outside of this struct.
|
| 45 |
+
if constexpr (std::is_void_v<cpp_type>) {
|
| 46 |
+
return false;
|
| 47 |
+
} else {
|
| 48 |
+
return iter.dtype(0) != c10::CppTypeToScalarType<cpp_type>::value;
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
} //namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/TensorShape.h
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
#include <ATen/core/Tensor.h>
|
| 3 |
+
#include <c10/util/irange.h>
|
| 4 |
+
#include <ATen/core/IListRef.h>
|
| 5 |
+
|
| 6 |
+
namespace at::native {
|
| 7 |
+
|
| 8 |
+
TORCH_API at::Tensor clone_preserve_strides(const at::Tensor& self);
|
| 9 |
+
|
| 10 |
+
inline bool cat_should_skip_tensor(const Tensor& t) {
|
| 11 |
+
return t.numel() == 0 && t.dim() == 1;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
// Check to see if the shape of tensors is compatible
|
| 15 |
+
// for being concatenated along a given dimension.
|
| 16 |
+
inline void check_cat_shape_except_dim(const Tensor & first, const Tensor & second, int64_t dimension, int64_t index) {
|
| 17 |
+
int64_t first_dims = first.dim();
|
| 18 |
+
int64_t second_dims = second.dim();
|
| 19 |
+
TORCH_CHECK(first_dims == second_dims, "Tensors must have same number of dimensions: got ",
|
| 20 |
+
first_dims, " and ", second_dims);
|
| 21 |
+
for (const auto dim : c10::irange(first_dims)) {
|
| 22 |
+
if (dim == dimension) {
|
| 23 |
+
continue;
|
| 24 |
+
}
|
| 25 |
+
int64_t first_dim_size = first.sizes()[dim];
|
| 26 |
+
int64_t second_dim_size = second.sizes()[dim];
|
| 27 |
+
TORCH_CHECK(first_dim_size == second_dim_size, "Sizes of tensors must match except in dimension ",
|
| 28 |
+
dimension, ". Expected size ", static_cast<long long>(first_dim_size), " but got size ", static_cast<long long>(second_dim_size), " for tensor number ", index, " in the list.");
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
inline void check_cat_no_zero_dim(const MaterializedITensorListRef& tensors) {
|
| 33 |
+
int64_t i = 0;
|
| 34 |
+
for(const Tensor& t : tensors) {
|
| 35 |
+
TORCH_CHECK(t.dim() > 0,
|
| 36 |
+
"zero-dimensional tensor (at position ", i, ") cannot be concatenated");
|
| 37 |
+
i++;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
inline int64_t get_num_splits(const Tensor& self, int64_t split_size, int64_t dim) {
|
| 42 |
+
TORCH_CHECK(self.dim() != 0, "split expects at least a 1-dimensional tensor");
|
| 43 |
+
TORCH_CHECK(split_size >= 0, "split expects split_size be non-negative, but got split_size=", split_size);
|
| 44 |
+
int64_t dim_size = self.size(dim);
|
| 45 |
+
TORCH_CHECK(split_size > 0 || dim_size == 0,
|
| 46 |
+
"split_size can only be 0 if dimension size is 0, "
|
| 47 |
+
"but got dimension size of ", dim_size);
|
| 48 |
+
// if split_size is 0 and dimension size is 0, there is 1 split.
|
| 49 |
+
int64_t num_splits = 1;
|
| 50 |
+
if (split_size != 0) {
|
| 51 |
+
// ensuring num_splits is at least 1 makes consistent the case where split_size > dim_size
|
| 52 |
+
// (returns a single split). We might want to error here, but keep it for BC.
|
| 53 |
+
num_splits = std::max<int64_t>((dim_size + split_size - 1) / split_size, 1);
|
| 54 |
+
}
|
| 55 |
+
return num_splits;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
} // namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/TransposeType.h
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
#include <c10/util/Exception.h>
|
| 3 |
+
|
| 4 |
+
namespace at::native {
|
| 5 |
+
|
| 6 |
+
// Used as an interface between the different BLAS-like libraries
|
| 7 |
+
enum class TransposeType {
|
| 8 |
+
NoTranspose,
|
| 9 |
+
Transpose,
|
| 10 |
+
ConjTranspose,
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
// Transforms TransposeType into the BLAS / LAPACK format
|
| 14 |
+
static inline char to_blas(TransposeType trans) {
|
| 15 |
+
switch (trans) {
|
| 16 |
+
case TransposeType::Transpose: return 'T';
|
| 17 |
+
case TransposeType::NoTranspose: return 'N';
|
| 18 |
+
case TransposeType::ConjTranspose: return 'C';
|
| 19 |
+
}
|
| 20 |
+
TORCH_INTERNAL_ASSERT(false, "Invalid transpose type");
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
} // namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/UnfoldBackward.h
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/core/Tensor.h>
|
| 4 |
+
#include <ATen/TensorIterator.h>
|
| 5 |
+
#include <ATen/native/DispatchStub.h>
|
| 6 |
+
#include <ATen/native/NonEmptyUtils.h>
|
| 7 |
+
|
| 8 |
+
#ifndef AT_PER_OPERATOR_HEADERS
|
| 9 |
+
#include <ATen/Functions.h>
|
| 10 |
+
#else
|
| 11 |
+
#include <ATen/ops/arange.h>
|
| 12 |
+
#endif
|
| 13 |
+
|
| 14 |
+
namespace at::native {
|
| 15 |
+
|
| 16 |
+
using unfold_backward_fn = void (*)(
|
| 17 |
+
Tensor& grad_in,
|
| 18 |
+
const Tensor& grad,
|
| 19 |
+
int64_t dim,
|
| 20 |
+
int64_t size,
|
| 21 |
+
int64_t step
|
| 22 |
+
);
|
| 23 |
+
|
| 24 |
+
DECLARE_DISPATCH(unfold_backward_fn, unfold_backward_stub);
|
| 25 |
+
|
| 26 |
+
namespace {
|
| 27 |
+
|
| 28 |
+
// Note on naming: it is unconventional.
|
| 29 |
+
// grad_in does not mean that it is a gradient wrt to input,
|
| 30 |
+
// grad_in/grad_out is just an input/output of unfold_backward kernel.
|
| 31 |
+
|
| 32 |
+
static C10_UNUSED TensorIterator _make_unfold_backward_iter_over_grad_out(
|
| 33 |
+
Tensor& grad_out,
|
| 34 |
+
const Tensor& grad_in,
|
| 35 |
+
int64_t dim,
|
| 36 |
+
int64_t size,
|
| 37 |
+
int64_t step
|
| 38 |
+
) {
|
| 39 |
+
dim = maybe_wrap_dim(dim, grad_out.dim());
|
| 40 |
+
// last dim stores the folds
|
| 41 |
+
|
| 42 |
+
auto grad_out_dim_size = ensure_nonempty_size(grad_out, dim);
|
| 43 |
+
auto grad_in_dim_size = ensure_nonempty_size(grad_in, dim);
|
| 44 |
+
// dictates the number of elements to iterate over
|
| 45 |
+
// in dimension `dim`
|
| 46 |
+
auto iter_dim_size = std::min(
|
| 47 |
+
grad_out_dim_size,
|
| 48 |
+
(grad_in_dim_size - 1) * step + size
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
/* prepare grad_out for TensorIterator { */
|
| 52 |
+
auto grad_out_strides = ensure_nonempty_vec(grad_out.strides().vec());
|
| 53 |
+
auto grad_out_sizes = ensure_nonempty_vec(grad_out.sizes().vec());
|
| 54 |
+
grad_out_sizes[dim] = iter_dim_size;
|
| 55 |
+
auto grad_out_restrided = grad_out.as_strided(
|
| 56 |
+
grad_out_sizes, grad_out_strides
|
| 57 |
+
);
|
| 58 |
+
/* } */
|
| 59 |
+
|
| 60 |
+
/* prepare grad_in for TensorIterator { */
|
| 61 |
+
auto grad_in_strides = ensure_nonempty_vec(grad_in.strides().vec());
|
| 62 |
+
auto grad_in_sizes = ensure_nonempty_vec(grad_in.sizes().vec());
|
| 63 |
+
|
| 64 |
+
// set strides for dim to 0
|
| 65 |
+
// and size to 1 because
|
| 66 |
+
// this dimension is indexed inside the kernel
|
| 67 |
+
grad_in_strides[dim] = 0;
|
| 68 |
+
grad_in_sizes[dim] = 1;
|
| 69 |
+
|
| 70 |
+
grad_in_strides.pop_back();
|
| 71 |
+
grad_in_sizes.pop_back();
|
| 72 |
+
|
| 73 |
+
auto grad_in_restrided = grad_in.squeeze(-1).as_strided(
|
| 74 |
+
grad_in_sizes, grad_in_strides
|
| 75 |
+
);
|
| 76 |
+
/* } */
|
| 77 |
+
|
| 78 |
+
// During the TensorIterator iteration we have to know
|
| 79 |
+
// i_dim in grad_out[i_1,...,i_dim,...i_n],
|
| 80 |
+
// idx_dim stores this information
|
| 81 |
+
/* prepare idx_dim for TensorIterator { */
|
| 82 |
+
auto idx_dim = at::arange(
|
| 83 |
+
0, iter_dim_size, grad_in.options().dtype(at::kLong)
|
| 84 |
+
);
|
| 85 |
+
|
| 86 |
+
auto grad_out_dim = ensure_nonempty_dim(grad_out.dim());
|
| 87 |
+
|
| 88 |
+
auto idx_dim_strides = std::vector<int64_t>(grad_out_dim, 0);
|
| 89 |
+
auto idx_dim_sizes = std::vector<int64_t>(grad_out_dim, 1);
|
| 90 |
+
|
| 91 |
+
idx_dim_strides[dim] = 1;
|
| 92 |
+
idx_dim_sizes[dim] = iter_dim_size;
|
| 93 |
+
|
| 94 |
+
// idx_dim size will broadcast over determined by grad_out sizes in TensorIterator
|
| 95 |
+
auto idx_dim_restrided = idx_dim.as_strided(idx_dim_sizes, idx_dim_strides);
|
| 96 |
+
/* } */
|
| 97 |
+
|
| 98 |
+
auto iter = TensorIteratorConfig()
|
| 99 |
+
.set_check_mem_overlap(false)
|
| 100 |
+
.check_all_same_dtype(false)
|
| 101 |
+
.resize_outputs(false)
|
| 102 |
+
.add_owned_output(grad_out_restrided)
|
| 103 |
+
.add_owned_input(grad_in_restrided)
|
| 104 |
+
.add_owned_input(idx_dim_restrided)
|
| 105 |
+
.build();
|
| 106 |
+
|
| 107 |
+
return iter;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
} // namespace at::native
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/group_norm.h
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/native/DispatchStub.h>
|
| 4 |
+
#include <cstdint>
|
| 5 |
+
|
| 6 |
+
namespace at {
|
| 7 |
+
class Tensor;
|
| 8 |
+
|
| 9 |
+
namespace native {
|
| 10 |
+
|
| 11 |
+
using forward_fn = void (*)(
|
| 12 |
+
const Tensor& /* X */,
|
| 13 |
+
const Tensor& /* gamma */,
|
| 14 |
+
const Tensor& /* beta */,
|
| 15 |
+
int64_t /* N */,
|
| 16 |
+
int64_t /* C */,
|
| 17 |
+
int64_t /* HxW */,
|
| 18 |
+
int64_t /* group */,
|
| 19 |
+
double /* eps */,
|
| 20 |
+
Tensor& /* Y */,
|
| 21 |
+
Tensor& /* mean */,
|
| 22 |
+
Tensor& /* rstd */);
|
| 23 |
+
|
| 24 |
+
using backward_fn = void (*)(
|
| 25 |
+
const Tensor& /* dY */,
|
| 26 |
+
const Tensor& /* X */,
|
| 27 |
+
const Tensor& /* mean */,
|
| 28 |
+
const Tensor& /* rstd */,
|
| 29 |
+
const Tensor& /* gamma */,
|
| 30 |
+
int64_t /* N */,
|
| 31 |
+
int64_t /* C */,
|
| 32 |
+
int64_t /* HxW */,
|
| 33 |
+
int64_t /* group */,
|
| 34 |
+
Tensor& /* dX */,
|
| 35 |
+
Tensor& /* dgamma */,
|
| 36 |
+
Tensor& /* dbeta */);
|
| 37 |
+
|
| 38 |
+
DECLARE_DISPATCH(forward_fn, GroupNormKernel);
|
| 39 |
+
DECLARE_DISPATCH(backward_fn, GroupNormBackwardKernel);
|
| 40 |
+
|
| 41 |
+
} // namespace native
|
| 42 |
+
} // namespace at
|
videollama2/lib/python3.10/site-packages/torch/include/ATen/native/im2col.h
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <ATen/core/Tensor.h>
|
| 4 |
+
#include <ATen/TensorUtils.h>
|
| 5 |
+
#include <ATen/Utils.h>
|
| 6 |
+
#include <ATen/Parallel.h>
|
| 7 |
+
#include <ATen/native/cpu/utils.h>
|
| 8 |
+
#include <c10/util/irange.h>
|
| 9 |
+
|
| 10 |
+
#include <algorithm>
|
| 11 |
+
|
| 12 |
+
namespace at::native {
|
| 13 |
+
|
| 14 |
+
template <typename T>
|
| 15 |
+
static void im2col(
|
| 16 |
+
const T* data_im,
|
| 17 |
+
const int64_t channels,
|
| 18 |
+
const int64_t height,
|
| 19 |
+
const int64_t width,
|
| 20 |
+
const int64_t output_height,
|
| 21 |
+
const int64_t output_width,
|
| 22 |
+
const int64_t kernel_h,
|
| 23 |
+
const int64_t kernel_w,
|
| 24 |
+
const int64_t pad_h,
|
| 25 |
+
const int64_t pad_w,
|
| 26 |
+
const int64_t stride_h,
|
| 27 |
+
const int64_t stride_w,
|
| 28 |
+
const int64_t dilation_h,
|
| 29 |
+
const int64_t dilation_w,
|
| 30 |
+
T* data_col,
|
| 31 |
+
bool is_channels_last = false) {
|
| 32 |
+
const int64_t height_col = output_height;
|
| 33 |
+
const int64_t width_col = output_width;
|
| 34 |
+
const int64_t channels_col = channels * kernel_h * kernel_w;
|
| 35 |
+
|
| 36 |
+
if (is_channels_last) {
|
| 37 |
+
at::parallel_for(0, height_col * width_col, 0, [&](int64_t begin, int64_t end) {
|
| 38 |
+
int64_t h_col{0}, w_col{0};
|
| 39 |
+
data_index_init(begin, h_col, height_col, w_col, width_col);
|
| 40 |
+
|
| 41 |
+
for (const auto i_col : c10::irange(begin, end)) {
|
| 42 |
+
for (const auto h_offset : c10::irange(kernel_h)) {
|
| 43 |
+
int64_t h_im = h_col * stride_h - pad_h + h_offset * dilation_h;
|
| 44 |
+
for (const auto w_offset : c10::irange(kernel_w)) {
|
| 45 |
+
int64_t w_im = w_col * stride_w - pad_w + w_offset * dilation_w;
|
| 46 |
+
|
| 47 |
+
const T* slice_im = data_im + (h_im * width + w_im) * channels;
|
| 48 |
+
T* slice_col = data_col + (i_col * kernel_h * kernel_w + h_offset * kernel_w + w_offset) * channels;
|
| 49 |
+
|
| 50 |
+
if (h_im >= 0 && w_im >= 0 && h_im < height && w_im < width) {
|
| 51 |
+
std::copy_n(slice_im, channels, slice_col);
|
| 52 |
+
} else {
|
| 53 |
+
std::fill_n(slice_col, channels, T(0));
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// move the next index
|
| 59 |
+
data_index_step(h_col, height_col, w_col, width_col);
|
| 60 |
+
}
|
| 61 |
+
});
|
| 62 |
+
} else {
|
| 63 |
+
at::parallel_for(0, channels_col, 0, [&](int64_t begin, int64_t end) {
|
| 64 |
+
int64_t c_im{0}, h_offset{0}, w_offset{0};
|
| 65 |
+
data_index_init(begin, c_im, channels, h_offset, kernel_h, w_offset, kernel_w);
|
| 66 |
+
|
| 67 |
+
for (const auto c_col : c10::irange(begin, end)) {
|
| 68 |
+
for (const auto h_col : c10::irange(height_col)) {
|
| 69 |
+
int64_t h_im = h_col * stride_h - pad_h + h_offset * dilation_h;
|
| 70 |
+
for (const auto w_col : c10::irange(width_col)) {
|
| 71 |
+
int64_t w_im = w_col * stride_w - pad_w + w_offset * dilation_w;
|
| 72 |
+
data_col[(c_col * height_col + h_col) * width_col + w_col] =
|
| 73 |
+
(h_im >= 0 && w_im >= 0 && h_im < height && w_im < width)
|
| 74 |
+
? data_im[(c_im * height + h_im) * width + w_im]
|
| 75 |
+
: static_cast<T>(0);
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// move to the next index
|
| 80 |
+
data_index_step(c_im, channels, h_offset, kernel_h, w_offset, kernel_w);
|
| 81 |
+
}
|
| 82 |
+
});
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
template <typename T>
|
| 87 |
+
static void col2im(
|
| 88 |
+
const T* data_col,
|
| 89 |
+
const int64_t channels,
|
| 90 |
+
const int64_t height,
|
| 91 |
+
const int64_t width,
|
| 92 |
+
const int64_t output_height,
|
| 93 |
+
const int64_t output_width,
|
| 94 |
+
const int64_t kernel_h,
|
| 95 |
+
const int64_t kernel_w,
|
| 96 |
+
const int64_t pad_h,
|
| 97 |
+
const int64_t pad_w,
|
| 98 |
+
const int64_t stride_h,
|
| 99 |
+
const int64_t stride_w,
|
| 100 |
+
const int64_t dilation_h,
|
| 101 |
+
const int64_t dilation_w,
|
| 102 |
+
T* data_im,
|
| 103 |
+
bool is_channels_last = false) {
|
| 104 |
+
std::fill_n(data_im, height * width * channels, T(0));
|
| 105 |
+
|
| 106 |
+
const int64_t height_col = output_height;
|
| 107 |
+
const int64_t width_col = output_width;
|
| 108 |
+
const int64_t channels_col = channels * kernel_h * kernel_w;
|
| 109 |
+
|
| 110 |
+
if (is_channels_last) {
|
| 111 |
+
for (const auto h_col : c10::irange(height_col)) {
|
| 112 |
+
for (const auto w_col : c10::irange(width_col)) {
|
| 113 |
+
for (const auto h_offset : c10::irange(kernel_h)) {
|
| 114 |
+
int64_t h_im = h_col * stride_h - pad_h + h_offset * dilation_h;
|
| 115 |
+
for (const auto w_offset : c10::irange(kernel_w)) {
|
| 116 |
+
int64_t w_im = w_col * stride_w - pad_w + w_offset * dilation_w;
|
| 117 |
+
|
| 118 |
+
T* slice_im = data_im + (h_im * width + w_im) * channels;
|
| 119 |
+
const T* slice_col = data_col + ((h_col * width_col + w_col) * kernel_h * kernel_w
|
| 120 |
+
+ h_offset * kernel_w + w_offset) * channels;
|
| 121 |
+
|
| 122 |
+
if (h_im >= 0 && h_im < height && w_im >= 0 && w_im < width) {
|
| 123 |
+
std::transform(slice_col, slice_col + channels, slice_im, slice_im, std::plus<T>());
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
} else {
|
| 130 |
+
for (const auto c_col : c10::irange(channels_col)) {
|
| 131 |
+
int64_t w_offset = c_col % kernel_w;
|
| 132 |
+
int64_t h_offset = (c_col / kernel_w) % kernel_h;
|
| 133 |
+
int64_t c_im = c_col / kernel_h / kernel_w;
|
| 134 |
+
|
| 135 |
+
for (const auto h_col : c10::irange(height_col)) {
|
| 136 |
+
int64_t h_im = h_col * stride_h - pad_h + h_offset * dilation_h;
|
| 137 |
+
for (const auto w_col : c10::irange(width_col)) {
|
| 138 |
+
int64_t w_im = w_col * stride_w - pad_w + w_offset * dilation_w;
|
| 139 |
+
|
| 140 |
+
if (h_im >= 0 && h_im < height && w_im >= 0 && w_im < width)
|
| 141 |
+
data_im[(c_im * height + h_im) * width + w_im] +=
|
| 142 |
+
data_col[(c_col * height_col + h_col) * width_col + w_col];
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
} // namespace at::native
|
vllm/lib/python3.10/site-packages/sympy/printing/__pycache__/defaults.cpython-310.pyc
ADDED
|
Binary file (276 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (170 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_aesaracode.cpython-310.pyc
ADDED
|
Binary file (21.2 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_c.cpython-310.pyc
ADDED
|
Binary file (31.2 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_codeprinter.cpython-310.pyc
ADDED
|
Binary file (2.1 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_conventions.cpython-310.pyc
ADDED
|
Binary file (3.81 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_cupy.cpython-310.pyc
ADDED
|
Binary file (2.65 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_cxx.cpython-310.pyc
ADDED
|
Binary file (4.48 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_dot.cpython-310.pyc
ADDED
|
Binary file (5.93 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_fortran.cpython-310.pyc
ADDED
|
Binary file (32.4 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_glsl.cpython-310.pyc
ADDED
|
Binary file (26.1 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_gtk.cpython-310.pyc
ADDED
|
Binary file (900 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_jax.cpython-310.pyc
ADDED
|
Binary file (11.8 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_jscode.cpython-310.pyc
ADDED
|
Binary file (12.4 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_julia.cpython-310.pyc
ADDED
|
Binary file (14.8 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_llvmjit.cpython-310.pyc
ADDED
|
Binary file (6.7 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_maple.cpython-310.pyc
ADDED
|
Binary file (14.4 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_mathematica.cpython-310.pyc
ADDED
|
Binary file (10.9 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_mathml.cpython-310.pyc
ADDED
|
Binary file (81.1 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_numpy.cpython-310.pyc
ADDED
|
Binary file (12.1 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_octave.cpython-310.pyc
ADDED
|
Binary file (20.8 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_precedence.cpython-310.pyc
ADDED
|
Binary file (3.38 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_preview.cpython-310.pyc
ADDED
|
Binary file (1.13 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_pycode.cpython-310.pyc
ADDED
|
Binary file (16.2 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_python.cpython-310.pyc
ADDED
|
Binary file (8.35 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_rcode.cpython-310.pyc
ADDED
|
Binary file (15.5 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_repr.cpython-310.pyc
ADDED
|
Binary file (16.3 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_smtlib.cpython-310.pyc
ADDED
|
Binary file (17.6 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_str.cpython-310.pyc
ADDED
|
Binary file (49.5 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_tableform.cpython-310.pyc
ADDED
|
Binary file (4.33 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_tensorflow.cpython-310.pyc
ADDED
|
Binary file (15.4 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_theanocode.cpython-310.pyc
ADDED
|
Binary file (21.6 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/__pycache__/test_tree.cpython-310.pyc
ADDED
|
Binary file (4.47 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/sympy/printing/tests/test_aesaracode.py
ADDED
|
@@ -0,0 +1,626 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Important note on tests in this module - the Aesara printing functions use a
|
| 3 |
+
global cache by default, which means that tests using it will modify global
|
| 4 |
+
state and thus not be independent from each other. Instead of using the "cache"
|
| 5 |
+
keyword argument each time, this module uses the aesara_code_ and
|
| 6 |
+
aesara_function_ functions defined below which default to using a new, empty
|
| 7 |
+
cache instead.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import logging
|
| 11 |
+
|
| 12 |
+
from sympy.external import import_module
|
| 13 |
+
from sympy.testing.pytest import raises, SKIP
|
| 14 |
+
|
| 15 |
+
from sympy.utilities.exceptions import ignore_warnings
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
aesaralogger = logging.getLogger('aesara.configdefaults')
|
| 19 |
+
aesaralogger.setLevel(logging.CRITICAL)
|
| 20 |
+
aesara = import_module('aesara')
|
| 21 |
+
aesaralogger.setLevel(logging.WARNING)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
if aesara:
|
| 25 |
+
import numpy as np
|
| 26 |
+
aet = aesara.tensor
|
| 27 |
+
from aesara.scalar.basic import ScalarType
|
| 28 |
+
from aesara.graph.basic import Variable
|
| 29 |
+
from aesara.tensor.var import TensorVariable
|
| 30 |
+
from aesara.tensor.elemwise import Elemwise, DimShuffle
|
| 31 |
+
from aesara.tensor.math import Dot
|
| 32 |
+
|
| 33 |
+
from sympy.printing.aesaracode import true_divide
|
| 34 |
+
|
| 35 |
+
xt, yt, zt = [aet.scalar(name, 'floatX') for name in 'xyz']
|
| 36 |
+
Xt, Yt, Zt = [aet.tensor('floatX', (False, False), name=n) for n in 'XYZ']
|
| 37 |
+
else:
|
| 38 |
+
#bin/test will not execute any tests now
|
| 39 |
+
disabled = True
|
| 40 |
+
|
| 41 |
+
import sympy as sy
|
| 42 |
+
from sympy.core.singleton import S
|
| 43 |
+
from sympy.abc import x, y, z, t
|
| 44 |
+
from sympy.printing.aesaracode import (aesara_code, dim_handling,
|
| 45 |
+
aesara_function)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# Default set of matrix symbols for testing - make square so we can both
|
| 49 |
+
# multiply and perform elementwise operations between them.
|
| 50 |
+
X, Y, Z = [sy.MatrixSymbol(n, 4, 4) for n in 'XYZ']
|
| 51 |
+
|
| 52 |
+
# For testing AppliedUndef
|
| 53 |
+
f_t = sy.Function('f')(t)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def aesara_code_(expr, **kwargs):
|
| 57 |
+
""" Wrapper for aesara_code that uses a new, empty cache by default. """
|
| 58 |
+
kwargs.setdefault('cache', {})
|
| 59 |
+
return aesara_code(expr, **kwargs)
|
| 60 |
+
|
| 61 |
+
def aesara_function_(inputs, outputs, **kwargs):
|
| 62 |
+
""" Wrapper for aesara_function that uses a new, empty cache by default. """
|
| 63 |
+
kwargs.setdefault('cache', {})
|
| 64 |
+
return aesara_function(inputs, outputs, **kwargs)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def fgraph_of(*exprs):
|
| 68 |
+
""" Transform SymPy expressions into Aesara Computation.
|
| 69 |
+
|
| 70 |
+
Parameters
|
| 71 |
+
==========
|
| 72 |
+
exprs
|
| 73 |
+
SymPy expressions
|
| 74 |
+
|
| 75 |
+
Returns
|
| 76 |
+
=======
|
| 77 |
+
aesara.graph.fg.FunctionGraph
|
| 78 |
+
"""
|
| 79 |
+
outs = list(map(aesara_code_, exprs))
|
| 80 |
+
ins = list(aesara.graph.basic.graph_inputs(outs))
|
| 81 |
+
ins, outs = aesara.graph.basic.clone(ins, outs)
|
| 82 |
+
return aesara.graph.fg.FunctionGraph(ins, outs)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def aesara_simplify(fgraph):
|
| 86 |
+
""" Simplify a Aesara Computation.
|
| 87 |
+
|
| 88 |
+
Parameters
|
| 89 |
+
==========
|
| 90 |
+
fgraph : aesara.graph.fg.FunctionGraph
|
| 91 |
+
|
| 92 |
+
Returns
|
| 93 |
+
=======
|
| 94 |
+
aesara.graph.fg.FunctionGraph
|
| 95 |
+
"""
|
| 96 |
+
mode = aesara.compile.get_default_mode().excluding("fusion")
|
| 97 |
+
fgraph = fgraph.clone()
|
| 98 |
+
mode.optimizer.rewrite(fgraph)
|
| 99 |
+
return fgraph
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def theq(a, b):
|
| 103 |
+
""" Test two Aesara objects for equality.
|
| 104 |
+
|
| 105 |
+
Also accepts numeric types and lists/tuples of supported types.
|
| 106 |
+
|
| 107 |
+
Note - debugprint() has a bug where it will accept numeric types but does
|
| 108 |
+
not respect the "file" argument and in this case and instead prints the number
|
| 109 |
+
to stdout and returns an empty string. This can lead to tests passing where
|
| 110 |
+
they should fail because any two numbers will always compare as equal. To
|
| 111 |
+
prevent this we treat numbers as a separate case.
|
| 112 |
+
"""
|
| 113 |
+
numeric_types = (int, float, np.number)
|
| 114 |
+
a_is_num = isinstance(a, numeric_types)
|
| 115 |
+
b_is_num = isinstance(b, numeric_types)
|
| 116 |
+
|
| 117 |
+
# Compare numeric types using regular equality
|
| 118 |
+
if a_is_num or b_is_num:
|
| 119 |
+
if not (a_is_num and b_is_num):
|
| 120 |
+
return False
|
| 121 |
+
|
| 122 |
+
return a == b
|
| 123 |
+
|
| 124 |
+
# Compare sequences element-wise
|
| 125 |
+
a_is_seq = isinstance(a, (tuple, list))
|
| 126 |
+
b_is_seq = isinstance(b, (tuple, list))
|
| 127 |
+
|
| 128 |
+
if a_is_seq or b_is_seq:
|
| 129 |
+
if not (a_is_seq and b_is_seq) or type(a) != type(b):
|
| 130 |
+
return False
|
| 131 |
+
|
| 132 |
+
return list(map(theq, a)) == list(map(theq, b))
|
| 133 |
+
|
| 134 |
+
# Otherwise, assume debugprint() can handle it
|
| 135 |
+
astr = aesara.printing.debugprint(a, file='str')
|
| 136 |
+
bstr = aesara.printing.debugprint(b, file='str')
|
| 137 |
+
|
| 138 |
+
# Check for bug mentioned above
|
| 139 |
+
for argname, argval, argstr in [('a', a, astr), ('b', b, bstr)]:
|
| 140 |
+
if argstr == '':
|
| 141 |
+
raise TypeError(
|
| 142 |
+
'aesara.printing.debugprint(%s) returned empty string '
|
| 143 |
+
'(%s is instance of %r)'
|
| 144 |
+
% (argname, argname, type(argval))
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
return astr == bstr
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def test_example_symbols():
|
| 151 |
+
"""
|
| 152 |
+
Check that the example symbols in this module print to their Aesara
|
| 153 |
+
equivalents, as many of the other tests depend on this.
|
| 154 |
+
"""
|
| 155 |
+
assert theq(xt, aesara_code_(x))
|
| 156 |
+
assert theq(yt, aesara_code_(y))
|
| 157 |
+
assert theq(zt, aesara_code_(z))
|
| 158 |
+
assert theq(Xt, aesara_code_(X))
|
| 159 |
+
assert theq(Yt, aesara_code_(Y))
|
| 160 |
+
assert theq(Zt, aesara_code_(Z))
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def test_Symbol():
|
| 164 |
+
""" Test printing a Symbol to a aesara variable. """
|
| 165 |
+
xx = aesara_code_(x)
|
| 166 |
+
assert isinstance(xx, Variable)
|
| 167 |
+
assert xx.broadcastable == ()
|
| 168 |
+
assert xx.name == x.name
|
| 169 |
+
|
| 170 |
+
xx2 = aesara_code_(x, broadcastables={x: (False,)})
|
| 171 |
+
assert xx2.broadcastable == (False,)
|
| 172 |
+
assert xx2.name == x.name
|
| 173 |
+
|
| 174 |
+
def test_MatrixSymbol():
|
| 175 |
+
""" Test printing a MatrixSymbol to a aesara variable. """
|
| 176 |
+
XX = aesara_code_(X)
|
| 177 |
+
assert isinstance(XX, TensorVariable)
|
| 178 |
+
assert XX.broadcastable == (False, False)
|
| 179 |
+
|
| 180 |
+
@SKIP # TODO - this is currently not checked but should be implemented
|
| 181 |
+
def test_MatrixSymbol_wrong_dims():
|
| 182 |
+
""" Test MatrixSymbol with invalid broadcastable. """
|
| 183 |
+
bcs = [(), (False,), (True,), (True, False), (False, True,), (True, True)]
|
| 184 |
+
for bc in bcs:
|
| 185 |
+
with raises(ValueError):
|
| 186 |
+
aesara_code_(X, broadcastables={X: bc})
|
| 187 |
+
|
| 188 |
+
def test_AppliedUndef():
|
| 189 |
+
""" Test printing AppliedUndef instance, which works similarly to Symbol. """
|
| 190 |
+
ftt = aesara_code_(f_t)
|
| 191 |
+
assert isinstance(ftt, TensorVariable)
|
| 192 |
+
assert ftt.broadcastable == ()
|
| 193 |
+
assert ftt.name == 'f_t'
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def test_add():
|
| 197 |
+
expr = x + y
|
| 198 |
+
comp = aesara_code_(expr)
|
| 199 |
+
assert comp.owner.op == aesara.tensor.add
|
| 200 |
+
|
| 201 |
+
def test_trig():
|
| 202 |
+
assert theq(aesara_code_(sy.sin(x)), aet.sin(xt))
|
| 203 |
+
assert theq(aesara_code_(sy.tan(x)), aet.tan(xt))
|
| 204 |
+
|
| 205 |
+
def test_many():
|
| 206 |
+
""" Test printing a complex expression with multiple symbols. """
|
| 207 |
+
expr = sy.exp(x**2 + sy.cos(y)) * sy.log(2*z)
|
| 208 |
+
comp = aesara_code_(expr)
|
| 209 |
+
expected = aet.exp(xt**2 + aet.cos(yt)) * aet.log(2*zt)
|
| 210 |
+
assert theq(comp, expected)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def test_dtype():
|
| 214 |
+
""" Test specifying specific data types through the dtype argument. """
|
| 215 |
+
for dtype in ['float32', 'float64', 'int8', 'int16', 'int32', 'int64']:
|
| 216 |
+
assert aesara_code_(x, dtypes={x: dtype}).type.dtype == dtype
|
| 217 |
+
|
| 218 |
+
# "floatX" type
|
| 219 |
+
assert aesara_code_(x, dtypes={x: 'floatX'}).type.dtype in ('float32', 'float64')
|
| 220 |
+
|
| 221 |
+
# Type promotion
|
| 222 |
+
assert aesara_code_(x + 1, dtypes={x: 'float32'}).type.dtype == 'float32'
|
| 223 |
+
assert aesara_code_(x + y, dtypes={x: 'float64', y: 'float32'}).type.dtype == 'float64'
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def test_broadcastables():
|
| 227 |
+
""" Test the "broadcastables" argument when printing symbol-like objects. """
|
| 228 |
+
|
| 229 |
+
# No restrictions on shape
|
| 230 |
+
for s in [x, f_t]:
|
| 231 |
+
for bc in [(), (False,), (True,), (False, False), (True, False)]:
|
| 232 |
+
assert aesara_code_(s, broadcastables={s: bc}).broadcastable == bc
|
| 233 |
+
|
| 234 |
+
# TODO - matrix broadcasting?
|
| 235 |
+
|
| 236 |
+
def test_broadcasting():
|
| 237 |
+
""" Test "broadcastable" attribute after applying element-wise binary op. """
|
| 238 |
+
|
| 239 |
+
expr = x + y
|
| 240 |
+
|
| 241 |
+
cases = [
|
| 242 |
+
[(), (), ()],
|
| 243 |
+
[(False,), (False,), (False,)],
|
| 244 |
+
[(True,), (False,), (False,)],
|
| 245 |
+
[(False, True), (False, False), (False, False)],
|
| 246 |
+
[(True, False), (False, False), (False, False)],
|
| 247 |
+
]
|
| 248 |
+
|
| 249 |
+
for bc1, bc2, bc3 in cases:
|
| 250 |
+
comp = aesara_code_(expr, broadcastables={x: bc1, y: bc2})
|
| 251 |
+
assert comp.broadcastable == bc3
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def test_MatMul():
|
| 255 |
+
expr = X*Y*Z
|
| 256 |
+
expr_t = aesara_code_(expr)
|
| 257 |
+
assert isinstance(expr_t.owner.op, Dot)
|
| 258 |
+
assert theq(expr_t, Xt.dot(Yt).dot(Zt))
|
| 259 |
+
|
| 260 |
+
def test_Transpose():
|
| 261 |
+
assert isinstance(aesara_code_(X.T).owner.op, DimShuffle)
|
| 262 |
+
|
| 263 |
+
def test_MatAdd():
|
| 264 |
+
expr = X+Y+Z
|
| 265 |
+
assert isinstance(aesara_code_(expr).owner.op, Elemwise)
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def test_Rationals():
|
| 269 |
+
assert theq(aesara_code_(sy.Integer(2) / 3), true_divide(2, 3))
|
| 270 |
+
assert theq(aesara_code_(S.Half), true_divide(1, 2))
|
| 271 |
+
|
| 272 |
+
def test_Integers():
|
| 273 |
+
assert aesara_code_(sy.Integer(3)) == 3
|
| 274 |
+
|
| 275 |
+
def test_factorial():
|
| 276 |
+
n = sy.Symbol('n')
|
| 277 |
+
assert aesara_code_(sy.factorial(n))
|
| 278 |
+
|
| 279 |
+
def test_Derivative():
|
| 280 |
+
with ignore_warnings(UserWarning):
|
| 281 |
+
simp = lambda expr: aesara_simplify(fgraph_of(expr))
|
| 282 |
+
assert theq(simp(aesara_code_(sy.Derivative(sy.sin(x), x, evaluate=False))),
|
| 283 |
+
simp(aesara.grad(aet.sin(xt), xt)))
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
def test_aesara_function_simple():
|
| 287 |
+
""" Test aesara_function() with single output. """
|
| 288 |
+
f = aesara_function_([x, y], [x+y])
|
| 289 |
+
assert f(2, 3) == 5
|
| 290 |
+
|
| 291 |
+
def test_aesara_function_multi():
|
| 292 |
+
""" Test aesara_function() with multiple outputs. """
|
| 293 |
+
f = aesara_function_([x, y], [x+y, x-y])
|
| 294 |
+
o1, o2 = f(2, 3)
|
| 295 |
+
assert o1 == 5
|
| 296 |
+
assert o2 == -1
|
| 297 |
+
|
| 298 |
+
def test_aesara_function_numpy():
|
| 299 |
+
""" Test aesara_function() vs Numpy implementation. """
|
| 300 |
+
f = aesara_function_([x, y], [x+y], dim=1,
|
| 301 |
+
dtypes={x: 'float64', y: 'float64'})
|
| 302 |
+
assert np.linalg.norm(f([1, 2], [3, 4]) - np.asarray([4, 6])) < 1e-9
|
| 303 |
+
|
| 304 |
+
f = aesara_function_([x, y], [x+y], dtypes={x: 'float64', y: 'float64'},
|
| 305 |
+
dim=1)
|
| 306 |
+
xx = np.arange(3).astype('float64')
|
| 307 |
+
yy = 2*np.arange(3).astype('float64')
|
| 308 |
+
assert np.linalg.norm(f(xx, yy) - 3*np.arange(3)) < 1e-9
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
def test_aesara_function_matrix():
|
| 312 |
+
m = sy.Matrix([[x, y], [z, x + y + z]])
|
| 313 |
+
expected = np.array([[1.0, 2.0], [3.0, 1.0 + 2.0 + 3.0]])
|
| 314 |
+
f = aesara_function_([x, y, z], [m])
|
| 315 |
+
np.testing.assert_allclose(f(1.0, 2.0, 3.0), expected)
|
| 316 |
+
f = aesara_function_([x, y, z], [m], scalar=True)
|
| 317 |
+
np.testing.assert_allclose(f(1.0, 2.0, 3.0), expected)
|
| 318 |
+
f = aesara_function_([x, y, z], [m, m])
|
| 319 |
+
assert isinstance(f(1.0, 2.0, 3.0), type([]))
|
| 320 |
+
np.testing.assert_allclose(f(1.0, 2.0, 3.0)[0], expected)
|
| 321 |
+
np.testing.assert_allclose(f(1.0, 2.0, 3.0)[1], expected)
|
| 322 |
+
|
| 323 |
+
def test_dim_handling():
|
| 324 |
+
assert dim_handling([x], dim=2) == {x: (False, False)}
|
| 325 |
+
assert dim_handling([x, y], dims={x: 1, y: 2}) == {x: (False, True),
|
| 326 |
+
y: (False, False)}
|
| 327 |
+
assert dim_handling([x], broadcastables={x: (False,)}) == {x: (False,)}
|
| 328 |
+
|
| 329 |
+
def test_aesara_function_kwargs():
|
| 330 |
+
"""
|
| 331 |
+
Test passing additional kwargs from aesara_function() to aesara.function().
|
| 332 |
+
"""
|
| 333 |
+
import numpy as np
|
| 334 |
+
f = aesara_function_([x, y, z], [x+y], dim=1, on_unused_input='ignore',
|
| 335 |
+
dtypes={x: 'float64', y: 'float64', z: 'float64'})
|
| 336 |
+
assert np.linalg.norm(f([1, 2], [3, 4], [0, 0]) - np.asarray([4, 6])) < 1e-9
|
| 337 |
+
|
| 338 |
+
f = aesara_function_([x, y, z], [x+y],
|
| 339 |
+
dtypes={x: 'float64', y: 'float64', z: 'float64'},
|
| 340 |
+
dim=1, on_unused_input='ignore')
|
| 341 |
+
xx = np.arange(3).astype('float64')
|
| 342 |
+
yy = 2*np.arange(3).astype('float64')
|
| 343 |
+
zz = 2*np.arange(3).astype('float64')
|
| 344 |
+
assert np.linalg.norm(f(xx, yy, zz) - 3*np.arange(3)) < 1e-9
|
| 345 |
+
|
| 346 |
+
def test_aesara_function_scalar():
|
| 347 |
+
""" Test the "scalar" argument to aesara_function(). """
|
| 348 |
+
from aesara.compile.function.types import Function
|
| 349 |
+
|
| 350 |
+
args = [
|
| 351 |
+
([x, y], [x + y], None, [0]), # Single 0d output
|
| 352 |
+
([X, Y], [X + Y], None, [2]), # Single 2d output
|
| 353 |
+
([x, y], [x + y], {x: 0, y: 1}, [1]), # Single 1d output
|
| 354 |
+
([x, y], [x + y, x - y], None, [0, 0]), # Two 0d outputs
|
| 355 |
+
([x, y, X, Y], [x + y, X + Y], None, [0, 2]), # One 0d output, one 2d
|
| 356 |
+
]
|
| 357 |
+
|
| 358 |
+
# Create and test functions with and without the scalar setting
|
| 359 |
+
for inputs, outputs, in_dims, out_dims in args:
|
| 360 |
+
for scalar in [False, True]:
|
| 361 |
+
|
| 362 |
+
f = aesara_function_(inputs, outputs, dims=in_dims, scalar=scalar)
|
| 363 |
+
|
| 364 |
+
# Check the aesara_function attribute is set whether wrapped or not
|
| 365 |
+
assert isinstance(f.aesara_function, Function)
|
| 366 |
+
|
| 367 |
+
# Feed in inputs of the appropriate size and get outputs
|
| 368 |
+
in_values = [
|
| 369 |
+
np.ones([1 if bc else 5 for bc in i.type.broadcastable])
|
| 370 |
+
for i in f.aesara_function.input_storage
|
| 371 |
+
]
|
| 372 |
+
out_values = f(*in_values)
|
| 373 |
+
if not isinstance(out_values, list):
|
| 374 |
+
out_values = [out_values]
|
| 375 |
+
|
| 376 |
+
# Check output types and shapes
|
| 377 |
+
assert len(out_dims) == len(out_values)
|
| 378 |
+
for d, value in zip(out_dims, out_values):
|
| 379 |
+
|
| 380 |
+
if scalar and d == 0:
|
| 381 |
+
# Should have been converted to a scalar value
|
| 382 |
+
assert isinstance(value, np.number)
|
| 383 |
+
|
| 384 |
+
else:
|
| 385 |
+
# Otherwise should be an array
|
| 386 |
+
assert isinstance(value, np.ndarray)
|
| 387 |
+
assert value.ndim == d
|
| 388 |
+
|
| 389 |
+
def test_aesara_function_bad_kwarg():
|
| 390 |
+
"""
|
| 391 |
+
Passing an unknown keyword argument to aesara_function() should raise an
|
| 392 |
+
exception.
|
| 393 |
+
"""
|
| 394 |
+
raises(Exception, lambda : aesara_function_([x], [x+1], foobar=3))
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
def test_slice():
|
| 398 |
+
assert aesara_code_(slice(1, 2, 3)) == slice(1, 2, 3)
|
| 399 |
+
|
| 400 |
+
def theq_slice(s1, s2):
|
| 401 |
+
for attr in ['start', 'stop', 'step']:
|
| 402 |
+
a1 = getattr(s1, attr)
|
| 403 |
+
a2 = getattr(s2, attr)
|
| 404 |
+
if a1 is None or a2 is None:
|
| 405 |
+
if not (a1 is None or a2 is None):
|
| 406 |
+
return False
|
| 407 |
+
elif not theq(a1, a2):
|
| 408 |
+
return False
|
| 409 |
+
return True
|
| 410 |
+
|
| 411 |
+
dtypes = {x: 'int32', y: 'int32'}
|
| 412 |
+
assert theq_slice(aesara_code_(slice(x, y), dtypes=dtypes), slice(xt, yt))
|
| 413 |
+
assert theq_slice(aesara_code_(slice(1, x, 3), dtypes=dtypes), slice(1, xt, 3))
|
| 414 |
+
|
| 415 |
+
def test_MatrixSlice():
|
| 416 |
+
cache = {}
|
| 417 |
+
|
| 418 |
+
n = sy.Symbol('n', integer=True)
|
| 419 |
+
X = sy.MatrixSymbol('X', n, n)
|
| 420 |
+
|
| 421 |
+
Y = X[1:2:3, 4:5:6]
|
| 422 |
+
Yt = aesara_code_(Y, cache=cache)
|
| 423 |
+
|
| 424 |
+
s = ScalarType('int64')
|
| 425 |
+
assert tuple(Yt.owner.op.idx_list) == (slice(s, s, s), slice(s, s, s))
|
| 426 |
+
assert Yt.owner.inputs[0] == aesara_code_(X, cache=cache)
|
| 427 |
+
# == doesn't work in Aesara like it does in SymPy. You have to use
|
| 428 |
+
# equals.
|
| 429 |
+
assert all(Yt.owner.inputs[i].data == i for i in range(1, 7))
|
| 430 |
+
|
| 431 |
+
k = sy.Symbol('k')
|
| 432 |
+
aesara_code_(k, dtypes={k: 'int32'})
|
| 433 |
+
start, stop, step = 4, k, 2
|
| 434 |
+
Y = X[start:stop:step]
|
| 435 |
+
Yt = aesara_code_(Y, dtypes={n: 'int32', k: 'int32'})
|
| 436 |
+
# assert Yt.owner.op.idx_list[0].stop == kt
|
| 437 |
+
|
| 438 |
+
def test_BlockMatrix():
|
| 439 |
+
n = sy.Symbol('n', integer=True)
|
| 440 |
+
A, B, C, D = [sy.MatrixSymbol(name, n, n) for name in 'ABCD']
|
| 441 |
+
At, Bt, Ct, Dt = map(aesara_code_, (A, B, C, D))
|
| 442 |
+
Block = sy.BlockMatrix([[A, B], [C, D]])
|
| 443 |
+
Blockt = aesara_code_(Block)
|
| 444 |
+
solutions = [aet.join(0, aet.join(1, At, Bt), aet.join(1, Ct, Dt)),
|
| 445 |
+
aet.join(1, aet.join(0, At, Ct), aet.join(0, Bt, Dt))]
|
| 446 |
+
assert any(theq(Blockt, solution) for solution in solutions)
|
| 447 |
+
|
| 448 |
+
@SKIP
|
| 449 |
+
def test_BlockMatrix_Inverse_execution():
|
| 450 |
+
k, n = 2, 4
|
| 451 |
+
dtype = 'float32'
|
| 452 |
+
A = sy.MatrixSymbol('A', n, k)
|
| 453 |
+
B = sy.MatrixSymbol('B', n, n)
|
| 454 |
+
inputs = A, B
|
| 455 |
+
output = B.I*A
|
| 456 |
+
|
| 457 |
+
cutsizes = {A: [(n//2, n//2), (k//2, k//2)],
|
| 458 |
+
B: [(n//2, n//2), (n//2, n//2)]}
|
| 459 |
+
cutinputs = [sy.blockcut(i, *cutsizes[i]) for i in inputs]
|
| 460 |
+
cutoutput = output.subs(dict(zip(inputs, cutinputs)))
|
| 461 |
+
|
| 462 |
+
dtypes = dict(zip(inputs, [dtype]*len(inputs)))
|
| 463 |
+
f = aesara_function_(inputs, [output], dtypes=dtypes, cache={})
|
| 464 |
+
fblocked = aesara_function_(inputs, [sy.block_collapse(cutoutput)],
|
| 465 |
+
dtypes=dtypes, cache={})
|
| 466 |
+
|
| 467 |
+
ninputs = [np.random.rand(*x.shape).astype(dtype) for x in inputs]
|
| 468 |
+
ninputs = [np.arange(n*k).reshape(A.shape).astype(dtype),
|
| 469 |
+
np.eye(n).astype(dtype)]
|
| 470 |
+
ninputs[1] += np.ones(B.shape)*1e-5
|
| 471 |
+
|
| 472 |
+
assert np.allclose(f(*ninputs), fblocked(*ninputs), rtol=1e-5)
|
| 473 |
+
|
| 474 |
+
def test_DenseMatrix():
|
| 475 |
+
from aesara.tensor.basic import Join
|
| 476 |
+
|
| 477 |
+
t = sy.Symbol('theta')
|
| 478 |
+
for MatrixType in [sy.Matrix, sy.ImmutableMatrix]:
|
| 479 |
+
X = MatrixType([[sy.cos(t), -sy.sin(t)], [sy.sin(t), sy.cos(t)]])
|
| 480 |
+
tX = aesara_code_(X)
|
| 481 |
+
assert isinstance(tX, TensorVariable)
|
| 482 |
+
assert isinstance(tX.owner.op, Join)
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
def test_cache_basic():
|
| 486 |
+
""" Test single symbol-like objects are cached when printed by themselves. """
|
| 487 |
+
|
| 488 |
+
# Pairs of objects which should be considered equivalent with respect to caching
|
| 489 |
+
pairs = [
|
| 490 |
+
(x, sy.Symbol('x')),
|
| 491 |
+
(X, sy.MatrixSymbol('X', *X.shape)),
|
| 492 |
+
(f_t, sy.Function('f')(sy.Symbol('t'))),
|
| 493 |
+
]
|
| 494 |
+
|
| 495 |
+
for s1, s2 in pairs:
|
| 496 |
+
cache = {}
|
| 497 |
+
st = aesara_code_(s1, cache=cache)
|
| 498 |
+
|
| 499 |
+
# Test hit with same instance
|
| 500 |
+
assert aesara_code_(s1, cache=cache) is st
|
| 501 |
+
|
| 502 |
+
# Test miss with same instance but new cache
|
| 503 |
+
assert aesara_code_(s1, cache={}) is not st
|
| 504 |
+
|
| 505 |
+
# Test hit with different but equivalent instance
|
| 506 |
+
assert aesara_code_(s2, cache=cache) is st
|
| 507 |
+
|
| 508 |
+
def test_global_cache():
|
| 509 |
+
""" Test use of the global cache. """
|
| 510 |
+
from sympy.printing.aesaracode import global_cache
|
| 511 |
+
|
| 512 |
+
backup = dict(global_cache)
|
| 513 |
+
try:
|
| 514 |
+
# Temporarily empty global cache
|
| 515 |
+
global_cache.clear()
|
| 516 |
+
|
| 517 |
+
for s in [x, X, f_t]:
|
| 518 |
+
st = aesara_code(s)
|
| 519 |
+
assert aesara_code(s) is st
|
| 520 |
+
|
| 521 |
+
finally:
|
| 522 |
+
# Restore global cache
|
| 523 |
+
global_cache.update(backup)
|
| 524 |
+
|
| 525 |
+
def test_cache_types_distinct():
|
| 526 |
+
"""
|
| 527 |
+
Test that symbol-like objects of different types (Symbol, MatrixSymbol,
|
| 528 |
+
AppliedUndef) are distinguished by the cache even if they have the same
|
| 529 |
+
name.
|
| 530 |
+
"""
|
| 531 |
+
symbols = [sy.Symbol('f_t'), sy.MatrixSymbol('f_t', 4, 4), f_t]
|
| 532 |
+
|
| 533 |
+
cache = {} # Single shared cache
|
| 534 |
+
printed = {}
|
| 535 |
+
|
| 536 |
+
for s in symbols:
|
| 537 |
+
st = aesara_code_(s, cache=cache)
|
| 538 |
+
assert st not in printed.values()
|
| 539 |
+
printed[s] = st
|
| 540 |
+
|
| 541 |
+
# Check all printed objects are distinct
|
| 542 |
+
assert len(set(map(id, printed.values()))) == len(symbols)
|
| 543 |
+
|
| 544 |
+
# Check retrieving
|
| 545 |
+
for s, st in printed.items():
|
| 546 |
+
assert aesara_code(s, cache=cache) is st
|
| 547 |
+
|
| 548 |
+
def test_symbols_are_created_once():
|
| 549 |
+
"""
|
| 550 |
+
Test that a symbol is cached and reused when it appears in an expression
|
| 551 |
+
more than once.
|
| 552 |
+
"""
|
| 553 |
+
expr = sy.Add(x, x, evaluate=False)
|
| 554 |
+
comp = aesara_code_(expr)
|
| 555 |
+
|
| 556 |
+
assert theq(comp, xt + xt)
|
| 557 |
+
assert not theq(comp, xt + aesara_code_(x))
|
| 558 |
+
|
| 559 |
+
def test_cache_complex():
|
| 560 |
+
"""
|
| 561 |
+
Test caching on a complicated expression with multiple symbols appearing
|
| 562 |
+
multiple times.
|
| 563 |
+
"""
|
| 564 |
+
expr = x ** 2 + (y - sy.exp(x)) * sy.sin(z - x * y)
|
| 565 |
+
symbol_names = {s.name for s in expr.free_symbols}
|
| 566 |
+
expr_t = aesara_code_(expr)
|
| 567 |
+
|
| 568 |
+
# Iterate through variables in the Aesara computational graph that the
|
| 569 |
+
# printed expression depends on
|
| 570 |
+
seen = set()
|
| 571 |
+
for v in aesara.graph.basic.ancestors([expr_t]):
|
| 572 |
+
# Owner-less, non-constant variables should be our symbols
|
| 573 |
+
if v.owner is None and not isinstance(v, aesara.graph.basic.Constant):
|
| 574 |
+
# Check it corresponds to a symbol and appears only once
|
| 575 |
+
assert v.name in symbol_names
|
| 576 |
+
assert v.name not in seen
|
| 577 |
+
seen.add(v.name)
|
| 578 |
+
|
| 579 |
+
# Check all were present
|
| 580 |
+
assert seen == symbol_names
|
| 581 |
+
|
| 582 |
+
|
| 583 |
+
def test_Piecewise():
|
| 584 |
+
# A piecewise linear
|
| 585 |
+
expr = sy.Piecewise((0, x<0), (x, x<2), (1, True)) # ___/III
|
| 586 |
+
result = aesara_code_(expr)
|
| 587 |
+
assert result.owner.op == aet.switch
|
| 588 |
+
|
| 589 |
+
expected = aet.switch(xt<0, 0, aet.switch(xt<2, xt, 1))
|
| 590 |
+
assert theq(result, expected)
|
| 591 |
+
|
| 592 |
+
expr = sy.Piecewise((x, x < 0))
|
| 593 |
+
result = aesara_code_(expr)
|
| 594 |
+
expected = aet.switch(xt < 0, xt, np.nan)
|
| 595 |
+
assert theq(result, expected)
|
| 596 |
+
|
| 597 |
+
expr = sy.Piecewise((0, sy.And(x>0, x<2)), \
|
| 598 |
+
(x, sy.Or(x>2, x<0)))
|
| 599 |
+
result = aesara_code_(expr)
|
| 600 |
+
expected = aet.switch(aet.and_(xt>0,xt<2), 0, \
|
| 601 |
+
aet.switch(aet.or_(xt>2, xt<0), xt, np.nan))
|
| 602 |
+
assert theq(result, expected)
|
| 603 |
+
|
| 604 |
+
|
| 605 |
+
def test_Relationals():
|
| 606 |
+
assert theq(aesara_code_(sy.Eq(x, y)), aet.eq(xt, yt))
|
| 607 |
+
# assert theq(aesara_code_(sy.Ne(x, y)), aet.neq(xt, yt)) # TODO - implement
|
| 608 |
+
assert theq(aesara_code_(x > y), xt > yt)
|
| 609 |
+
assert theq(aesara_code_(x < y), xt < yt)
|
| 610 |
+
assert theq(aesara_code_(x >= y), xt >= yt)
|
| 611 |
+
assert theq(aesara_code_(x <= y), xt <= yt)
|
| 612 |
+
|
| 613 |
+
|
| 614 |
+
def test_complexfunctions():
|
| 615 |
+
dtypes = {x:'complex128', y:'complex128'}
|
| 616 |
+
xt, yt = aesara_code(x, dtypes=dtypes), aesara_code(y, dtypes=dtypes)
|
| 617 |
+
from sympy.functions.elementary.complexes import conjugate
|
| 618 |
+
from aesara.tensor import as_tensor_variable as atv
|
| 619 |
+
from aesara.tensor import complex as cplx
|
| 620 |
+
assert theq(aesara_code(y*conjugate(x), dtypes=dtypes), yt*(xt.conj()))
|
| 621 |
+
assert theq(aesara_code((1+2j)*x), xt*(atv(1.0)+atv(2.0)*cplx(0,1)))
|
| 622 |
+
|
| 623 |
+
|
| 624 |
+
def test_constantfunctions():
|
| 625 |
+
tf = aesara_function([],[1+1j])
|
| 626 |
+
assert(tf()==1+1j)
|