-
Notifications
You must be signed in to change notification settings - Fork 614
Added an option to use the pure python implementation. #1137
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
Changes from all commits
e4f4fd7
91fb3a2
ed123be
a17572e
44e2b73
e717d0b
73c149e
b66e1ac
39ef6f8
d8bc287
ab32156
fe9246f
60c7c9f
d6a3aac
3b906e2
3183583
415f1f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ py_library( | |
"tanhshrink.py", | ||
], | ||
data = [ | ||
"//tensorflow_addons:options.py", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree that is this painful and unituitive. Sorry for any wasted time. We could raise this with the bazel team, but I believe this is fundamental to how this resolving works. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's linked to how bazel works and that makes sense for monorepos like tensorflow. I'm not convinced the added value of making the wheels + running the tests with bazel outweight the costs in addons. It makes totally sense to use it to build the SO though. I know we had a similar conversation a while ago, maybe I'll open an issue so that we can discuss it more. Anyway thanks for the fix! It helps a lot! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think this can be discussed further. Typical contributions to Addons will/should fall into a subpackage that should have the BUILD already setup. This PR is a change that affects the entirety of the project so it's a bit more complicated. I agree we should encourage contributors to make these types of changes but we can look at and cons again to see if its worth splitting the C++ test/builds from python tests/builds. |
||
"//tensorflow_addons/custom_ops/activations:_activation_ops.so", | ||
"//tensorflow_addons/utils", | ||
], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
import platform | ||
import warnings | ||
import traceback | ||
|
||
try: | ||
TF_ADDONS_PY_OPS = bool(int(os.environ["TF_ADDONS_PY_OPS"])) | ||
except KeyError: | ||
if platform.system() == "Linux": | ||
TF_ADDONS_PY_OPS = False | ||
else: | ||
TF_ADDONS_PY_OPS = True | ||
seanpmorgan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
FALLBACK_WARNING_TEMPLATE = """{} | ||
|
||
The {} C++/CUDA custom op could not be loaded. | ||
For this reason, Addons will fallback to an implementation written | ||
in Python with public TensorFlow ops. There worst you might experience with | ||
this is a moderate slowdown on GPU. There can be multiple | ||
gabrieldemarmiesse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
reason for this loading error, one of them may be an ABI incompatibility between | ||
the TensorFlow installed on your system and the TensorFlow used to compile | ||
TensorFlow Addons' custom ops. The stacktrace generated when loading the | ||
shared object file was displayed above. | ||
|
||
If you want this warning to disappear, either make sure the TensorFlow installed | ||
is compatible with this version of Addons, or tell TensorFlow Addons to | ||
prefer using Python implementations and not custom C++/CUDA ones. You can do that | ||
by changing the TF_ADDONS_PY_OPS flag | ||
either with the environment variable: | ||
```bash | ||
TF_ADDONS_PY_OPS=1 python my_script.py | ||
``` | ||
or in your code, after your imports: | ||
```python | ||
import tensorflow_addons as tfa | ||
import ... | ||
import ... | ||
|
||
tfa.options.TF_ADDONS_PY_OPS = True | ||
``` | ||
""" | ||
|
||
|
||
def warn_fallback(op_name): | ||
warning_msg = FALLBACK_WARNING_TEMPLATE.format(traceback.format_exc(), op_name) | ||
warnings.warn(warning_msg, RuntimeWarning) | ||
global TF_ADDONS_PY_OPS | ||
TF_ADDONS_PY_OPS = True |
Uh oh!
There was an error while loading. Please reload this page.