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

[BugFix] Fixes #20983 - Store py_func dtypes for correct conversion #21038

Merged
merged 3 commits into from
Aug 10, 2018

Conversation

sabhiram
Copy link
Contributor

@sabhiram sabhiram commented Jul 22, 2018

  1. Implement wrapper class PythonFunc to store Tout list
    for appropriate dtype conversion from tensorflow types to
    numpy types using the dtype.as_numpy_dtype member.
  2. Add py_func_test to illustrate broken behavior (see
    testConvertEmptyList).

@caisq caisq self-assigned this Jul 23, 2018
@caisq caisq added awaiting review Pull request awaiting review kokoro:run labels Jul 23, 2018
@sabhiram
Copy link
Contributor Author

sabhiram commented Jul 23, 2018

^ WIP on the CI errors - they were due to the FuncRegistry._convert() being used from dataset_ops. If this is being called this way, should _convert (better name?) be exposed from script_ops more officially (not through the FuncRegistry)?

My fixes are done, I am in-tow for the 9 million bazel files that needed recompilation :) Will squash and push once I confirm things are resolved locally.

"""Tests for script_ops.py_func."""

def test_basic_convert(self):
def get_not_empty_list(args):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you delete this file and add your tests to tensorflow/python/kernel_tests/py_func_test.py?

@@ -2524,6 +2524,18 @@ py_library(
],
)

py_test(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this build rule and instead add your tests to tensorflow/python/kernel_tests/py_func_test.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do - thanks for the pointers. Will fix and push shortly.

@asimshankar asimshankar removed their request for review July 23, 2018 17:36
…nversion

1.  Implement wrapper class `PythonFunc` to store Tout list
    for appropriate dtype conversion from tensorflow types to
    numpy types using the `dtype.as_numpy_dtype` member.
2.  Adjust BUILD file to include py_test of the script_ops_test.
3.  Add script_ops_test to illustrate broken behavior (see
    `test_convert_empty_list`). Run the specific test suite with:

      bazel test //tensorflow/python:script_ops_test

4.  `_convert` was being called from dataset_ops, update this to
    refer to the `PythonFunc` instead of the `FuncRegistry`.
5.  [Review Feedback] Move script_ops tests to py_func_test.py. Also
    removed the BUILD rules for the deleted test file.
@sabhiram
Copy link
Contributor Author

@akshayka - Thanks for the feedback, I think I should have done justice to your comments. Please let me know if this looks better.

PS: One of the basic tests that I had originally added seemed useless given the py_func_test.py file, so I went ahead and removed it (preserved the test that will fail without these changes).

self._convert(x, dtype=dtype.as_numpy_dtype)
for (x, dtype) in zip(ret, self._out_dtypes)
]
return self._convert(ret) # TODO: pass self._out_dtypes?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to not pass out_dtypes here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose if the py_func returns a None, it could lead to some similar (unexpected) behavior. Let me see about adding another test or two so we can check this. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing - the registry will force the Tout to be an array / list -- see ~line 270 in the _internal_py_func where the Tout is initialized. So we would need to sanitize the _out_dtypes. But that should be easy.

Disabled the `testBadNumpyReturnType` which should allow for a
conversion of an arbitrary np.array into a list of a specified dtype.

Modified the exception expectation for the `testBadReturnType` test.
@sabhiram
Copy link
Contributor Author

@akshayka - One of the tests is commented out as (I think) it no longer applies. Once we are all happy with this changeset, I can squash the edits so you have a single commit to merge (if that matters).

@tensorflowbutler tensorflowbutler removed the awaiting review Pull request awaiting review label Jul 24, 2018
@akshayka
Copy link
Contributor

Great, go ahead and delete the test you commented out, I agree with you that it no longer applies.

@sabhiram
Copy link
Contributor Author

@akshaym - any reservations?

@akshaym
Copy link
Contributor

akshaym commented Jul 26, 2018

@sabhiram not from me. I think @akshayka is the best person to review this, so I'll unassign myself.

@akshaym akshaym removed their request for review July 26, 2018 21:10
@sabhiram
Copy link
Contributor Author

@akshayka - I think this is good to go - might need your blessing before the bot takes over.

tensorflow-copybara pushed a commit that referenced this pull request Aug 10, 2018
tensorflow-copybara pushed a commit that referenced this pull request Aug 10, 2018
Rollback breaking change.
END_PUBLIC

Automated rollback of commit 20622da. Revert #21038.

PiperOrigin-RevId: 208256026
@sabhiram
Copy link
Contributor Author

@akshayka - Heh, what did I break? Unfortunately I cannot peer into the CI process enough to guess how this affected what. Happy to help see it through if needed.

@akshayka
Copy link
Contributor

Hey Sabhiram, sorry for the delay. I didn't have the time to diagnose the issue, but the change caused an internal-only test to segfault.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes ready to pull PR ready for merge process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants