-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Bring Your Own Datatypes #5812
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
Merged
Merged
Bring Your Own Datatypes #5812
Changes from all commits
Commits
Show all changes
167 commits
Select commit
Hold shift + click to select a range
97eca8e
Add ChangeDatatype pass and unittest
gussmith23 4861ad5
[WIP] Jared's work on Fri
gussmith23 d6a0309
Fix simplify inference to work over different data types.
jroesch f5f37f0
Formatting
gussmith23 3b879c9
Copy setup code from other test file
gussmith23 143195d
Logging in Relay
gussmith23 95485b7
Remove duplicate TVM_DLL
gussmith23 73fe88f
Add Sub, Mul, Div, Max to bfloat lib
gussmith23 cbee8f6
Fix previous broken rebased commit
gussmith23 5b4e108
Remove line
gussmith23 10bf96a
Add LowerCustomDatatypes to build passes
gussmith23 549af5e
Upcast ints to custom datatypes too, as well as to floats
gussmith23 b290d29
Add and use convert_ndarray
gussmith23 40b3e82
Lower Call
gussmith23 dd615af
Relay: create constant scalars of custom dtypes
gussmith23 ab248f3
Custom datatype formatting in Relay
gussmith23 d2e4119
Update unittests
gussmith23 a4506ae
Add simpler example that's not working yet
gussmith23 fed9103
Add Python unittests to Makefile
gussmith23 8369343
Fix bug
gussmith23 4633964
Fix function name in GetPackedFunc call
gussmith23 a118a6e
convert_ndarray makes its own executor
gussmith23 d54e738
Add simple test case
gussmith23 d2f2e18
Move setup() calls
gussmith23 cdfda16
Use convert_ndarray
gussmith23 ef335e5
Change import to make it more specific
gussmith23 78438aa
Fix another Registry::Get call
gussmith23 49dad92
Allow users to register minimum functions for custom datatypes
gussmith23 bab3bb3
Remove check for float
gussmith23 97c3714
Add test
gussmith23 d78f8a7
Fix inception test
gussmith23 3b99965
Add MobileNet
gussmith23 62d26fe
Lower custom datatypes before intrinsics
gussmith23 5fe578c
Add exp and sqrt bfloat functions
gussmith23 6e3ee1f
[buggy commit] Lower intrinsics like sqrt, exp
gussmith23 e9997ba
Formatting
gussmith23 838e087
Fix bug
gussmith23 976113a
Add lowering for new ops in test
gussmith23 f82ad51
Add int to bfloat
gussmith23 a734c09
Remove print
gussmith23 02565f3
Add all tests
gussmith23 a7dbbdc
Correct image size
gussmith23 1dd86a6
Add TODO
gussmith23 4c592a0
Add "notbfloat" type
gussmith23 ab89ce8
Convert arguments
gussmith23 4848ab4
Rewrite custom datatype constants in Relay
gussmith23 f05cf34
Add test_ops
gussmith23 14d34b7
Print constants in Relay
gussmith23 c5cddb0
Use topi.testing
gussmith23 2ea0e84
Test conv2d
gussmith23 2c4b73f
Add test_model
gussmith23 b7191fb
Comment out model tests
gussmith23 119ea8d
Register notbfloat
gussmith23 e66c9c4
Add commented code
gussmith23 038b957
Add posit tests
gussmith23 69eebcd
test_ops_same_function
gussmith23 8077878
[temporary] move incomplete commit to macbook
gussmith23 ab4bd75
Add more to tests
gussmith23 a20c15c
Formatting
gussmith23 6008895
Uncomment add
gussmith23 7fa8275
Remove bad tests
gussmith23 ca27fbe
Change comments
gussmith23 40378b8
Change function name and docstring
gussmith23 0ed63f7
Change main function
gussmith23 f47b541
Restructure tests
gussmith23 190407e
Fix visibility of posit functions
gussmith23 2e17add
YAPF
gussmith23 8f26fce
Switching keywords around to resolve build errors on some systems
gussmith23 73ea71b
Improve test by running smaller mobilenet
gussmith23 545b80b
Add test_cast
gussmith23 134e597
Change datatype name; add simple test
gussmith23 27edbd0
Rename to posit32
gussmith23 899ce54
Merge 3 posit types into one file
gussmith23 26f4815
Add a nop type
gussmith23 cf4f1db
Remove bfloat
gussmith23 4e9b618
Refactor test comments
gussmith23 a8d10b0
Refactor conv2d test
gussmith23 442e4f5
Add optional tolerance arguments
gussmith23 660714e
Add posit8 and posit16
gussmith23 da22056
Add comment about posit8
gussmith23 20e3a7c
Whoops -- actually add noptype to CMakeLists
gussmith23 21e79b2
Add rtol, atol to run_workload
gussmith23 23b9d16
Add noptype to tests
gussmith23 d9db34b
Run noptype over other models, too
gussmith23 7335f1b
Pass correct arguments to calls
gussmith23 8fe5d27
Fix line length errors
gussmith23 fc82c57
Raise tolerances (again) to avoid flaky test
gussmith23 6e102f9
fix style
hypercubestart 1312648
add test for tanh, log, sigmoid
hypercubestart 08f86d0
Remove references to bfloat, notbfloat
gussmith23 e396fa7
Change comments
gussmith23 b3d25a8
Remove old test file
gussmith23 098e2d5
fix min func
hypercubestart b9afc23
refactoring unit test file
hypercubestart f225add
use posits es2
hypercubestart 35742f8
cleanup
hypercubestart ce02836
comment
hypercubestart f855fa2
coment if_then_else
hypercubestart ce533ca
support different bit widths
hypercubestart bbe7a34
use random seed to create stable tests
hypercubestart 4da49fc
update documentation
hypercubestart 460d713
removed nop-type and code consistency
hypercubestart e14913b
add batchnorm test
hypercubestart 2d43218
rebase and update
hypercubestart eb24a6a
fix tests and format
hypercubestart 9501e55
pylint
hypercubestart 640e745
change order of include
hypercubestart 37a1540
include order
hypercubestart 946902f
fix style
hypercubestart 134fc52
remove posit c linkage
hypercubestart d97766d
update universal
hypercubestart 28466ba
fix style
hypercubestart 8de1844
fix test
hypercubestart 99a5cda
fix overflow error with minfunc and posits
hypercubestart ab0235d
style
hypercubestart f58e263
use change_dtype to convert params
hypercubestart 4189fdc
update universal
hypercubestart e136658
fix fatal error
hypercubestart 3f90742
fix constant repr
hypercubestart 7e2047e
minor update to posites2
hypercubestart ee640d5
update universal
hypercubestart 8d49900
fix rst
hypercubestart d5c3d71
fix invalid import and sqrt
hypercubestart f543c80
update universal
hypercubestart 5b4f126
comments
hypercubestart e9a6c44
comments and expand testing
hypercubestart 34b762d
increase atol/rtol for custom[posites2]32
hypercubestart 6231cb3
Re-add newline
gussmith23 f57c037
Remove comment
gussmith23 65c59eb
Remove opt level and comment
gussmith23 42501be
Change docstring
gussmith23 a1960d0
Add TODO
gussmith23 b30e08c
Add file header and newline
gussmith23 a00957c
Update docstring
gussmith23 c9920fc
Update file docstring
gussmith23 3b2fa03
Update docstrings
gussmith23 8aa7c7b
Delete todos
gussmith23 9a11027
create_min_lower_func
hypercubestart b3d3af3
add better debugging message
hypercubestart 5b501c4
docs
hypercubestart cc3d6cc
add BYODT tutorial
hypercubestart f683ff6
add todo
hypercubestart 00f87a2
Reformat some of tutorial to RST, plus code fixes
gussmith23 36443bd
tutorial notebook runs now
hypercubestart a957d4d
fix hyperlink
hypercubestart c940fc0
rebase
hypercubestart 7030a81
add to tutorial
hypercubestart 5d4b119
fix mobilenet model
hypercubestart 1aaf723
add skip tag
hypercubestart ff1a87d
black lint
hypercubestart 515746d
add compiler flag and add dummy float
hypercubestart 33084fe
myfloat and posites2 test
hypercubestart d3e9168
remove universal
hypercubestart 25850a3
lint
hypercubestart 2c34863
lint
hypercubestart 6998ab7
add setup
hypercubestart 3b9fff2
build with USE_POSIT for CI/CD
hypercubestart e2898fe
fix posit cmake
hypercubestart f96c95e
add cd /
hypercubestart baa453b
undo docker changes
hypercubestart 30b8b6e
change tutorial to use myfloat
hypercubestart 142a055
move files
hypercubestart 21b7da9
lint
hypercubestart eba7389
fix
hypercubestart 47fde5e
remove filter
hypercubestart 3967ed9
fix lint
hypercubestart ccdc65b
fix suggestions
hypercubestart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
if(USE_BYOC_POSIT) | ||
message(STATUS "Build with contrib.posit") | ||
if (NOT UNIVERSAL_PATH) | ||
message(FATAL_ERROR "Fail to get Universal path") | ||
endif(NOT UNIVERSAL_PATH) | ||
|
||
include_directories(${UNIVERSAL_PATH}/include) | ||
list(APPEND COMPILER_SRCS "src/target/datatype/posit/posit-wrapper.cc") | ||
endif(USE_BYOC_POSIT) |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# pylint: disable=unused-argument | ||
"""Change Datatype Pass""" | ||
from ..function import Function | ||
from ..expr_functor import ExprMutator | ||
from ..transform.transform import function_pass | ||
from ..expr import var, bind | ||
|
||
|
||
@function_pass(opt_level=0) | ||
gussmith23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
class ChangeDatatype(ExprMutator): | ||
"""Mutator for changing the datatype of Relay programs. | ||
|
||
This pass should be useful for users of the Bring Your Own Datatypes | ||
framework. | ||
TODO(@gussmith23 @hypercubestart) Add link to documentation when it exists | ||
|
||
Example: | ||
|
||
.. code-block:: python | ||
|
||
from tvm.relay.testing.inception_v3 import get_workload | ||
mod, params = get_workload() | ||
|
||
def change_dtype(mod, params, src, dst): | ||
mod = ChangeDatatype(src, dst)(mod) | ||
params = dict((p, tvm.nd.array(params[p].asnumpy().astype(dst))) for p in params) | ||
return mod, params | ||
|
||
mod, params = change_dtype(mod, params, "float32", "custom[posites2]32") | ||
|
||
Parameters | ||
---------- | ||
src : String | ||
The source datatype name, e.g. "float" or "posites2" (but not "float32" | ||
or "custom[posites2]32"). | ||
dst : String | ||
The destination datatype name, in the same format. | ||
|
||
Returns | ||
------- | ||
mod : tvm.IRModule | ||
Module where all nodes of dtype `src` have been changed to have dtype | ||
`dst`. | ||
""" | ||
|
||
def __init__(self, src, dst): | ||
self.src = src | ||
self.dst = dst | ||
super().__init__() | ||
|
||
def transform_function(self, func, mod, ctx): | ||
return self.visit(func) | ||
|
||
def visit_constant(self, const): | ||
if const.data.dtype == self.src: | ||
return const.astype(self.dst) | ||
return const | ||
gussmith23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def visit_function(self, fn): | ||
new_params = [] | ||
binds = {} | ||
|
||
for param in fn.params: | ||
# Get the parameter's type annotation. | ||
var_type = param.type_annotation | ||
|
||
# See if we want to replace dtype. | ||
if var_type.dtype == self.src: | ||
dtype = self.dst | ||
else: | ||
dtype = var_type.dtype | ||
|
||
# Generate new variable. | ||
new_param = var(param.name_hint, shape=var_type.shape, dtype=dtype) | ||
|
||
new_params.append(new_param) | ||
binds[param] = new_param | ||
|
||
new_body = self.visit(fn.body) | ||
# Rewrite the body to use new parameters. | ||
new_body = bind(new_body, binds) | ||
|
||
# Construct the updated function and return. | ||
return Function( | ||
new_params, | ||
new_body, | ||
# You could change the return type, if you use None it will re-infer. | ||
None, | ||
type_params=fn.type_params, | ||
attrs=fn.attrs, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also remove https://github.com/apache/incubator-tvm/blob/master/licenses/LICENSE.bfloat16.txt