DepthTensor 2.8.0__tar.gz → 3.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {depthtensor-2.8.0 → depthtensor-3.0.0}/LICENSE +1 -1
- depthtensor-3.0.0/MANIFEST.in +1 -0
- depthtensor-3.0.0/PKG-INFO +119 -0
- depthtensor-3.0.0/README.md +100 -0
- depthtensor-3.0.0/csrc/bindings/bind_nn.cpp +29 -0
- depthtensor-3.0.0/csrc/bindings/main.cpp +11 -0
- depthtensor-3.0.0/csrc/cpu/nn/activations.cpp +19 -0
- depthtensor-3.0.0/csrc/include/nn/activations.h +9 -0
- depthtensor-3.0.0/depthtensor.egg-info/PKG-INFO +119 -0
- depthtensor-3.0.0/depthtensor.egg-info/SOURCES.txt +42 -0
- {depthtensor-2.8.0/src → depthtensor-3.0.0}/depthtensor.egg-info/requires.txt +1 -1
- depthtensor-3.0.0/depthtensor.egg-info/top_level.txt +1 -0
- {depthtensor-2.8.0 → depthtensor-3.0.0}/pyproject.toml +10 -10
- depthtensor-3.0.0/setup.py +37 -0
- depthtensor-3.0.0/src/DepthTensor/__init__.py +155 -0
- depthtensor-3.0.0/src/DepthTensor/_core/__init__.py +0 -0
- depthtensor-3.0.0/src/DepthTensor/_core/autograd.py +123 -0
- depthtensor-3.0.0/src/DepthTensor/_core/exceptions.py +15 -0
- depthtensor-3.0.0/src/DepthTensor/_core/indexing.py +180 -0
- depthtensor-3.0.0/src/DepthTensor/_core/nn/__init__.py +0 -0
- depthtensor-3.0.0/src/DepthTensor/_core/nn/_backend/__init__.py +1 -0
- depthtensor-3.0.0/src/DepthTensor/_core/nn/_backend/activation_functions.py +204 -0
- depthtensor-3.0.0/src/DepthTensor/_core/nn/functional/__init__.py +1 -0
- depthtensor-3.0.0/src/DepthTensor/_core/nn/functional/activation_functions.py +20 -0
- depthtensor-3.0.0/src/DepthTensor/_core/ops/__init__.py +0 -0
- depthtensor-3.0.0/src/DepthTensor/_core/ops/comparison.py +616 -0
- depthtensor-3.0.0/src/DepthTensor/_core/ops/creation.py +252 -0
- depthtensor-3.0.0/src/DepthTensor/_core/ops/elementwise.py +1758 -0
- depthtensor-3.0.0/src/DepthTensor/_core/ops/function.py +32 -0
- depthtensor-3.0.0/src/DepthTensor/_core/ops/reduction.py +587 -0
- depthtensor-3.0.0/src/DepthTensor/_core/output.py +180 -0
- depthtensor-3.0.0/src/DepthTensor/_core/random/__init__.py +0 -0
- depthtensor-3.0.0/src/DepthTensor/_core/random/generator.py +322 -0
- depthtensor-3.0.0/src/DepthTensor/_core/storage.py +132 -0
- depthtensor-3.0.0/src/DepthTensor/_core/utils.py +402 -0
- depthtensor-3.0.0/src/DepthTensor/_ext/__init__.pyi +7 -0
- depthtensor-3.0.0/src/DepthTensor/_ext/nn.pyi +41 -0
- depthtensor-3.0.0/src/DepthTensor/enum/__init__.py +5 -0
- depthtensor-3.0.0/src/DepthTensor/enum/initialize_grad.py +6 -0
- depthtensor-3.0.0/src/DepthTensor/tensor.py +1928 -0
- {depthtensor-2.8.0 → depthtensor-3.0.0}/src/DepthTensor/typing.py +2 -10
- depthtensor-3.0.0/tests/test_env.py +2 -0
- depthtensor-2.8.0/PKG-INFO +0 -149
- depthtensor-2.8.0/README.md +0 -108
- depthtensor-2.8.0/src/DepthTensor/__init__.py +0 -9
- depthtensor-2.8.0/src/DepthTensor/_core/__init__.py +0 -4
- depthtensor-2.8.0/src/DepthTensor/_core/exceptions.py +0 -16
- depthtensor-2.8.0/src/DepthTensor/_core/ops/__init__.py +0 -5
- depthtensor-2.8.0/src/DepthTensor/_core/ops/comparison.py +0 -516
- depthtensor-2.8.0/src/DepthTensor/_core/ops/creation.py +0 -218
- depthtensor-2.8.0/src/DepthTensor/_core/ops/elementwise.py +0 -1470
- depthtensor-2.8.0/src/DepthTensor/_core/ops/function.py +0 -15
- depthtensor-2.8.0/src/DepthTensor/_core/ops/reduction.py +0 -297
- depthtensor-2.8.0/src/DepthTensor/_core/random/__init__.py +0 -1
- depthtensor-2.8.0/src/DepthTensor/_core/random/generator.py +0 -236
- depthtensor-2.8.0/src/DepthTensor/_core/utils.py +0 -284
- depthtensor-2.8.0/src/DepthTensor/autodiff.py +0 -109
- depthtensor-2.8.0/src/DepthTensor/tensor.py +0 -1301
- depthtensor-2.8.0/src/depthtensor.egg-info/PKG-INFO +0 -149
- depthtensor-2.8.0/src/depthtensor.egg-info/SOURCES.txt +0 -27
- depthtensor-2.8.0/src/depthtensor.egg-info/top_level.txt +0 -1
- depthtensor-2.8.0/tests/test_autodiff.py +0 -265
- depthtensor-2.8.0/tests/test_ops_forward.py +0 -82
- depthtensor-2.8.0/tests/test_tensor_errors.py +0 -47
- depthtensor-2.8.0/tests/test_tensor_init.py +0 -59
- {depthtensor-2.8.0/src → depthtensor-3.0.0}/depthtensor.egg-info/dependency_links.txt +0 -0
- {depthtensor-2.8.0 → depthtensor-3.0.0}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
recursive-include csrc *.cpp *.h
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: depthtensor
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: Tensor math and autograd on CPU and CUDA
|
|
5
|
+
Author-email: Hong Ha Le <lehahong1310@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/l-h-ha/DepthTensor
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/l-h-ha/DepthTensor/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy
|
|
16
|
+
Provides-Extra: cuda
|
|
17
|
+
Requires-Dist: cupy; extra == "cuda"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# DepthTensor
|
|
21
|
+
|
|
22
|
+
DepthTensor provides broadcasted tensor math, reductions, matrix multiplication, and reverse-mode autodiff. It uses NumPy on CPU and CuPy on CUDA. For neural networks, see [DepthML](https://github.com/l-h-ha/DepthML).
|
|
23
|
+
|
|
24
|
+
DepthTensor supports real-valued tensors. Autograd requires a floating-point dtype.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
Use Python 3.10 or later. Pip installs NumPy and builds the C++ extension from source. Install a C++ compiler and Python development headers on Linux, or MSVC and the Windows SDK on Windows.
|
|
29
|
+
|
|
30
|
+
### CPU
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
python -m pip install depthtensor
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### CPU + CUDA
|
|
37
|
+
|
|
38
|
+
On Linux or Windows, use a supported NVIDIA GPU and a compatible driver. Run `nvidia-smi` to check the CUDA version your driver supports. Choose one install command. [NVIDIA driver check](https://docs.nvidia.com/deploy/nvidia-smi/index.html#cuda-umd-version)
|
|
39
|
+
|
|
40
|
+
| CUDA | Install |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| 12.x | `python -m pip install depthtensor "cupy-cuda12x[ctk]"` |
|
|
43
|
+
| 13.x | `python -m pip install depthtensor "cupy-cuda13x[ctk]"` |
|
|
44
|
+
|
|
45
|
+
`[ctk]` installs CUDA libraries through pip. Remove `[ctk]` to use an installed CUDA Toolkit. Set `device = "cuda"` in the example. [CuPy installation guide](https://docs.cupy.dev/en/stable/install.html#installing-cupy-from-pypi)
|
|
46
|
+
|
|
47
|
+
`python -m pip install "depthtensor[cuda]"` uses CuPy's source package and requires an installed CUDA Toolkit. Use one CuPy package per environment. [CuPy source builds](https://docs.cupy.dev/en/stable/install.html#installing-cupy-from-source)
|
|
48
|
+
|
|
49
|
+
## Build from source
|
|
50
|
+
|
|
51
|
+
Install from the repository root.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
python -m pip install .
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Build a wheel in `dist/` with pip.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python -m pip wheel . --no-deps --wheel-dir dist
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Example
|
|
64
|
+
|
|
65
|
+
Minimize the Rosenbrock function with gradient descent.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import depthtensor as dt
|
|
69
|
+
|
|
70
|
+
device = "cpu"
|
|
71
|
+
x = dt.Tensor([1.2], device=device, requires_grad=True)
|
|
72
|
+
y = dt.Tensor([1.2], device=device, requires_grad=True)
|
|
73
|
+
a = dt.Tensor([1], device=device)
|
|
74
|
+
b = dt.Tensor([100], device=device)
|
|
75
|
+
|
|
76
|
+
lr = 0.001
|
|
77
|
+
for i in range(500):
|
|
78
|
+
loss = (a - x) ** 2 + b * (y - x**2) ** 2
|
|
79
|
+
loss.backward()
|
|
80
|
+
x.data -= lr * x.grad
|
|
81
|
+
y.data -= lr * y.grad
|
|
82
|
+
x.zero_grad()
|
|
83
|
+
y.zero_grad()
|
|
84
|
+
|
|
85
|
+
if i % 10 == 0:
|
|
86
|
+
print(loss.item())
|
|
87
|
+
|
|
88
|
+
print(f"({x.data}, {y.data})")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## CPU benchmarks
|
|
92
|
+
|
|
93
|
+
Intel i5-11400H, Windows 26200, Python 3.11.15.
|
|
94
|
+
DepthTensor 3.0.0, PyTorch 2.12.1+cpu, TensorFlow 2.21.0, NumPy 2.3.5.
|
|
95
|
+
|
|
96
|
+
Rounded median (min–max) in µs/call.
|
|
97
|
+
|
|
98
|
+
| Tasks | Input shapes | DepthTensor | PyTorch | TensorFlow |
|
|
99
|
+
| --- | --- | ---: | ---: | ---: |
|
|
100
|
+
| Vector add | `1024 each` | 26 (21–41) | **4** (4–12) | 36 (24–66) |
|
|
101
|
+
| Broadcast add | `1024×1024 + 1024` | 1747 (1354–2957) | **481** (312–1024) | 793 (535–932) |
|
|
102
|
+
| ReLU | `1024×1024` | 7961 (6033–9598) | **412** (337–620) | 516 (413–1148) |
|
|
103
|
+
| Row sum | `1024×1024` | 588 (427–800) | 274 (189–467) | **214** (187–384) |
|
|
104
|
+
| Matmul | `512×512 each` | 4192 (3350–5444) | 3210 (3079–3755) | **3077** (2760–4022) |
|
|
105
|
+
| Matmul → ReLU → MSE + backward | `256×128 @ 128×128` | 2255 (1858–3681) | **782** (580–911) | 1832 (1531–2672) |
|
|
106
|
+
|
|
107
|
+
DepthTensor ranked third in all six matmul runs.
|
|
108
|
+
|
|
109
|
+
Run from the repo root in a Python 3.11 venv.
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
python -m pip install --index-url https://download.pytorch.org/whl/cpu "torch==2.12.1+cpu"
|
|
113
|
+
python -m pip install . "tensorflow-cpu==2.21.0" "numpy==2.3.5"
|
|
114
|
+
python benchmarks/run.py --runs 6
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
[MIT](LICENSE).
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# DepthTensor
|
|
2
|
+
|
|
3
|
+
DepthTensor provides broadcasted tensor math, reductions, matrix multiplication, and reverse-mode autodiff. It uses NumPy on CPU and CuPy on CUDA. For neural networks, see [DepthML](https://github.com/l-h-ha/DepthML).
|
|
4
|
+
|
|
5
|
+
DepthTensor supports real-valued tensors. Autograd requires a floating-point dtype.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Use Python 3.10 or later. Pip installs NumPy and builds the C++ extension from source. Install a C++ compiler and Python development headers on Linux, or MSVC and the Windows SDK on Windows.
|
|
10
|
+
|
|
11
|
+
### CPU
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
python -m pip install depthtensor
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### CPU + CUDA
|
|
18
|
+
|
|
19
|
+
On Linux or Windows, use a supported NVIDIA GPU and a compatible driver. Run `nvidia-smi` to check the CUDA version your driver supports. Choose one install command. [NVIDIA driver check](https://docs.nvidia.com/deploy/nvidia-smi/index.html#cuda-umd-version)
|
|
20
|
+
|
|
21
|
+
| CUDA | Install |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| 12.x | `python -m pip install depthtensor "cupy-cuda12x[ctk]"` |
|
|
24
|
+
| 13.x | `python -m pip install depthtensor "cupy-cuda13x[ctk]"` |
|
|
25
|
+
|
|
26
|
+
`[ctk]` installs CUDA libraries through pip. Remove `[ctk]` to use an installed CUDA Toolkit. Set `device = "cuda"` in the example. [CuPy installation guide](https://docs.cupy.dev/en/stable/install.html#installing-cupy-from-pypi)
|
|
27
|
+
|
|
28
|
+
`python -m pip install "depthtensor[cuda]"` uses CuPy's source package and requires an installed CUDA Toolkit. Use one CuPy package per environment. [CuPy source builds](https://docs.cupy.dev/en/stable/install.html#installing-cupy-from-source)
|
|
29
|
+
|
|
30
|
+
## Build from source
|
|
31
|
+
|
|
32
|
+
Install from the repository root.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
python -m pip install .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Build a wheel in `dist/` with pip.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python -m pip wheel . --no-deps --wheel-dir dist
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Example
|
|
45
|
+
|
|
46
|
+
Minimize the Rosenbrock function with gradient descent.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import depthtensor as dt
|
|
50
|
+
|
|
51
|
+
device = "cpu"
|
|
52
|
+
x = dt.Tensor([1.2], device=device, requires_grad=True)
|
|
53
|
+
y = dt.Tensor([1.2], device=device, requires_grad=True)
|
|
54
|
+
a = dt.Tensor([1], device=device)
|
|
55
|
+
b = dt.Tensor([100], device=device)
|
|
56
|
+
|
|
57
|
+
lr = 0.001
|
|
58
|
+
for i in range(500):
|
|
59
|
+
loss = (a - x) ** 2 + b * (y - x**2) ** 2
|
|
60
|
+
loss.backward()
|
|
61
|
+
x.data -= lr * x.grad
|
|
62
|
+
y.data -= lr * y.grad
|
|
63
|
+
x.zero_grad()
|
|
64
|
+
y.zero_grad()
|
|
65
|
+
|
|
66
|
+
if i % 10 == 0:
|
|
67
|
+
print(loss.item())
|
|
68
|
+
|
|
69
|
+
print(f"({x.data}, {y.data})")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## CPU benchmarks
|
|
73
|
+
|
|
74
|
+
Intel i5-11400H, Windows 26200, Python 3.11.15.
|
|
75
|
+
DepthTensor 3.0.0, PyTorch 2.12.1+cpu, TensorFlow 2.21.0, NumPy 2.3.5.
|
|
76
|
+
|
|
77
|
+
Rounded median (min–max) in µs/call.
|
|
78
|
+
|
|
79
|
+
| Tasks | Input shapes | DepthTensor | PyTorch | TensorFlow |
|
|
80
|
+
| --- | --- | ---: | ---: | ---: |
|
|
81
|
+
| Vector add | `1024 each` | 26 (21–41) | **4** (4–12) | 36 (24–66) |
|
|
82
|
+
| Broadcast add | `1024×1024 + 1024` | 1747 (1354–2957) | **481** (312–1024) | 793 (535–932) |
|
|
83
|
+
| ReLU | `1024×1024` | 7961 (6033–9598) | **412** (337–620) | 516 (413–1148) |
|
|
84
|
+
| Row sum | `1024×1024` | 588 (427–800) | 274 (189–467) | **214** (187–384) |
|
|
85
|
+
| Matmul | `512×512 each` | 4192 (3350–5444) | 3210 (3079–3755) | **3077** (2760–4022) |
|
|
86
|
+
| Matmul → ReLU → MSE + backward | `256×128 @ 128×128` | 2255 (1858–3681) | **782** (580–911) | 1832 (1531–2672) |
|
|
87
|
+
|
|
88
|
+
DepthTensor ranked third in all six matmul runs.
|
|
89
|
+
|
|
90
|
+
Run from the repo root in a Python 3.11 venv.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
python -m pip install --index-url https://download.pytorch.org/whl/cpu "torch==2.12.1+cpu"
|
|
94
|
+
python -m pip install . "tensorflow-cpu==2.21.0" "numpy==2.3.5"
|
|
95
|
+
python benchmarks/run.py --runs 6
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
[MIT](LICENSE).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#include <pybind11/pybind11.h>
|
|
2
|
+
#include <pybind11/numpy.h>
|
|
3
|
+
|
|
4
|
+
#include "nn/activations.h"
|
|
5
|
+
|
|
6
|
+
namespace py = pybind11;
|
|
7
|
+
using namespace depthtensor::nn;
|
|
8
|
+
|
|
9
|
+
template <typename T>
|
|
10
|
+
void py_relu_forward_cpu(py::array_t<T> tensor) {
|
|
11
|
+
constexpr int contiguous_flags = py::array::c_style | py::array::f_style;
|
|
12
|
+
if (!tensor.writeable() || !(tensor.flags() & contiguous_flags)) {
|
|
13
|
+
throw std::runtime_error("Tensor must be writable and contiguous.");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
py::buffer_info buf = tensor.request();
|
|
17
|
+
T *ptr = static_cast<T *>(buf.ptr);
|
|
18
|
+
|
|
19
|
+
relu_forward_cpu_impl(ptr, buf.size);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void init_nn(py::module_ &m) {
|
|
23
|
+
py::module_ nn_m = m.def_submodule("nn", "Neural network ops.");
|
|
24
|
+
|
|
25
|
+
nn_m.def("relu_forward_cpu", &py_relu_forward_cpu<float>, py::arg("tensor").noconvert(),
|
|
26
|
+
"ReLU for float32");
|
|
27
|
+
nn_m.def("relu_forward_cpu", &py_relu_forward_cpu<double>, py::arg("tensor").noconvert(),
|
|
28
|
+
"ReLU for float64");
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#include "nn/activations.h"
|
|
2
|
+
|
|
3
|
+
namespace depthtensor {
|
|
4
|
+
namespace nn {
|
|
5
|
+
template <typename T>
|
|
6
|
+
void relu_forward_cpu_impl(T *data, size_t size) {
|
|
7
|
+
T zero = static_cast<T>(0);
|
|
8
|
+
for (size_t i = 0; i < size; i++) {
|
|
9
|
+
if (data[i] < zero) {
|
|
10
|
+
data[i] = zero;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
template void relu_forward_cpu_impl<float>(float *data, size_t size);
|
|
16
|
+
template void relu_forward_cpu_impl<double>(double *data, size_t size);
|
|
17
|
+
template void relu_forward_cpu_impl<int>(int *data, size_t size);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: depthtensor
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: Tensor math and autograd on CPU and CUDA
|
|
5
|
+
Author-email: Hong Ha Le <lehahong1310@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/l-h-ha/DepthTensor
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/l-h-ha/DepthTensor/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy
|
|
16
|
+
Provides-Extra: cuda
|
|
17
|
+
Requires-Dist: cupy; extra == "cuda"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# DepthTensor
|
|
21
|
+
|
|
22
|
+
DepthTensor provides broadcasted tensor math, reductions, matrix multiplication, and reverse-mode autodiff. It uses NumPy on CPU and CuPy on CUDA. For neural networks, see [DepthML](https://github.com/l-h-ha/DepthML).
|
|
23
|
+
|
|
24
|
+
DepthTensor supports real-valued tensors. Autograd requires a floating-point dtype.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
Use Python 3.10 or later. Pip installs NumPy and builds the C++ extension from source. Install a C++ compiler and Python development headers on Linux, or MSVC and the Windows SDK on Windows.
|
|
29
|
+
|
|
30
|
+
### CPU
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
python -m pip install depthtensor
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### CPU + CUDA
|
|
37
|
+
|
|
38
|
+
On Linux or Windows, use a supported NVIDIA GPU and a compatible driver. Run `nvidia-smi` to check the CUDA version your driver supports. Choose one install command. [NVIDIA driver check](https://docs.nvidia.com/deploy/nvidia-smi/index.html#cuda-umd-version)
|
|
39
|
+
|
|
40
|
+
| CUDA | Install |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| 12.x | `python -m pip install depthtensor "cupy-cuda12x[ctk]"` |
|
|
43
|
+
| 13.x | `python -m pip install depthtensor "cupy-cuda13x[ctk]"` |
|
|
44
|
+
|
|
45
|
+
`[ctk]` installs CUDA libraries through pip. Remove `[ctk]` to use an installed CUDA Toolkit. Set `device = "cuda"` in the example. [CuPy installation guide](https://docs.cupy.dev/en/stable/install.html#installing-cupy-from-pypi)
|
|
46
|
+
|
|
47
|
+
`python -m pip install "depthtensor[cuda]"` uses CuPy's source package and requires an installed CUDA Toolkit. Use one CuPy package per environment. [CuPy source builds](https://docs.cupy.dev/en/stable/install.html#installing-cupy-from-source)
|
|
48
|
+
|
|
49
|
+
## Build from source
|
|
50
|
+
|
|
51
|
+
Install from the repository root.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
python -m pip install .
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Build a wheel in `dist/` with pip.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python -m pip wheel . --no-deps --wheel-dir dist
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Example
|
|
64
|
+
|
|
65
|
+
Minimize the Rosenbrock function with gradient descent.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import depthtensor as dt
|
|
69
|
+
|
|
70
|
+
device = "cpu"
|
|
71
|
+
x = dt.Tensor([1.2], device=device, requires_grad=True)
|
|
72
|
+
y = dt.Tensor([1.2], device=device, requires_grad=True)
|
|
73
|
+
a = dt.Tensor([1], device=device)
|
|
74
|
+
b = dt.Tensor([100], device=device)
|
|
75
|
+
|
|
76
|
+
lr = 0.001
|
|
77
|
+
for i in range(500):
|
|
78
|
+
loss = (a - x) ** 2 + b * (y - x**2) ** 2
|
|
79
|
+
loss.backward()
|
|
80
|
+
x.data -= lr * x.grad
|
|
81
|
+
y.data -= lr * y.grad
|
|
82
|
+
x.zero_grad()
|
|
83
|
+
y.zero_grad()
|
|
84
|
+
|
|
85
|
+
if i % 10 == 0:
|
|
86
|
+
print(loss.item())
|
|
87
|
+
|
|
88
|
+
print(f"({x.data}, {y.data})")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## CPU benchmarks
|
|
92
|
+
|
|
93
|
+
Intel i5-11400H, Windows 26200, Python 3.11.15.
|
|
94
|
+
DepthTensor 3.0.0, PyTorch 2.12.1+cpu, TensorFlow 2.21.0, NumPy 2.3.5.
|
|
95
|
+
|
|
96
|
+
Rounded median (min–max) in µs/call.
|
|
97
|
+
|
|
98
|
+
| Tasks | Input shapes | DepthTensor | PyTorch | TensorFlow |
|
|
99
|
+
| --- | --- | ---: | ---: | ---: |
|
|
100
|
+
| Vector add | `1024 each` | 26 (21–41) | **4** (4–12) | 36 (24–66) |
|
|
101
|
+
| Broadcast add | `1024×1024 + 1024` | 1747 (1354–2957) | **481** (312–1024) | 793 (535–932) |
|
|
102
|
+
| ReLU | `1024×1024` | 7961 (6033–9598) | **412** (337–620) | 516 (413–1148) |
|
|
103
|
+
| Row sum | `1024×1024` | 588 (427–800) | 274 (189–467) | **214** (187–384) |
|
|
104
|
+
| Matmul | `512×512 each` | 4192 (3350–5444) | 3210 (3079–3755) | **3077** (2760–4022) |
|
|
105
|
+
| Matmul → ReLU → MSE + backward | `256×128 @ 128×128` | 2255 (1858–3681) | **782** (580–911) | 1832 (1531–2672) |
|
|
106
|
+
|
|
107
|
+
DepthTensor ranked third in all six matmul runs.
|
|
108
|
+
|
|
109
|
+
Run from the repo root in a Python 3.11 venv.
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
python -m pip install --index-url https://download.pytorch.org/whl/cpu "torch==2.12.1+cpu"
|
|
113
|
+
python -m pip install . "tensorflow-cpu==2.21.0" "numpy==2.3.5"
|
|
114
|
+
python benchmarks/run.py --runs 6
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
[MIT](LICENSE).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.py
|
|
6
|
+
csrc/bindings/bind_nn.cpp
|
|
7
|
+
csrc/bindings/main.cpp
|
|
8
|
+
csrc/cpu/nn/activations.cpp
|
|
9
|
+
csrc/include/nn/activations.h
|
|
10
|
+
depthtensor.egg-info/PKG-INFO
|
|
11
|
+
depthtensor.egg-info/SOURCES.txt
|
|
12
|
+
depthtensor.egg-info/dependency_links.txt
|
|
13
|
+
depthtensor.egg-info/requires.txt
|
|
14
|
+
depthtensor.egg-info/top_level.txt
|
|
15
|
+
src/DepthTensor/__init__.py
|
|
16
|
+
src/DepthTensor/tensor.py
|
|
17
|
+
src/DepthTensor/typing.py
|
|
18
|
+
src/DepthTensor/_core/__init__.py
|
|
19
|
+
src/DepthTensor/_core/autograd.py
|
|
20
|
+
src/DepthTensor/_core/exceptions.py
|
|
21
|
+
src/DepthTensor/_core/indexing.py
|
|
22
|
+
src/DepthTensor/_core/output.py
|
|
23
|
+
src/DepthTensor/_core/storage.py
|
|
24
|
+
src/DepthTensor/_core/utils.py
|
|
25
|
+
src/DepthTensor/_core/nn/__init__.py
|
|
26
|
+
src/DepthTensor/_core/nn/_backend/__init__.py
|
|
27
|
+
src/DepthTensor/_core/nn/_backend/activation_functions.py
|
|
28
|
+
src/DepthTensor/_core/nn/functional/__init__.py
|
|
29
|
+
src/DepthTensor/_core/nn/functional/activation_functions.py
|
|
30
|
+
src/DepthTensor/_core/ops/__init__.py
|
|
31
|
+
src/DepthTensor/_core/ops/comparison.py
|
|
32
|
+
src/DepthTensor/_core/ops/creation.py
|
|
33
|
+
src/DepthTensor/_core/ops/elementwise.py
|
|
34
|
+
src/DepthTensor/_core/ops/function.py
|
|
35
|
+
src/DepthTensor/_core/ops/reduction.py
|
|
36
|
+
src/DepthTensor/_core/random/__init__.py
|
|
37
|
+
src/DepthTensor/_core/random/generator.py
|
|
38
|
+
src/DepthTensor/_ext/__init__.pyi
|
|
39
|
+
src/DepthTensor/_ext/nn.pyi
|
|
40
|
+
src/DepthTensor/enum/__init__.py
|
|
41
|
+
src/DepthTensor/enum/initialize_grad.py
|
|
42
|
+
tests/test_env.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
depthtensor
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["setuptools>=
|
|
2
|
+
requires = ["setuptools>=77.0.3", "pybind11>=2.10.0"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "depthtensor"
|
|
7
|
-
version = "
|
|
8
|
-
description = "
|
|
7
|
+
version = "3.0.0"
|
|
8
|
+
description = "Tensor math and autograd on CPU and CUDA"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [
|
|
11
|
-
{ name = "
|
|
11
|
+
{ name = "Hong Ha Le", email = "lehahong1310@gmail.com" }
|
|
12
12
|
]
|
|
13
|
-
license =
|
|
13
|
+
license = "MIT"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
14
15
|
classifiers = [
|
|
15
16
|
"Programming Language :: Python :: 3",
|
|
16
17
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
17
|
-
"License :: OSI Approved :: MIT License",
|
|
18
18
|
"Operating System :: OS Independent"
|
|
19
19
|
]
|
|
20
|
-
requires-python = ">=3.
|
|
20
|
+
requires-python = ">=3.10"
|
|
21
21
|
dependencies = [
|
|
22
22
|
"numpy"
|
|
23
23
|
]
|
|
24
24
|
|
|
25
25
|
[project.optional-dependencies]
|
|
26
|
-
|
|
26
|
+
cuda = [
|
|
27
27
|
"cupy"
|
|
28
28
|
]
|
|
29
29
|
|
|
@@ -31,5 +31,5 @@ gpu = [
|
|
|
31
31
|
"Homepage" = "https://github.com/l-h-ha/DepthTensor"
|
|
32
32
|
"Bug Tracker" = "https://github.com/l-h-ha/DepthTensor/issues"
|
|
33
33
|
|
|
34
|
-
[tool.
|
|
35
|
-
|
|
34
|
+
[tool.ruff.lint]
|
|
35
|
+
select = ["E4", "E7", "E9", "F"]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from setuptools import setup, Extension, find_namespace_packages
|
|
2
|
+
import pybind11
|
|
3
|
+
import glob
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
source_package = "depthtensor" if "depthtensor" in os.listdir("src") else "DepthTensor"
|
|
7
|
+
source_packages = find_namespace_packages(
|
|
8
|
+
where="src",
|
|
9
|
+
include=[source_package, f"{source_package}.*"],
|
|
10
|
+
)
|
|
11
|
+
packages = [package.replace(source_package, "depthtensor", 1) for package in source_packages]
|
|
12
|
+
|
|
13
|
+
bindings_src = glob.glob("csrc/bindings/*.cpp")
|
|
14
|
+
cpu_core_src = glob.glob("csrc/cpu/core/*.cpp")
|
|
15
|
+
cpu_nn_src = glob.glob("csrc/cpu/nn/*.cpp")
|
|
16
|
+
|
|
17
|
+
all_sources = bindings_src + cpu_core_src + cpu_nn_src
|
|
18
|
+
|
|
19
|
+
ext_modules = [
|
|
20
|
+
Extension(
|
|
21
|
+
"depthtensor._ext",
|
|
22
|
+
sources=all_sources,
|
|
23
|
+
include_dirs=[
|
|
24
|
+
pybind11.get_include(),
|
|
25
|
+
os.path.abspath("csrc/include"),
|
|
26
|
+
],
|
|
27
|
+
language="c++",
|
|
28
|
+
extra_compile_args=["-O3", "-Wall", "-shared", "-fPIC"],
|
|
29
|
+
),
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
setup(
|
|
33
|
+
packages=packages,
|
|
34
|
+
package_dir={"depthtensor": f"src/{source_package}"},
|
|
35
|
+
package_data={"depthtensor._ext": ["*.pyi"]},
|
|
36
|
+
ext_modules=ext_modules,
|
|
37
|
+
)
|