Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tflite backend #93

Open
wants to merge 125 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
723965c
WIP
neil-tan Apr 23, 2019
7659273
- verified dependencies are importable
neil-tan Apr 24, 2019
236ec41
initial commit
neil-tan Oct 4, 2019
4bb2de5
op regristation
neil-tan Oct 5, 2019
3f19de7
tied everything together; lacks of op factory/converter
neil-tan Oct 7, 2019
9db8ba4
uses Affine Quantization
neil-tan Oct 9, 2019
f46ff9f
private variable and member functions
neil-tan Oct 9, 2019
8b60cc5
float32 for intermediate tensors
neil-tan Oct 16, 2019
295efea
- bugfixes in tflite_exporter.py
neil-tan Oct 17, 2019
b7f3adb
problem with tensor.isVariable()
neil-tan Oct 17, 2019
4d37abf
problem reading back tensor buffers
neil-tan Oct 17, 2019
fdd18a2
tensor buffer bug fix
neil-tan Oct 18, 2019
280fdc8
-fixed problem with builtin_opcode
neil-tan Oct 22, 2019
4f72a8b
iterables require reversing prior to flatbuffer prepending
neil-tan Nov 22, 2019
58d533f
refactoring: fb-vector-builder in progress
neil-tan Nov 23, 2019
5a56092
fb-vector-builder refactoring completed
neil-tan Nov 23, 2019
1a184ed
- using flatbuffers 136d75fa6580ef87d1b7cbc243e617f21149852e
neil-tan Nov 25, 2019
99c925a
daily commit - ops require options; see TODO in tflite_exporter.py
neil-tan Nov 27, 2019
ab7d08e
OperatorAddBuiltinOptions breaks input tensors? try regenerate the fl…
neil-tan Nov 28, 2019
2fd92f6
regenerated the fb python bindings
neil-tan Nov 29, 2019
56bbd26
input1 tensor failed to print after invoke
neil-tan Nov 29, 2019
acef9d0
- a more comprehensive test graph
neil-tan Nov 29, 2019
0e3c5f1
binding data to the first input tensor
neil-tan Nov 29, 2019
b16236b
run test with "pytest -s tests/tflm"
neil-tan Nov 29, 2019
3c60d92
clean up flatbuffers import
neil-tan Nov 29, 2019
5c1bf60
added flatbuffers to setup.py
neil-tan Dec 6, 2019
f4b87e5
updated this branch to use the new ugraph-constructor
neil-tan Dec 12, 2019
ab6940a
- onnx frontend build ugraph done (missing shape and dtype)
dboyliao Feb 22, 2020
6317eda
update tests and fix transformers
dboyliao Feb 24, 2020
f697120
making some transformer generic (not specific to tensorflow)
dboyliao Feb 25, 2020
fb5413e
update pipfile, locks
dboyliao Feb 27, 2020
ae052c9
lock file update
dboyliao Feb 28, 2020
8e8ef35
ortools mem allocation optimizer
dboyliao Feb 29, 2020
4a23369
tensor mem alloc: fix bug and add logging
dboyliao Feb 29, 2020
3e282a2
tensor mem alloc visualization
dboyliao Mar 1, 2020
ba5ad38
minor fix
dboyliao Mar 1, 2020
c87784e
python3.5 compatible (no f-string)
dboyliao Mar 1, 2020
8b09892
remove data manager from snippet creation and update tests
dboyliao Mar 2, 2020
5f3f2d2
cleanup DataManager, TensorLifeProbe transformer and update tests
dboyliao Mar 2, 2020
2b3481b
Fix kwargs parsing bug, add include_inputs flag for tensor alloc tran…
dboyliao Mar 2, 2020
4458319
better visualization
dboyliao Mar 3, 2020
a5a3043
update README
dboyliao Mar 3, 2020
9fb54f7
use backendpart to refactor the offline memory planner
Knight-X Feb 19, 2020
416f21a
fix bugs and update tests (exclude slow test)
dboyliao Mar 4, 2020
b0ecd72
make graph_lower a submodule
dboyliao Mar 5, 2020
facaa5d
Decouple graph transformation and code generator
dboyliao Mar 5, 2020
444ddbe
update tests
dboyliao Mar 7, 2020
11bc08b
Add test for cli speed
dboyliao Mar 7, 2020
fd749f4
circle-ci: utf8 local
dboyliao Mar 7, 2020
1ccc721
making tensor alloc lowering optional
dboyliao Mar 8, 2020
d8a17cf
update tests and add comments/docstrings
dboyliao Mar 8, 2020
af52ec8
fix bug and update tests
dboyliao Mar 8, 2020
a3f0368
make Configuration nearly unmutable object
dboyliao Mar 8, 2020
f07f5dd
Add notes to generated config file
dboyliao Mar 8, 2020
aa7a2fe
Fix transformer bug and update tests
dboyliao Mar 8, 2020
e11cc0d
update plugin example
dboyliao Mar 8, 2020
2ad07b9
unify alloc plan format
dboyliao Mar 9, 2020
1154aec
Fix init signature and add comments
dboyliao Mar 9, 2020
f8a81d6
Fix indentation
dboyliao Mar 10, 2020
78e9678
making bakend part apply and transform abstract and put checks on them
dboyliao Mar 10, 2020
ef50c05
update templates
dboyliao Mar 10, 2020
7670a0a
add tests
dboyliao Mar 11, 2020
d17e873
Extensible OpEqualityDelegate
dboyliao Mar 11, 2020
6feccbe
modify for brutal force version of memory planner
Knight-X Mar 11, 2020
4b5f8fd
remove the unnecssary lib
Knight-X Mar 11, 2020
3dc3f03
change the default setting of memory planner
Knight-X Mar 11, 2020
26e38f6
remove the brutal force memory planner
Knight-X Mar 11, 2020
d5f50c7
Merge pull request #105 from Knight-X/rearch_pr
dboyliao Mar 11, 2020
7ba874f
Merge pull request #104 from uTensor/rearch
dboyliao Mar 11, 2020
4179356
Merge pull request #103 from uTensor/ortools
dboyliao Mar 11, 2020
ac08440
resolve review issues
dboyliao Mar 13, 2020
ef4f1cb
Add data alignment attribute for SpaceAllocation
dboyliao Mar 13, 2020
2c2c9e6
better logging messages
dboyliao Mar 13, 2020
7d9d6ea
add comments
dboyliao Mar 14, 2020
89b0b73
merge develop and fixed a conflict
neil-tan Mar 20, 2020
436a3f8
Merge remote-tracking branch 'origin/develop' into f/tflite-parser
neil-tan Mar 20, 2020
6796df5
resolve code review issues, including renaming and minor code
dboyliao Mar 18, 2020
319f635
add new cnn pb file
dboyliao Mar 20, 2020
fde1fc8
update README.rst
dboyliao Mar 20, 2020
982bffd
resolve review issue: subroutines for rearch code generator and tests
dboyliao Mar 21, 2020
f31f012
minor update for tests
dboyliao Mar 21, 2020
97efefd
Add attributes to _Operator (rearch)
dboyliao Mar 23, 2020
1166e91
modify backend apply procedure
dboyliao Apr 1, 2020
c4bd90f
nightly
neil-tan Apr 1, 2020
95a1c50
memory planner: make output tensors optionally included in the planning
dboyliao Apr 7, 2020
e23a17b
before testing
neil-tan Apr 7, 2020
4c09391
merge onnx branch
dboyliao Apr 8, 2020
373bbc5
seems to work on the first glance, expecting devils in the detail
neil-tan Apr 9, 2020
142d752
checkpoint before reworking the quantization info
neil-tan Apr 12, 2020
598f824
quantization param in generic type
neil-tan Apr 12, 2020
a4f21ec
minor cleanup
neil-tan Apr 12, 2020
d7fe924
Add constructor signature for op factory
dboyliao Apr 15, 2020
154d8ab
Resolve review issues
dboyliao Apr 18, 2020
df94383
Formatting files
dboyliao Apr 20, 2020
4577bf8
update lockfile
dboyliao Apr 20, 2020
1cc82c5
reformat file and add configuration to pylint
dboyliao Apr 21, 2020
5606693
Fix "b"-prefix in the tensor names (with decoding to utf8)
dboyliao Apr 23, 2020
21da98c
addressing issues mentioned in the PR107 comments
neil-tan Apr 24, 2020
bda37bb
fix node_name
dboyliao Apr 24, 2020
3903dfe
Fix linting issues
dboyliao Apr 24, 2020
a8c904e
fix minor issues and add test for tflite parser
dboyliao Apr 24, 2020
1da0d5b
Merge pull request #107 from uTensor/f/tflite-parser
dboyliao Apr 24, 2020
13644c3
re-arch code generator refactoring
dboyliao Apr 27, 2020
9ed32f4
clean up code
dboyliao Apr 28, 2020
131e978
adding ops for code generator
dboyliao Apr 28, 2020
cff4940
minor fix: utils.prune_graph
dboyliao Apr 29, 2020
5dda2b9
rearch code generator beta
dboyliao Apr 29, 2020
090cd31
fix templates and type str
dboyliao Apr 30, 2020
b4469a7
namespaces support (same optype, different namespaces)
dboyliao May 1, 2020
5851a49
Fix bug and minor refactor (removing misleading op_info attributes fo…
dboyliao May 1, 2020
5a09094
Fix templates and snippets bug
dboyliao May 1, 2020
fa6c7f4
method renaming to prevent misunderstanding
dboyliao May 3, 2020
249a11c
Fix TF2.0 imports and bugs (v1 and v2 behavior inconsistent)
dboyliao May 4, 2020
79491c3
update tests and fix onnx parser
dboyliao May 4, 2020
1d6e3c7
add tests
dboyliao May 4, 2020
d6352a3
TF 2.0 support
dboyliao May 4, 2020
139a890
update requirements.txt
dboyliao May 4, 2020
2f84e09
speed up loading time
dboyliao May 4, 2020
8418cc2
prettify printing
dboyliao May 4, 2020
32f78cd
cli refactoring and exporting high-level api
dboyliao May 5, 2020
357a212
Add isort:skip_file
dboyliao May 5, 2020
18a396a
Add target kwargs to api
dboyliao May 6, 2020
18f0460
sync with release branch
dboyliao May 6, 2020
cae7806
remove frontend.tflite_flatbuffer module and update imports
dboyliao May 6, 2020
31b9f50
update tests
dboyliao May 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- run: pip3 install .
- run:
name: Test
command: pytest -vv tests
command: LC_ALL=C.UTF-8 LANG=C.UTF-8 pytest -vv tests -m 'not slow_test and not deprecated'
#- run: genhtml main_coverage.info --output-directory /tmp/coverage
#- store_test_results:
# path: /tmp/test_results
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#system files
__pycache__
.DS_Store
# virtual env
.venv
venv
Expand All @@ -20,4 +23,4 @@ tests/deep_mlp/data
.vscode
# docs
doc/build
doc/source/_build
doc/source/_build
6 changes: 5 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
verify_ssl = false
name = "pypi"

[packages]
e1839a8 = {path = ".",editable = true}

[dev-packages]
matplotlib = "*"
pylint = "*"
"flake8" = "*"
pytest = "*"
Expand All @@ -16,3 +17,6 @@ scipy = "*"
graphviz = "*"
sphinx = "*"
sphinx-autoapi = "*"

[pipenv]
allow_prereleases = true
1,163 changes: 696 additions & 467 deletions Pipfile.lock

Large diffs are not rendered by default.

30 changes: 27 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,32 @@ Use Case: Dropout Layer Removal

\ |cnn-dropout|

.. subgraph-match-end

We use mainly `Tensorflow`_ for declaring the pattern graph for matcher now.

High-level graph builder is on its way, see `Future Works <#future-works>`_ for detail.

.. subgraph-match-end

.. offline-tensor-alloc-start

Offline Tensor Memory Allocation
--------------------------------

Considering following simple multi layers perceptron (`simple_mnist.pb`_):

\ |mlp-alloc-graph|

Once enabled the optimization transformer, ``tensor_alloc``, an offline tensor memory allocation planner,
``utensor-cli`` will generate ``uTensor`` runtime codes that use following optimized allocation plan:

\ |mlp-alloc|

- y-axis: tensor names ordered by topological sorting
- x-axis: these are the memory span occupied by each tensor, that is, the memory address offset and
the size of the tensor

.. offline-tensor-alloc-end

Tutorials
=========

Expand Down Expand Up @@ -313,6 +333,7 @@ Future Works
.. _Tensorflow: https://www.tensorflow.org
.. _PyTorch: https://pytorch.org/
.. _uTensor: https://github.com/uTensor/uTensor
.. _simple_mnist.pb: https://github.com/uTensor/utensor_cgen/blob/develop/tests/deep_mlp/simple_mnist.pb

.. readme_end

Expand All @@ -322,7 +343,10 @@ Future Works
:alt: conv-pool-fuse
.. |convert-example| image:: doc/source/_images/convert_example.png
:alt: convert-example

.. |mlp-alloc| image:: doc/source/_images/mlp_alloc.png
:alt: mlp-alloc
.. |mlp-alloc-graph| image:: doc/source/_images/mlp_alloc_graph.png
:alt: mlp-alloc-graph

.. TODOs
.. =====
Expand Down
Binary file added doc/source/_images/mlp_alloc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/_images/mlp_alloc_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions doc/source/images.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@
:height: 300
.. |convert-example| image:: /_images/convert_example.png
:alt: convert-example
.. |mlp-alloc| image:: /_images/mlp_alloc.png
:alt: mlp-alloc
.. |mlp-alloc-graph| image:: /_images/mlp_alloc_graph.png
:alt: mlp-alloc-graph
:width: 300
:height: 450
41 changes: 38 additions & 3 deletions example_config.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
# https://github.com/toml-lang/toml
# <target_name>.<component>.<part>
# we use string 'None' to represent python None value
# you should convert the string to None if you try to write extension for utensor_cgen
[utensor.backend]
legacy-api = true

[utensor.backend.tensor_alloc_planner]
max_pool_size = 1048576
include_inputs = false
out_fname = "None"
enabled = true

[utensor.backend.legacy_code_generator]
src_fname = "None"
params_dir = "data"
embed_params_dir = "/fs/data"
model_dir = "models"
transform_methods = [ "dropout(name_pattern=r\"(dropout[_\\w\\d]*)/.*\")", "linear_reorder", "quantize", "conv_pool", "inline", "biasAdd", "remove_id_op", "fake_gather_v2", "refcnt",]
save_graph = false
debug_cmt = false

[utensor.backend.graph_lower]
[utensor.backend.legacy_graph_lower]

[utensor.backend.rearch_code_generator]
src_fname = "None"
header_fname = "None"
params_dir = "data"
model_dir = "models"
meta_data_pool_size = "auto"
ram_data_pool_size = "auto"

[utensor.backend.rearch_graph_lower]

[utensor.backend.pipeline_transformer]
save_graph = false
transform_methods = [ "dropout(name_pattern=r'(dropout[_\\w\\d]*)/.*')", "linear_reorder", "quantize", "conv_pool", "inline", "biasAdd", "remove_id_op", "fake_gather_v2", "refcnt",]

[utensor.backend.tensor_alloc_planner.aesthetic_kwargs]
split_on_large_graph = true
num_tensors_per_split = 20
figsize = "None"
fontsize = 12
lw = 12
rand_seed = 1111

[utensor.backend.tensor_alloc_planner.dtype_size_map]
float = 4
double = 8
uint8 = 1
int = 4
long = 8
45 changes: 22 additions & 23 deletions plugins/dummy_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
from textwrap import wrap

from utensor_cgen.backend.base import Backend
from utensor_cgen.backend import BackendManager
from utensor_cgen.backend.base import Backend
from utensor_cgen.utils import class_property


@BackendManager.register
class DummyBackend(Backend):
TARGET = 'dummy-backend'
TARGET = 'dummy-backend'

def __init__(self, config):
if not config:
config = self.default_config
self.output_file = config[self.TARGET][self.COMPONENT]['output-file']
def __init__(self, config):
self.output_file = self.config[self.TARGET][self.COMPONENT]['output-file']

def apply(self, ugraph):
with open(self.output_file, 'w') as fid:
fid.write('#include <stdio.h>\n\n')
fid.write('int main(int argc, char* argv[]) {\n')
fid.write(' printf("graph name: {}\\n");\n'.format(ugraph.name))
fid.write(' printf("ops in topological sorted order:\\n");\n')
for op_name in ugraph.topo_order:
fid.write(' printf(" {}\\n");\n'.format(op_name))
fid.write(' return 0;\n}')
def apply(self, ugraph):
with open(self.output_file, 'w') as fid:
fid.write('#include <stdio.h>\n\n')
fid.write('int main(int argc, char* argv[]) {\n')
fid.write(' printf("graph name: {}\\n");\n'.format(ugraph.name))
fid.write(' printf("ops in topological sorted order:\\n");\n')
for op_name in ugraph.topo_order:
fid.write(' printf(" {}\\n");\n'.format(op_name))
fid.write(' return 0;\n}')

@class_property
def default_config(cls):
return {
cls.TARGET: {
cls.COMPONENT: {
'output-file': 'list_op.c'
}
}
@class_property
def default_config(cls):
return {
cls.TARGET: {
cls.COMPONENT: {
'output-file': 'list_op.c'
}
}
}
Loading