deep-atomic 0.2.0__tar.gz → 0.2.2__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.
Files changed (27) hide show
  1. deep_atomic-0.2.2/.pre-commit-config.yaml +7 -0
  2. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/PKG-INFO +33 -20
  3. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/README.md +30 -18
  4. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/pyproject.toml +9 -3
  5. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/src/deep_atomic/__init__.py +2 -2
  6. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/src/deep_atomic/graph.py +162 -155
  7. deep_atomic-0.2.2/src/deep_atomic/nn.py +381 -0
  8. deep_atomic-0.2.2/src/deep_atomic/op.py +277 -0
  9. deep_atomic-0.2.2/src/deep_atomic/optimizer.py +12 -0
  10. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/src/deep_atomic/tensor.py +90 -78
  11. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/src/deep_atomic/utils.py +3 -2
  12. deep_atomic-0.2.2/tests/conftest.py +44 -0
  13. deep_atomic-0.2.2/tests/init_test.py +41 -0
  14. deep_atomic-0.2.2/tests/nn_test.py +583 -0
  15. deep_atomic-0.2.2/tests/op_test.py +396 -0
  16. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/tests/utils.py +10 -12
  17. deep_atomic-0.2.2/uv.lock +797 -0
  18. deep_atomic-0.2.0/src/deep_atomic/op.py +0 -230
  19. deep_atomic-0.2.0/tests/backward_test.py +0 -686
  20. deep_atomic-0.2.0/tests/init_test.py +0 -40
  21. deep_atomic-0.2.0/tests/op_test.py +0 -492
  22. deep_atomic-0.2.0/uv.lock +0 -1249
  23. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/.github/workflows/publish-pypi.yml +0 -0
  24. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/.gitignore +0 -0
  25. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/.vscode/settings.json +0 -0
  26. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/LICENSE +0 -0
  27. {deep_atomic-0.2.0 → deep_atomic-0.2.2}/tests/__init__.py +0 -0
@@ -0,0 +1,7 @@
1
+ repos:
2
+ - repo: https://github.com/astral-sh/ruff-pre-commit
3
+ rev: v0.15.21
4
+ hooks:
5
+ - id: ruff-check
6
+ args: [--fix, --exit-non-zero-on-fix]
7
+ - id: ruff-format
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deep_atomic
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: A simple deep learning framework built upon numpy only
5
5
  Author-email: Elliot Zhang <elliot_zh@proton.me>
6
6
  License: MIT
@@ -8,11 +8,12 @@ License-File: LICENSE
8
8
  Classifier: License :: OSI Approved :: MIT License
9
9
  Classifier: Operating System :: OS Independent
10
10
  Classifier: Programming Language :: Python :: 3
11
- Requires-Python: >=3.8
11
+ Requires-Python: >=3.10
12
12
  Requires-Dist: numpy>=1.24.4
13
13
  Requires-Dist: pytest>=8.3.5
14
14
  Provides-Extra: dev
15
15
  Requires-Dist: black>=23.0; extra == 'dev'
16
+ Requires-Dist: pre-commit>=4.6.0; extra == 'dev'
16
17
  Requires-Dist: pytest-cov>=4.0; extra == 'dev'
17
18
  Requires-Dist: pytest>=7.0; extra == 'dev'
18
19
  Requires-Dist: ruff>=0.1.0; extra == 'dev'
@@ -20,7 +21,7 @@ Description-Content-Type: text/markdown
20
21
 
21
22
  # Deep Atomic
22
23
 
23
- A simple deep learning framework built upon numpy only. Mainly for practice and learning.
24
+ A simple deep learning framework built on NumPy only. Mainly for practice and learning.
24
25
 
25
26
  ## Usage
26
27
 
@@ -52,7 +53,7 @@ a = da.Tensor(
52
53
 
53
54
  ### Supported Operations
54
55
 
55
- Most essential deeplearning operations are implemented. For those that also exist in NumPy, we follow NumPy's API conventions.
56
+ Most essential deep-learning operations are implemented. For those that also exist in NumPy, we follow NumPy's API conventions.
56
57
 
57
58
  ```python
58
59
  a, b = da.Tensor(np.random.rand(3, 4)), da.Tensor(np.random.rand(3, 4))
@@ -69,24 +70,28 @@ c = da.log(a)
69
70
  c = da.sin(a)
70
71
  # the same for cos, tan, arcsin, arccos, arctan, sinh, cosh, tanh, arcsinh, arccosh, arctanh
71
72
 
72
- d = a < b # element-wise comparison, create a boolean tensor
73
+ d = a < b # element-wise comparison, creates a boolean tensor
73
74
  e = a <= b
74
75
  c = a > b
75
76
  c = a >= b
76
77
  c = a == b
77
78
  c = a != b
78
- c = da.fmax(a, b) # IMPORTANT: here da.fmax is identical to da.maximum, for simplicity. same for da.fmin / da.minimum
79
+ c = da.fmax(a, b) # IMPORTANT: here da.fmax is identical to da.maximum, for simplicity. Same for da.fmin / da.minimum
79
80
  c = da.maximum(a, b)
80
81
  c = da.fmin(a, b)
81
82
  c = da.minimum(a, b)
82
83
 
83
- c = d & e # element-wise and
84
- c = d | e # element-wise or
85
- c = d ^ e # element-wise xor
86
- c = da.logical_not(d) # element-wise not
87
- c = d.all(axis=-1) # reduction of and operation
88
- c = d.any(axis=-1) # reduction of or operation
89
- c = da.where(d, a, b) # return elements chosen from a or b depending on condition
84
+ c = da.logical_and(d, e) # element-wise and
85
+ c = d & e # equivalence
86
+ c = da.logical_or(d, e) # element-wise or
87
+ c = d | e
88
+ c = da.logical_xor(d, e) # element-wise xor
89
+ c = d ^ e
90
+ c = da.logical_not(d) # element-wise not
91
+ c = ~d
92
+ c = d.all(axis=-1, keepdims=False) # logical AND reduction. axis=None, keepdims=False by default
93
+ c = d.any(axis=-1, keepdims=False) # logical OR reduction. axis=None, keepdims=False by default
94
+ c = da.where(d, a, b) # returns elements chosen from a or b depending on condition
90
95
 
91
96
  c = da.topk(a, 2, axis=-1, largest=True) # same as pytorch. axis=-1, largest=True by default
92
97
 
@@ -94,6 +99,7 @@ c = da.sum(a) # shape: (1,)
94
99
  c = da.sum(a, axis=1) # shape: (3,)
95
100
  c = da.sum(a, axis=1, keepdims=True) # shape: (3, 1)
96
101
  # min, max, argmin, argmax follow the same signature
102
+ # all reductions set axis=None, keepdims=False by default
97
103
 
98
104
  c = da.softmax(a, axis=-1, temperature=0.6) # support temperature. temperature=1 by default
99
105
  c = da.log_softmax(a, axis=-1, temperature=0.6)
@@ -114,17 +120,17 @@ c = a.tile(2, 2) # method‑style alternative
114
120
 
115
121
  ### Autograd
116
122
 
117
- Autograd is supported via computational graph.
118
- _Currently only support scalar source points._
123
+ Autograd is supported via a computational graph.
124
+ _Currently only supports scalar source points._
119
125
 
120
126
  ```python
121
127
  x = Tensor(np.random.rand(3, 4)) # requires_grad == True by default
122
128
  res = ... # some calculation related to x. res is a **scalar** result
123
129
  res.backward()
124
- print(res.grad) # gradient get!
130
+ print(res.grad) # gradient computed!
125
131
  ```
126
132
 
127
- ## Todo
133
+ ## To Do
128
134
 
129
135
  - [ ] more basic operations and their autograd
130
136
  - [x] topk
@@ -132,22 +138,29 @@ print(res.grad) # gradient get!
132
138
  - [x] gather or take_along_axis
133
139
  - [ ] scatter
134
140
  - [ ] convolution and 2d convolution
141
+ - [ ] pooling
142
+ - [ ] softmax attention
135
143
  - [ ] direct masking and indexing via `[]` syntax
136
144
  - [ ] einsum
145
+ - [ ] normalization
137
146
  - [ ] support backward with Vector-Jacobian Product like pytorch
138
- - [ ] basic neural network classes
147
+ - [ ] basic neural network modules
139
148
  - [ ] optimizers and loss functions
149
+ - [ ] dataset pipelines
150
+ - [ ] save and load state dict file
140
151
  - [ ] full training test
141
152
  - [ ] benchmark with pytorch on CPU
142
- - [ ] attention layers and full LLM training
153
+ - [ ] full LLM training
143
154
  - [ ] finer type annotations, comments and documentation
144
155
 
145
156
  ## Development
146
157
 
147
- Recommend manage dependencies using [uv](https://github.com/astral-sh/uv).
158
+ We recommend managing dependencies with [uv](https://github.com/astral-sh/uv).
159
+ We use [pre-commit](https://github.com/pre-commit/pre-commit) to manage hooks that help lint and format our code.
148
160
 
149
161
  ```bash
150
162
  uv sync
163
+ pre-commit install # install pre-commit git hooks for lint and format
151
164
  ```
152
165
 
153
166
  Run tests:
@@ -1,6 +1,6 @@
1
1
  # Deep Atomic
2
2
 
3
- A simple deep learning framework built upon numpy only. Mainly for practice and learning.
3
+ A simple deep learning framework built on NumPy only. Mainly for practice and learning.
4
4
 
5
5
  ## Usage
6
6
 
@@ -32,7 +32,7 @@ a = da.Tensor(
32
32
 
33
33
  ### Supported Operations
34
34
 
35
- Most essential deeplearning operations are implemented. For those that also exist in NumPy, we follow NumPy's API conventions.
35
+ Most essential deep-learning operations are implemented. For those that also exist in NumPy, we follow NumPy's API conventions.
36
36
 
37
37
  ```python
38
38
  a, b = da.Tensor(np.random.rand(3, 4)), da.Tensor(np.random.rand(3, 4))
@@ -49,24 +49,28 @@ c = da.log(a)
49
49
  c = da.sin(a)
50
50
  # the same for cos, tan, arcsin, arccos, arctan, sinh, cosh, tanh, arcsinh, arccosh, arctanh
51
51
 
52
- d = a < b # element-wise comparison, create a boolean tensor
52
+ d = a < b # element-wise comparison, creates a boolean tensor
53
53
  e = a <= b
54
54
  c = a > b
55
55
  c = a >= b
56
56
  c = a == b
57
57
  c = a != b
58
- c = da.fmax(a, b) # IMPORTANT: here da.fmax is identical to da.maximum, for simplicity. same for da.fmin / da.minimum
58
+ c = da.fmax(a, b) # IMPORTANT: here da.fmax is identical to da.maximum, for simplicity. Same for da.fmin / da.minimum
59
59
  c = da.maximum(a, b)
60
60
  c = da.fmin(a, b)
61
61
  c = da.minimum(a, b)
62
62
 
63
- c = d & e # element-wise and
64
- c = d | e # element-wise or
65
- c = d ^ e # element-wise xor
66
- c = da.logical_not(d) # element-wise not
67
- c = d.all(axis=-1) # reduction of and operation
68
- c = d.any(axis=-1) # reduction of or operation
69
- c = da.where(d, a, b) # return elements chosen from a or b depending on condition
63
+ c = da.logical_and(d, e) # element-wise and
64
+ c = d & e # equivalence
65
+ c = da.logical_or(d, e) # element-wise or
66
+ c = d | e
67
+ c = da.logical_xor(d, e) # element-wise xor
68
+ c = d ^ e
69
+ c = da.logical_not(d) # element-wise not
70
+ c = ~d
71
+ c = d.all(axis=-1, keepdims=False) # logical AND reduction. axis=None, keepdims=False by default
72
+ c = d.any(axis=-1, keepdims=False) # logical OR reduction. axis=None, keepdims=False by default
73
+ c = da.where(d, a, b) # returns elements chosen from a or b depending on condition
70
74
 
71
75
  c = da.topk(a, 2, axis=-1, largest=True) # same as pytorch. axis=-1, largest=True by default
72
76
 
@@ -74,6 +78,7 @@ c = da.sum(a) # shape: (1,)
74
78
  c = da.sum(a, axis=1) # shape: (3,)
75
79
  c = da.sum(a, axis=1, keepdims=True) # shape: (3, 1)
76
80
  # min, max, argmin, argmax follow the same signature
81
+ # all reductions set axis=None, keepdims=False by default
77
82
 
78
83
  c = da.softmax(a, axis=-1, temperature=0.6) # support temperature. temperature=1 by default
79
84
  c = da.log_softmax(a, axis=-1, temperature=0.6)
@@ -94,17 +99,17 @@ c = a.tile(2, 2) # method‑style alternative
94
99
 
95
100
  ### Autograd
96
101
 
97
- Autograd is supported via computational graph.
98
- _Currently only support scalar source points._
102
+ Autograd is supported via a computational graph.
103
+ _Currently only supports scalar source points._
99
104
 
100
105
  ```python
101
106
  x = Tensor(np.random.rand(3, 4)) # requires_grad == True by default
102
107
  res = ... # some calculation related to x. res is a **scalar** result
103
108
  res.backward()
104
- print(res.grad) # gradient get!
109
+ print(res.grad) # gradient computed!
105
110
  ```
106
111
 
107
- ## Todo
112
+ ## To Do
108
113
 
109
114
  - [ ] more basic operations and their autograd
110
115
  - [x] topk
@@ -112,22 +117,29 @@ print(res.grad) # gradient get!
112
117
  - [x] gather or take_along_axis
113
118
  - [ ] scatter
114
119
  - [ ] convolution and 2d convolution
120
+ - [ ] pooling
121
+ - [ ] softmax attention
115
122
  - [ ] direct masking and indexing via `[]` syntax
116
123
  - [ ] einsum
124
+ - [ ] normalization
117
125
  - [ ] support backward with Vector-Jacobian Product like pytorch
118
- - [ ] basic neural network classes
126
+ - [ ] basic neural network modules
119
127
  - [ ] optimizers and loss functions
128
+ - [ ] dataset pipelines
129
+ - [ ] save and load state dict file
120
130
  - [ ] full training test
121
131
  - [ ] benchmark with pytorch on CPU
122
- - [ ] attention layers and full LLM training
132
+ - [ ] full LLM training
123
133
  - [ ] finer type annotations, comments and documentation
124
134
 
125
135
  ## Development
126
136
 
127
- Recommend manage dependencies using [uv](https://github.com/astral-sh/uv).
137
+ We recommend managing dependencies with [uv](https://github.com/astral-sh/uv).
138
+ We use [pre-commit](https://github.com/pre-commit/pre-commit) to manage hooks that help lint and format our code.
128
139
 
129
140
  ```bash
130
141
  uv sync
142
+ pre-commit install # install pre-commit git hooks for lint and format
131
143
  ```
132
144
 
133
145
  Run tests:
@@ -4,10 +4,10 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "deep_atomic"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "A simple deep learning framework built upon numpy only"
9
9
  readme = "README.md"
10
- requires-python = ">=3.8"
10
+ requires-python = ">=3.10"
11
11
  license = { text = "MIT" }
12
12
  authors = [
13
13
  { name = "Elliot Zhang", email = "elliot_zh@proton.me" }
@@ -28,6 +28,7 @@ dev = [
28
28
  "pytest-cov>=4.0",
29
29
  "black>=23.0",
30
30
  "ruff>=0.1.0",
31
+ "pre-commit>=4.6.0"
31
32
  ]
32
33
 
33
34
  [tool.black]
@@ -36,9 +37,14 @@ target-version = ['py38']
36
37
 
37
38
  [tool.ruff]
38
39
  line-length = 88
39
- lint.select = ["E", "F", "W", "I"]
40
+ lint.select = ["I"] # currently only use isort
40
41
  lint.fixable = ["I"]
41
42
 
43
+ [tool.ruff.lint.isort]
44
+ known-third-party = ["numpy"]
45
+ known-first-party = ["deep-atomic"]
46
+ force-sort-within-sections = true
47
+
42
48
  [tool.pytest.ini_options]
43
49
  testpaths = ["tests"]
44
50
  python_files = "*_test.py"
@@ -1,7 +1,7 @@
1
1
  """deep-atomic - A simple deep learning framework built upon numpy only"""
2
2
 
3
- __version__ = "0.2.0"
3
+ __version__ = "0.2.2"
4
4
  __author__ = "elliot_zh@proton.me"
5
5
 
6
- from .tensor import *
7
6
  from .op import *
7
+ from .tensor import *