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

[Relay][Frontend][Tensorflow] Fix GatherV2, Add StopGradient #4238

Merged
merged 2 commits into from
Nov 4, 2019

Conversation

trevor-m
Copy link
Contributor

@trevor-m trevor-m commented Oct 31, 2019

These changes are needed to parse a BERT TF model into relay.

  1. GatherV2
    TensorFlow recently added batch_dims as an attribute of the GatherV2 op to support batched gather. This would cause the parser the fail since it didn't expect that attribute. I added a check to make sure the attribute doesn't change the behavior of the op if it happens to exist and also added it to the ignore list. We can support parsing of batched gather at a later date.

  2. StopGradient
    This is a training op meant to stop gradient flow over certain edges in the graph. It has no purpose in inference so it can be safely mapped to identity.

@kevinthesun
Copy link
Contributor

kevinthesun commented Oct 31, 2019

@trevor-m Thank you for adding this. Can you take a look at the CI failure?

@trevor-m
Copy link
Contributor Author

trevor-m commented Oct 31, 2019

@trevor-m Thank you for adding this. Can you take a look at the CI failure?

Thanks @kevinthesun, the link http://ci.tvm.ai:8080/job/tvm/job/PR-4238/1/display/redirect isn't working for me.

Edit:
Looks like unrelated issue with runner:

docker: failed to register layer: Error processing tar file(exit status 1): write /usr/local/VulkanSDK/1.0.65.0/source/shaderc/src/build/third_party/spirv-tools/test/val/test_val_validation_state: no space left on device.

@yzhliu
Copy link
Member

yzhliu commented Oct 31, 2019

please kick ci later.

@MarisaKirisame
Copy link
Contributor

MarisaKirisame commented Oct 31, 2019

I object mapping it to identity directly, because we have an ad algorithm. Can it be replaced with an operator that map to identity, and has grad of 0?

@trevor-m
Copy link
Contributor Author

trevor-m commented Nov 1, 2019

I object mapping it to identity directly, because we have an ad algorithm. Can it be replaced with an operator that map to identity, and has grad of 0?

That makes sense to me. How do you see this being implemented? Do you mean creating a new op in relay or is there a way to do it just in the parser?

Looks like nnvm had an op block_grad which is equivalent to StopGradients.

@MarisaKirisame
Copy link
Contributor

You have to create an op in relay.
Then, it will have a grad function, which will return [zeros_like(orig.args[0])].
It wont be a big change (probably ~30 lines, most of which will be copied), and it will help you learn a bit about the stack.
I can do it if you found it too difficult though.

@trevor-m
Copy link
Contributor Author

trevor-m commented Nov 2, 2019

That sounds good, thanks for the description!

I’ll update this PR with the change shortly.

@tqchen tqchen merged commit 3f472f9 into apache:master Nov 4, 2019
zxy844288792 pushed a commit to neo-ai/tvm that referenced this pull request Nov 13, 2019
…4238)

* Add StopGradient. Add batch_dims attr to ignore list for GatherV2

* Trigger CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants