nnflow 0.1.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.
@@ -0,0 +1,63 @@
1
+ name: Build and Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published] # Triggers when you create a new GitHub Release
6
+ workflow_dispatch: # Allows you to manually trigger it via GitHub UI if needed
7
+
8
+ jobs:
9
+ # JOB 1: Build wheels and source distribution on Ubuntu Linux
10
+ build_package:
11
+ name: Build wheels and sdist on Ubuntu
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - name: Check out repository
16
+ uses: actions/checkout@v4
17
+
18
+ - name: Set up Python
19
+ uses: actions/setup-python@v5
20
+ with:
21
+ python-version: "3.11"
22
+
23
+ - name: Install build tools
24
+ run: |
25
+ python -m pip install --upgrade pip
26
+ pip install cibuildwheel build
27
+
28
+ - name: Build C++ Binary Wheels
29
+ run: python -m cibuildwheel --output-dir dist
30
+ env:
31
+ # Targets standard 64-bit Linux architectures only
32
+ CIBW_BUILD: "cp*-manylinux_x86_64"
33
+ CIBW_BUILD_FRONTEND: "build"
34
+
35
+ - name: Build Source Distribution (sdist)
36
+ run: python -m build --sdist --outdir dist
37
+
38
+ - name: Upload Artifacts for Safety
39
+ uses: actions/upload-artifact@v4
40
+ with:
41
+ name: pypi-artifacts-${{ github.sha }}
42
+ path: ./dist/*
43
+
44
+ # JOB 2: Safely authenticate and upload to PyPI
45
+ publish:
46
+ name: Publish package to PyPI
47
+ needs: build_package
48
+ runs-on: ubuntu-latest
49
+ environment:
50
+ name: pypi
51
+ url: https://pypi.org
52
+ permissions:
53
+ id-token: write # Required for PyPI Trusted Publisher OIDC authentication
54
+
55
+ steps:
56
+ - name: Download built distributions
57
+ uses: actions/download-artifact@v4
58
+ with:
59
+ name: pypi-artifacts-${{ github.sha }}
60
+ path: dist
61
+
62
+ - name: Publish package distributions to PyPI
63
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,209 @@
1
+ # Created by https://www.toptal.com/developers/gitignore/api/c++,python
2
+ # Edit at https://www.toptal.com/developers/gitignore?templates=c++,python
3
+
4
+ ### C++ ###
5
+ # Prerequisites
6
+ *.d
7
+
8
+ # Compiled Object files
9
+ *.slo
10
+ *.lo
11
+ *.o
12
+ *.obj
13
+
14
+ # Precompiled Headers
15
+ *.gch
16
+ *.pch
17
+
18
+ # Compiled Dynamic libraries
19
+ *.so
20
+ *.dylib
21
+ *.dll
22
+
23
+ # Fortran module files
24
+ *.mod
25
+ *.smod
26
+
27
+ # Compiled Static libraries
28
+ *.lai
29
+ *.la
30
+ *.a
31
+ *.lib
32
+
33
+ # Executables
34
+ *.exe
35
+ *.out
36
+ *.app
37
+
38
+ ### Python ###
39
+ # Byte-compiled / optimized / DLL files
40
+ __pycache__/
41
+ *.py[cod]
42
+ *$py.class
43
+
44
+ # C extensions
45
+
46
+ # Distribution / packaging
47
+ .Python
48
+ build/
49
+ develop-eggs/
50
+ dist/
51
+ downloads/
52
+ eggs/
53
+ .eggs/
54
+ lib/
55
+ lib64/
56
+ parts/
57
+ sdist/
58
+ var/
59
+ wheels/
60
+ share/python-wheels/
61
+ *.egg-info/
62
+ .installed.cfg
63
+ *.egg
64
+ MANIFEST
65
+
66
+ # PyInstaller
67
+ # Usually these files are written by a python script from a template
68
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
69
+ *.manifest
70
+ *.spec
71
+
72
+ # Installer logs
73
+ pip-log.txt
74
+ pip-delete-this-directory.txt
75
+
76
+ # Unit test / coverage reports
77
+ htmlcov/
78
+ .tox/
79
+ .nox/
80
+ .coverage
81
+ .coverage.*
82
+ .cache
83
+ nosetests.xml
84
+ coverage.xml
85
+ *.cover
86
+ *.py,cover
87
+ .hypothesis/
88
+ .pytest_cache/
89
+ cover/
90
+
91
+ # Translations
92
+ *.mo
93
+ *.pot
94
+
95
+ # Django stuff:
96
+ *.log
97
+ local_settings.py
98
+ db.sqlite3
99
+ db.sqlite3-journal
100
+
101
+ # Flask stuff:
102
+ instance/
103
+ .webassets-cache
104
+
105
+ # Scrapy stuff:
106
+ .scrapy
107
+
108
+ # Sphinx documentation
109
+ docs/_build/
110
+
111
+ # PyBuilder
112
+ .pybuilder/
113
+ target/
114
+
115
+ # Jupyter Notebook
116
+ .ipynb_checkpoints
117
+
118
+ # IPython
119
+ profile_default/
120
+ ipython_config.py
121
+
122
+ # pyenv
123
+ # For a library or package, you might want to ignore these files since the code is
124
+ # intended to run in multiple environments; otherwise, check them in:
125
+ # .python-version
126
+
127
+ # pipenv
128
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
129
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
130
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
131
+ # install all needed dependencies.
132
+ #Pipfile.lock
133
+
134
+ # poetry
135
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
136
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
137
+ # commonly ignored for libraries.
138
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
139
+ #poetry.lock
140
+
141
+ # pdm
142
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
143
+ #pdm.lock
144
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
145
+ # in version control.
146
+ # https://pdm.fming.dev/#use-with-ide
147
+ .pdm.toml
148
+
149
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
150
+ __pypackages__/
151
+
152
+ # Celery stuff
153
+ celerybeat-schedule
154
+ celerybeat.pid
155
+
156
+ # SageMath parsed files
157
+ *.sage.py
158
+
159
+ # Environments
160
+ .env
161
+ .venv
162
+ env/
163
+ venv/
164
+ ENV/
165
+ env.bak/
166
+ venv.bak/
167
+
168
+ # Spyder project settings
169
+ .spyderproject
170
+ .spyproject
171
+
172
+ # Rope project settings
173
+ .ropeproject
174
+
175
+ # mkdocs documentation
176
+ /site
177
+
178
+ # mypy
179
+ .mypy_cache/
180
+ .dmypy.json
181
+ dmypy.json
182
+
183
+ # Pyre type checker
184
+ .pyre/
185
+
186
+ # pytype static type analyzer
187
+ .pytype/
188
+
189
+ # Cython debug symbols
190
+ cython_debug/
191
+
192
+ # PyCharm
193
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
194
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
195
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
196
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
197
+ #.idea/
198
+
199
+ ### Python Patch ###
200
+ # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
201
+ poetry.toml
202
+
203
+ # ruff
204
+ .ruff_cache/
205
+
206
+ # LSP config files
207
+ pyrightconfig.json
208
+
209
+ # End of https://www.toptal.com/developers/gitignore/api/c++,python
@@ -0,0 +1,19 @@
1
+ {
2
+ "configurations": [
3
+ {
4
+ "name": "Local Env",
5
+ "includePath": [
6
+ "${workspaceFolder}/**",
7
+ "${workspaceFolder}/include",
8
+ "${workspaceFolder}/.venv/lib/python*/site-packages/pybind11/include",
9
+ "${workspaceFolder}/.venv/include/site/"
10
+ ],
11
+ "defines": [],
12
+ "compilerPath": "/usr/bin/g++",
13
+ "cStandard": "c11",
14
+ "cppStandard": "c++14",
15
+ "intelliSenseMode": "linux-gcc-x64"
16
+ }
17
+ ],
18
+ "version": 4
19
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+
8
+ ]
9
+ }
@@ -0,0 +1,20 @@
1
+ cmake_minimum_required(VERSION 3.15)
2
+ project(nnflow_backend LANGUAGES CXX)
3
+
4
+ # Force standard required for modern pybind11
5
+ set(CMAKE_CXX_STANDARD 14)
6
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
7
+
8
+ # Find pybind11 (resolved automatically by uv and scikit-build-core)
9
+ find_package(pybind11 CONFIG REQUIRED)
10
+
11
+ # Include your header file directory
12
+ include_directories(include layers)
13
+
14
+ # Compile your main binding file and the underlying batchnorm logic together
15
+ pybind11_add_module(_core
16
+ nnflow/main.cpp
17
+ )
18
+
19
+ # Crucial: Install the binary directly into the flat python folder
20
+ install(TARGETS _core DESTINATION nnflow)
nnflow-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.2
2
+ Name: nnflow
3
+ Version: 0.1.0
4
+ Summary: NNFlow
5
+ Requires-Python: >=3.8
6
+ Description-Content-Type: text/markdown
7
+
nnflow-0.1.0/README.md ADDED
File without changes
@@ -0,0 +1,40 @@
1
+ #pragma once
2
+
3
+ #include <map>
4
+ #include <string>
5
+ #include <vector>
6
+
7
+ using namespace std;
8
+
9
+ enum NNF_DataType {
10
+ NNF_UINT8,
11
+ NNF_INT8,
12
+ NNF_UINT16,
13
+ NNF_INT16,
14
+ NNF_FLOAT16,
15
+ NNF_BFLOAT16,
16
+ NNF_FLOAT32
17
+ };
18
+
19
+ class NNF_Tensor {
20
+ void *ptr;
21
+ std::string name;
22
+ std::vector<int> shape;
23
+ NNF_DataType dataType;
24
+ };
25
+
26
+ class NNF_Buffer {
27
+ std::string name;
28
+ std::vector<int> shape;
29
+ NNF_DataType dataType;
30
+ };
31
+
32
+ class NNF_Layer {
33
+ std::string name;
34
+ std::vector<NNF_Buffer*> inputs, outputs;
35
+ };
36
+
37
+ class NNF_Graph{
38
+ std::map<string, std::string> metadata;
39
+ std::vector<NNF_Layer*> layers;
40
+ };
@@ -0,0 +1,23 @@
1
+ #include <cmath>
2
+ #include <nnf_layer.h>
3
+
4
+ class BatchNorm : public NNF_Layer {
5
+ public:
6
+ float eps = 1e-5;
7
+ float momentum = 0.1;
8
+
9
+ void *scale;
10
+ void *bias;
11
+ void *mean;
12
+ void *variance;
13
+
14
+ BatchNorm(
15
+ std::string name,
16
+ float eps,
17
+ float momentum
18
+ ) {
19
+ name = name;
20
+ this->eps = eps;
21
+ this->momentum = momentum;
22
+ }
23
+ };
@@ -0,0 +1 @@
1
+ from ._core import *
@@ -0,0 +1,47 @@
1
+ #include <pybind11/pybind11.h> // Must be included first
2
+ #include <pybind11/stl.h>
3
+ #include <nnf_layer.h>
4
+ #include <batchnorm.h>
5
+
6
+ namespace py = pybind11;
7
+
8
+ PYBIND11_MODULE(_core, m) {
9
+ m.doc() = "nnflow structural and layers C++ backend core plugin";
10
+
11
+ // --- Bind Enums ---
12
+ py::enum_<NNF_DataType>(m, "NNF_DataType")
13
+ .value("NNF_UINT8", NNF_DataType::NNF_UINT8)
14
+ .value("NNF_INT8", NNF_DataType::NNF_INT8)
15
+ .value("NNF_UINT16", NNF_DataType::NNF_UINT16)
16
+ .value("NNF_INT16", NNF_DataType::NNF_INT16)
17
+ .value("NNF_FLOAT16", NNF_DataType::NNF_FLOAT16)
18
+ .value("NNF_BFLOAT16", NNF_DataType::NNF_BFLOAT16)
19
+ .value("NNF_FLOAT32", NNF_DataType::NNF_FLOAT32)
20
+ .export_values();
21
+
22
+ // --- Bind Base Structural Classes ---
23
+ py::class_<NNF_Tensor>(m, "NNF_Tensor")
24
+ .def(py::init<>()); // Assumes a default constructor exists
25
+
26
+ py::class_<NNF_Buffer>(m, "NNF_Buffer")
27
+ .def(py::init<>());
28
+
29
+ py::class_<NNF_Layer>(m, "NNF_Layer")
30
+ .def(py::init<>());
31
+
32
+ py::class_<NNF_Graph>(m, "NNF_Graph")
33
+ .def(py::init<>());
34
+
35
+ // --- Bind Derived Layer Subclasses ---
36
+ // Passing NNF_Layer as the second template argument enables native Python OOP inheritance!
37
+ py::class_<BatchNorm, NNF_Layer>(m, "BatchNorm")
38
+ // Binds the constructor with default keyword arguments matching your architecture definitions
39
+ .def(py::init<std::string, float, float>(),
40
+ py::arg("name"),
41
+ py::arg("eps") = 1e-5,
42
+ py::arg("momentum") = 0.1)
43
+
44
+ // Expose parameters so you can read/write them from Python scripts directly
45
+ .def_readwrite("eps", &BatchNorm::eps)
46
+ .def_readwrite("momentum", &BatchNorm::momentum);
47
+ }
@@ -0,0 +1,13 @@
1
+ [build-system]
2
+ requires = ["scikit-build-core>=0.4.3", "pybind11"]
3
+ build-backend = "scikit_build_core.build"
4
+
5
+ [project]
6
+ name = "nnflow"
7
+ version = "0.1.0"
8
+ description = "NNFlow"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+
12
+ [tool.scikit-build]
13
+ cmake.build-type = "Release"
nnflow-0.1.0/test.py ADDED
@@ -0,0 +1,31 @@
1
+ import nnflow
2
+
3
+ print("====================================")
4
+ print("🎉 Success! nnflow loaded perfectly.")
5
+ print("====================================")
6
+
7
+ # 1. Verify and inspect your custom Enum types
8
+ print("Available Data Types:")
9
+ print(f" - Float32: {nnflow.NNF_DataType.NNF_FLOAT32}")
10
+ print(f" - BFloat16: {nnflow.NNF_DataType.NNF_BFLOAT16}")
11
+
12
+ # 2. Instantiate structural classes to confirm their baseline wrappers work
13
+ tensor = nnflow.NNF_Tensor()
14
+ graph = nnflow.NNF_Graph()
15
+ print(f"\nCreated baseline internal C++ objects:")
16
+ print(f" - Tensor instance: {tensor}")
17
+ print(f" - Graph instance: {graph}")
18
+
19
+ # 3. Create and customize your header-only BatchNorm layer
20
+ # This runs the inlined constructor we set up in batchnorm.h!
21
+ bn_layer = nnflow.BatchNorm(name="my_batchnorm_layer", eps=1e-4, momentum=0.2)
22
+
23
+ print(f"\nInstantiated BatchNorm Layer:")
24
+ print(f" - Object type: {type(bn_layer)}")
25
+ print(f" - Current eps value: {bn_layer.eps}")
26
+ print(f" - Current momentum value: {bn_layer.momentum}")
27
+
28
+ # 4. Modify properties dynamically from Python to confirm read/write bindings
29
+ bn_layer.eps = 3e-5
30
+ print(f" - Updated eps value: {bn_layer.eps}")
31
+ print("====================================")
nnflow-0.1.0/uv.lock ADDED
@@ -0,0 +1,8 @@
1
+ version = 1
2
+ revision = 5
3
+ requires-python = ">=3.8"
4
+
5
+ [[package]]
6
+ name = "nnflow"
7
+ version = "0.1.0"
8
+ source = { editable = "." }