Skip to content

Conversation

realdoug
Copy link

@realdoug realdoug commented Apr 9, 2019

naming & code organization changes as discussed here

Copy link
Contributor

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

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

Thank you! 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you'll need to rename usages of NumpyConversionTests to PythonConversionTests as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// This file defines conversion logic between Python types &
// This file defines conversions between Python types and TensorFlow library
// types.

@realdoug
Copy link
Author

realdoug commented Apr 9, 2019

@dan-zheng My bad, noticed the Python/Numpy test naming right after hitting submit. Should be good now.

@dan-zheng
Copy link
Contributor

@swift-ci Please test tensorflow

@dan-zheng dan-zheng added the tensorflow This is for "tensorflow" branch PRs. label Apr 9, 2019
@dan-zheng
Copy link
Contributor

@swift-ci Please test tensorflow

Copy link
Contributor

@rxwei rxwei left a comment

Choose a reason for hiding this comment

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

There's some important issues I missed in the last merged PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if(hasLen == true) {
if Python.hasattr(pythonObject, "__len__" == true {

Copy link
Contributor

Choose a reason for hiding this comment

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

End sentences with a period.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be 80 columns long.

Copy link
Author

Choose a reason for hiding this comment

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

@rxwei is there a linter I can install to catch this kind of stuff?

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't review the last change closely. Maybe tests broke because TensorShape(0)'s initialization defaulted to TensorShape(0 as PythonObject) somehow?

Copy link
Author

Choose a reason for hiding this comment

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

@rxwei Yep, that is exactly the case. I spent some time looking into how to manipulate the prority order of the initializers, but if you have a suggested approach i can definitely try it out. I settled for just making sure that this initializer successfully passes through to the correct initializer, since TensorShape(0 as PythonObject) should be valid anyway.

It is also possible that the failure was due to this initializer being failable, but the only reliable repro steps are what I outlined here.

I guess the question is what would you want/expect the output of the below program to be?

func doThing(_ arg: PythonObject) {
  print(type(of: arg))
}

func doThing(_ arg: Int32) {
  print(type(of: arg))
}

doThing(1)

Output currently is PythonObject. Perhaps that is the real underlying bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. There are two bigger problems. First, the TensorFlow module shouldn't logically depend on Python, i.e. there can be targets that require all APIs that use Python be #if'd out. Second, we ultimately want to optimize tensor operations through techniques like graph program extraction, but having this Python layer for the initialization of a simple tensor shape makes it extremely inefficient when we are targeting hardware like TPUs.

I think a better solution would be to split this protocol into two. This has actually been on my mind for over a year now:

PythonConvertible defines conversion to Python; ConvertibleFromPython defines conversion from Python.

TensorShape will then only conform to PythonConvertible, but not the other one, making this integer literal issue go away.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, makes sense. I could definitely work on a PR for the split up of the protocol.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great. Let's do that!

Copy link
Contributor

Choose a reason for hiding this comment

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

Matching scalar does seem right to me. Why is this necessary?

Copy link
Author

@realdoug realdoug Apr 11, 2019

Choose a reason for hiding this comment

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

@rxwei the reason is that [Int32](1) (and [Int32](1 as PythonObject)) is not valid in Swift, but TensorShape(1) is valid. Or do you mean that you would just prefer [Int32]([pythonObject]) here?

@dan-zheng dan-zheng self-requested a review April 12, 2019 05:06
@realdoug
Copy link
Author

realdoug commented Apr 12, 2019

@dan-zheng ok, made the syntax updates here in case you want to merge just this. I'll follow up later this weekend with the protocol split.

@realdoug realdoug changed the title [TF-76] numpy => python [TF-76] PythonConvertible conformance for TensorShape Apr 15, 2019
@realdoug
Copy link
Author

@dan-zheng @rxwei this branch has the protocol split on it now.

@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

Oh excellent. We can skip the revert then.

Copy link
Contributor

@rxwei rxwei left a comment

Choose a reason for hiding this comment

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

This is awesome. Thanks Doug!

rxwei and others added 3 commits April 15, 2019 17:43
Co-Authored-By: realdoug <dfriedm3@gmail.com>
Co-Authored-By: realdoug <dfriedm3@gmail.com>
Co-Authored-By: realdoug <dfriedm3@gmail.com>
@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

@swift-ci please test tensorflow

3 similar comments
@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

@swift-ci please test tensorflow Linux

@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

CI seems dead. This PR needs to go in before #24012. @dan-zheng could you help make sure this gets tested?

Co-Authored-By: realdoug <dfriedm3@gmail.com>
@realdoug realdoug changed the title [TF-76] PythonConvertible conformance for TensorShape [TF-76] file renames + split PythonConvertible protocol Apr 15, 2019
@dan-zheng
Copy link
Contributor

@swift-ci Please test tensorflow

1 similar comment
@dan-zheng
Copy link
Contributor

@swift-ci Please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

@swift-ci please test tensorflow

@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

@swift-ci please test tensorflow, seriously

@dan-zheng
Copy link
Contributor

dan-zheng commented Apr 15, 2019

@swift-ci Please test tensorflow

EDIT: I think Jenkins is busy. https://ci-external.swift.org/computer/ubuntu-16.04-tensorflow
Once non-PR CI is done, let's try to trigger PR CI.

@rxwei
Copy link
Contributor

rxwei commented Apr 15, 2019

@swift-ci please test tensorflow

@dan-zheng
Copy link
Contributor

@swift-ci Please test tensorflow

@dan-zheng
Copy link
Contributor

@swift-ci Please test tensorflow linux

@rxwei
Copy link
Contributor

rxwei commented Apr 16, 2019

@swift-ci please test tensorflow Linux

@dan-zheng
Copy link
Contributor

There is one test failure:

[ RUN      ] PythonConversion.shaped-array-conversion
stdout>>> check failed at /Volumes/BuildData/Users/swiftci/jenkins/workspace/swift-PR-TensorFlow-macOS/swift/test/TensorFlowRuntime/python_conversion.swift, line 62
stdout>>> expected: (2, 7, 2) (of type Python.PythonObject)
stdout>>> actual: [2, 7, 2] (of type Python.PythonObject)
stdout>>> check failed at /Volumes/BuildData/Users/swiftci/jenkins/workspace/swift-PR-TensorFlow-macOS/swift/test/TensorFlowRuntime/python_conversion.swift, line 64
stdout>>> expected: (14, 2) (of type Python.PythonObject)
stdout>>> actual: [14, 2] (of type Python.PythonObject)
[     FAIL ] PythonConversion.shaped-array-conversion
[ RUN      ] PythonConversion.tensor-conversion
[       OK ] PythonConversion.tensor-conversion
[ RUN      ] PythonConversion.tensor-round-trip
[       OK ] PythonConversion.tensor-round-trip
[ RUN      ] PythonConversion.tensor-shape
[       OK ] PythonConversion.tensor-shape
PythonConversion: Some tests failed, aborting
UXPASS: []
FAIL: ["shaped-array-conversion"]
SKIP: []

NumPy arrays have tuple shapes, not list shapes.
@dan-zheng
Copy link
Contributor

@swift-ci Please test tensorflow

@dan-zheng dan-zheng merged commit 3c27938 into swiftlang:tensorflow Apr 16, 2019
@realdoug
Copy link
Author

ugh sorry bout that! Could have sworn that passed locally for me.

rxwei pushed a commit to rxwei/swift that referenced this pull request May 11, 2019
)

Split `PythonConvertible` into two protocols:
* `PythonConvertible`: conversion to Python.
* `ConvertibleFromPython`: conversion from Python.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tensorflow This is for "tensorflow" branch PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants