Skip to content

Commit 48f95c2

Browse files
committed
sync with develop
2 parents f4b87e5 + 70d4ba5 commit 48f95c2

File tree

103 files changed

+2084
-839
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+2084
-839
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
steps:
77
- checkout
88
- run: mkdir -p /tmp/coverage && mkdir -p /tmp/test_results
9-
- run: pip3 install -e .[dev]
9+
- run: pip3 install .
1010
- run:
1111
name: Test
1212
command: pytest -vv tests

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ dev_notes
88
!tests/deep_mlp/end_to_end.ipynb
99
*.egg*
1010
worktree/
11+
build/
12+
dist/
1113
# tests
1214
.pytest_cache
1315
tests/*/cpp

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
include LICENSE README.md
2-
recursive-include utensor_cgen/backend/snippets/templates *
2+
recursive-include utensor_cgen/backend/utensor/snippets/templates *

Makefile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
tests:
44
rm -f tests_log.txt
55
make test_utils test_ir test_transformer test_frontend \
6-
test_matcher test_graph_constructor
6+
test_matcher test_graph_constructor test_backend
77

88
test_%:
99
@if [ -d .venv ]; then \
@@ -12,5 +12,23 @@ test_%:
1212
pytest tests/$@ -vv -s | tee -a tests_log.txt; \
1313
fi;
1414

15+
package:
16+
rm -rf dist/*
17+
.venv/bin/python setup.py bdist_wheel sdist
18+
rm -rf build utensor_cgen.egg-info/
19+
20+
upload-test: package
21+
.venv/bin/twine upload -r pypitest dist/*
22+
23+
install-test: package
24+
pip uninstall -y utensor-cgen
25+
pip install dist/*.tar.gz
26+
27+
upload: package
28+
.venv/bin/twine upload -r pypi dist/*
29+
1530
clean:
16-
rm -rf tests_log.txt *.pdf .pytest_cache
31+
rm -rf tests_log.txt *.pdf \
32+
models data \
33+
tests/test_backend/{models,data} \
34+
.pytest_cache dist/ build/

Pipfile.lock

Lines changed: 431 additions & 400 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.rst

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,22 @@ Overall Architecture
7272

7373
::
7474

75-
============ +-----------------+ ===================
76-
|| model file || --> | frontend Parser | --> || uTensorGraph (IR) ||
77-
============ +-----------------+ ===================
78-
|
79-
+-------------------------------+ |
80-
| graph transformer | |
81-
| (legalization & optimization) | <------/
82-
+-------------------------------+
83-
|
84-
v
85-
===========================
86-
|| uTensorGraph ||
87-
|| (legalized and optimized) ||
88-
===========================
89-
|
90-
+--------------------------+ |
91-
| backend (code generator) | <----/
75+
============ +-----------------+ ============================
76+
|| model file || --> | frontend Parser | --> || uTensorGraph (IR, generic) ||
77+
============ +-----------------+ ============================
78+
|
79+
v
80+
+---------------------+
81+
======================= | graph transformer |
82+
|| uTensorGraph || <-- | (optimization) |
83+
|| (generic, optimized) || +---------------------+
84+
=======================
85+
|
86+
+--------------------------+ |
87+
| backend (code generator) | <--/
9288
+--------------------------+
9389
|
94-
`---> (target files, ex: model.cpp, model.hpp, weights.idx)
90+
`---> (target files, ex: model.cpp, model.hpp, weights.idx, ...etc)
9591

9692
Basic Usage
9793
===========
@@ -114,7 +110,8 @@ Convert Model File to C/C++ Code
114110
.. code-block:: console
115111
116112
$ utensor-cli convert <model.pb> \
117-
--output-nodes=<node_name>[,<node_name>,...]
113+
--output-nodes=<node name>[,<node name>,...] \
114+
[--config=config.toml]
118115
119116
Convert given pb file into cpp/hpp files.
120117

@@ -123,6 +120,8 @@ nodes you want to output, seperated by comma for multiple values.
123120

124121
In graph theory terminology, they are ``leaf`` nodes of your graph.
125122

123+
Use ``--config`` to pass a configuration file to the cli, you can use ``generate-config`` command to generate one (see below).
124+
126125
example
127126
~~~~~~~
128127

@@ -132,8 +131,34 @@ example
132131
133132
Run ``utensor-cli convert --help`` for detailed information.
134133

135-
:mod:`utensor_cgen` as Library
136-
==============================
134+
Configuration
135+
-------------
136+
137+
``utensor-cli`` use ``toml`` as configuration format.
138+
139+
You can generate configuration file of given target as following:
140+
141+
.. code-block:: console
142+
143+
$ utensor-cli generate-config --target <target name> [-o filename.toml]
144+
145+
This command will generate a ``toml`` file listing all configurable values with its defaults.
146+
147+
You can modify the value and pass the file to cli with ``--config`` flag.
148+
149+
example
150+
~~~~~~~
151+
152+
.. code-block:: console
153+
154+
# generate config file
155+
$ utensor-cli generate-config --target utensor -o myconfig.toml
156+
157+
# after editting myconfig.toml
158+
$ utensor-cli convert mymodel.pb --config=myconfig.toml --output-nodes=output,...
159+
160+
Use :mod:`utensor_cgen` as Library
161+
==================================
137162

138163
.. subgraph-match-begine
139164
@@ -223,8 +248,8 @@ TensorFlow_
223248

224249
1. Freeze your `tensorflow.Graph`
225250

226-
- please refer to the `official doc <https://www.tensorflow.org/guide/extend/model_files>`_
227-
and read the `Freezing <https://www.tensorflow.org/guide/extend/model_files#freezing>`_ section
251+
- please refer to this `issue track <https://github.com/tensorflow/tensorflow/issues/27614>`_ for detail
252+
- especially this `comment <https://github.com/tensorflow/tensorflow/issues/27614#issuecomment-571889676>`_ by Robin2091
228253

229254
2. Follow instructions in :ref:`install` section to install :mod:`utensor_cgen`
230255

example_config.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# https://github.com/toml-lang/toml
2+
# <target_name>.<component>.<part>
3+
[utensor.backend]
4+
legacy-api = true
5+
6+
[utensor.backend.legacy_code_generator]
7+
src_fname = "None"
8+
params_dir = "data"
9+
embed_params_dir = "/fs/data"
10+
model_dir = "models"
11+
transform_methods = [ "dropout(name_pattern=r\"(dropout[_\\w\\d]*)/.*\")", "linear_reorder", "quantize", "conv_pool", "inline", "biasAdd", "remove_id_op", "fake_gather_v2", "refcnt",]
12+
save_graph = false
13+
debug_cmt = false
14+
15+
[utensor.backend.graph_lower]

plugins/dummy_backend/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from textwrap import wrap
2+
3+
from utensor_cgen.backend.base import Backend
4+
from utensor_cgen.backend import BackendManager
5+
from utensor_cgen.utils import class_property
6+
7+
@BackendManager.register
8+
class DummyBackend(Backend):
9+
TARGET = 'dummy-backend'
10+
11+
def __init__(self, config):
12+
if not config:
13+
config = self.default_config
14+
self.output_file = config[self.TARGET][self.COMPONENT]['output-file']
15+
16+
def apply(self, ugraph):
17+
with open(self.output_file, 'w') as fid:
18+
fid.write('#include <stdio.h>\n\n')
19+
fid.write('int main(int argc, char* argv[]) {\n')
20+
fid.write(' printf("graph name: {}\\n");\n'.format(ugraph.name))
21+
fid.write(' printf("ops in topological sorted order:\\n");\n')
22+
for op_name in ugraph.topo_order:
23+
fid.write(' printf(" {}\\n");\n'.format(op_name))
24+
fid.write(' return 0;\n}')
25+
26+
@class_property
27+
def default_config(cls):
28+
return {
29+
cls.TARGET: {
30+
cls.COMPONENT: {
31+
'output-file': 'list_op.c'
32+
}
33+
}
34+
}

setup.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,48 @@
33
import os
44

55
from setuptools import find_packages, setup
6+
from setuptools.command.develop import develop as _develop
7+
from setuptools.command.install import install as _install
68

79
root_dir = os.path.abspath(os.path.dirname(__file__))
810
with open(os.path.join(root_dir, "LICENSE")) as rf:
911
license = rf.read()
1012

13+
14+
class _CompileFlatbuffMixin(object):
15+
16+
def run(self):
17+
super(_CompileFlatbuffMixin, self).run()
18+
self._build_flatbuffer()
19+
20+
def _build_flatbuffer(self):
21+
install_dir = self.install_platlib
22+
if install_dir is None:
23+
install_dir = os.path.abspath('utensor')
24+
25+
26+
class _Install(_CompileFlatbuffMixin, _install): pass
27+
28+
29+
class _Develop(_CompileFlatbuffMixin, _develop): pass
30+
31+
1132
setup(
1233
name='utensor_cgen',
1334
version_config={
1435
"starting_version": "0.0.0",
15-
"version_format": "{tag}.dev{sha:.7s}"
36+
"version_format": "{tag}.{sha:.7s}.dev"
1637
},
1738
setup_requires=['better-setuptools-git-version'],
39+
cmdclass={'install': _Install, 'develop': _Develop},
1840
description="C code generation program for uTensor",
1941
long_description="please go to [doc](https://utensor-cgen.readthedocs.io/en/latest/) page for more information",
20-
url="https://github.com/dboyliao/utensor_cgen",
42+
url="https://github.com/uTensor/utensor_cgen",
2143
author="Dboy Liao",
2244
author_email="qmalliao@gmail.com",
2345
license=license,
2446
packages=find_packages(),
25-
include_package_data=True,
26-
package_data={"utensor_cgen": ["backend/snippets/templates/*"]},
47+
package_data={'utensor_cgen.backend.utensor.snippets': ["templates/*/*/*"]},
2748
entry_points={
2849
"console_scripts": [
2950
"utensor-cli=utensor_cgen.cli:cli"
@@ -38,7 +59,8 @@
3859
'torchvision',
3960
'onnx-tf==1.2.1',
4061
'graphviz',
41-
'flatbuffers'
62+
'flatbuffers',
63+
'toml',
4264
],
4365
extras_require={
4466
'dev': ['pytest']

tests/test_backend/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)