-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Fix the TF tutorial to run against TF2.0 and TF1.x #4104
Conversation
TF2.0 adds a `half_pixel_centers` attribute to the `resize` function in the image API. This commit completes the hooks in Relay's TF frontend. At the point of this commit, no new test yet. Also, this commit addresses solely the `resize` change. Other commits address other changes in TF2.0.
This looks cleaner than trying to detect the TF version.
This is a direct change, relying on the compat API provided by the TF team. This code will last as long as the compat API exists, so a "proper" support for TF1.x and 2.x will require more work in some future.
Explicit padding is a special case in TF2.0 (see reference linked below). Some models are serialized with that mode, and break TF support in TVM. Support is *partial* as EXPLICIT falls back to set padding on the Relay op, which only supports 2 values. At some point, padding may need to be extended to support 4 values, but that is out of scope of this support commit. Reference on EXPLICIT padding: tensorflow/tensorflow@ec81825#diff-1d1c0bb0a880f85b6164f71dbb2f446e
The `half_pixel_centers` attribute is a new feature in TF2.0. Earlier commits of mine mistakenly introduce them in the Relay API. This is probably not what Relay is expected to support, and the semantics of `half_pixel_centers` is unclear (to me, at least) at this point.
@srkreddy1238 Not sure who to ask for reviews. Would you guide me on this one? |
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.
Left one comment but otherwise LGTM.
return AttrCvt(op_name="resize", | ||
ignores=['Tdim'], | ||
ignores=['Tdim', 'half_pixel_centers'], |
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.
it would be nice if add half_pixel_centers
in tvm resize op. If the result is different from tensorflow, we might need to raise error instead of ignoring
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.
I think half_pixel_centers is the new name of align_corners (used in TF 1.X) that we do support in tvm resize.
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.
then add transforms={'half_pixel_centers':'align_corners'}
here should be working
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.
It seems the two attributes serve different purposes. The doc says nothing really. The source code does half_pixel_centers
processing is applied optionally on top of align_corners
processing. E.g.
Eigen::Index in_y = std::min(
(align_corners)
? static_cast<Eigen::Index>(roundf(scaler(y, height_scale)))
: static_cast<Eigen::Index>(floorf(scaler(y, height_scale))),
in_height - 1);
if (half_pixel_centers) {
in_y = std::max(static_cast<Eigen::Index>(0), in_y);
}
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.
Idea: How about a unit test that compares a TF model using that attribute to Relay ignoring the attribute? I was reading the test suite to add to this PR, when I saw little coverage on such kind of issue, and fixing the tutorial seemed good to release early.
I'll try a test today, but if you have some guidance/advice/preference, I'd be happy to hear it. It may just be a different PR.
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.
left several comments, lgtm
CR apache#4104 (comment) Addresses apache#4104
Complying without understanding the rationale for now.
An argument ignored for the wrong operation.
Note: At present tests fail, but I cannot say why (they seem unrelated to changes here). The same errors happen on |
@ic could you retrigger the CI by push a trivial commit? |
@yzhliu Sorry for my late reaction. Just syncing with |
* WIP Run the TF tutorial on TF2 * Remove debugger statement. * Complete the support for TF2.0's `resize`. TF2.0 adds a `half_pixel_centers` attribute to the `resize` function in the image API. This commit completes the hooks in Relay's TF frontend. At the point of this commit, no new test yet. Also, this commit addresses solely the `resize` change. Other commits address other changes in TF2.0. * Support TF2.0 in the tutorial by using the compat API. This looks cleaner than trying to detect the TF version. * Use the TF compat API, so as to support TF2.0. This is a direct change, relying on the compat API provided by the TF team. This code will last as long as the compat API exists, so a "proper" support for TF1.x and 2.x will require more work in some future. * Partial support for EXPLICIT padding introduced in TF2.0. Explicit padding is a special case in TF2.0 (see reference linked below). Some models are serialized with that mode, and break TF support in TVM. Support is *partial* as EXPLICIT falls back to set padding on the Relay op, which only supports 2 values. At some point, padding may need to be extended to support 4 values, but that is out of scope of this support commit. Reference on EXPLICIT padding: tensorflow/tensorflow@ec81825#diff-1d1c0bb0a880f85b6164f71dbb2f446e * Guard on checking for optional TF2.0 attribute. * Do not expect Relay to implement TF-specific attributes. The `half_pixel_centers` attribute is a new feature in TF2.0. Earlier commits of mine mistakenly introduce them in the Relay API. This is probably not what Relay is expected to support, and the semantics of `half_pixel_centers` is unclear (to me, at least) at this point. * Remove unclear comment. CR apache#4104 (comment) Addresses apache#4104 * Changes after review. Complying without understanding the rationale for now. * Fix the arguments set mistakenly. An argument ignored for the wrong operation.
TF 2.0 is now the stable release and breaks a few operations (different names, attributes, namespaces, etc). TF 1.x still evolves a little bit (1.15 coming), and the user community is likely to expect 1.x to still be supported.
This PR fixes the TF tutorial, as well as the TF frontend to Relay, so as to address #4101 . It is also the first part in supporting TF2.x completely.
Note for CR:
tests/python/frontend/tensorflow/test_forward.py
around line 1103), so I guess it is more valuable for the community to get a fixed tutorial sooner. I am looking at how to test such change effectively, though, so may push something before the CR is completed (or require to complete).The following is the original contents for this PR, but way too broad. The target to support TF2.0 is tracked with issue #4102
This PR is WIP (read "not working yet"), as suggested by @srkreddy1238 to get started with TF 2 support
TF 2.0 is now the stable release and breaks a few operations (different names, attributes, namespaces, etc). TF 1.x still evolves a little bit (1.15 coming), and the user community is likely to expect 1.x to still be supported.
Here is a very early attempt at supporting TF 2.0, still compatible with TF 1.x, based on a first target: Get the TF tutorial back on track. There will be more to do.
resize
has a new attribute, and no choice but to add it).