Skip to content

Instantly share code, notes, and snippets.

@agostini01
Created December 3, 2019 16:26
Show Gist options
  • Save agostini01/8d393c11d61c0c16231f6f57385a6650 to your computer and use it in GitHub Desktop.
Save agostini01/8d393c11d61c0c16231f6f57385a6650 to your computer and use it in GitHub Desktop.
Custom OP for tensorflow 2.0

I have been working on TF 2.0 and the custom op tutorial presented here does allow execution of the op.

This is mainly due to eager execution and different custom op handling.

In order to call a custom op in python one must:

Start docker image

docker pull tensorflow/tensorflow:nightly-custom-op-ubuntu16
docker run -it --rm tensorflow/tensorflow:nightly-custom-op-ubuntu16 /bin/bash

Inside docker

git clone https://github.com/tensorflow/custom-op.git
cd custom-op

Build the pip package with bazel

./configure.sh
bazel build build_pip_pkg
bazel-bin/build_pip_pkg artifacts

Install the pip package

pip install artifacts/*.whl

Test the package

cd .. # Super important, otherwise python can't see the tensorflow_zero_out kernel
python -c "import tensorflow as tf;import tensorflow_zero_out as myop;print(myop.zero_out([[1,2], [3,4]]))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment