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

Support passing JActivity from python to java #1985

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

zhichao-li
Copy link
Contributor

@zhichao-li zhichao-li commented Dec 6, 2017

What changes were proposed in this pull request?

This PR would enable us to pass JActivity from Python to Java which is consist of ndarray or nested list of ndarray . JActivity(Python) --> JActivity(Java)
i.e:

        value = np.random.random_sample([2, 3])
        nested = JActivity([ [value, value],  [value, value]])
        back = callBigDlFunc("float", "testPyToJavaActivity",
                             nested)

How was this patch tested?

unittest

@zhichao-li
Copy link
Contributor Author

@jason-dai How about this style?
By default, we only return JActivity as JavaObject without Serialization and we can use toPy method to enforce the serialization to convert it to ndarray or nested list of ndarray.

Java Side:

  def testPyToJavaActivity(jactivity: JActivity): JActivity = {
    jactivity
  }

Python Side:

        back = callBigDlFunc("float", "testActivityWithTableOfTable")  # back is a JActivity from Java which is a JavaObject without serialization
        assert isinstance(back, JavaObject)
        back_again = callBigDlFunc("float", "testPyToJavaActivity", back)  # back_again is also a JavaObject withou serialization
        assert isinstance(back_again, JavaObject)
        back_again = back_again.toPy()
        assert isinstance(back_again.value, list)
        assert isinstance(back_again.value[0], list)
        assert isinstance(back_again.value[0][0], np.ndarray)

@zhichao-li
Copy link
Contributor Author

jenkins passed

@jason-dai
Copy link
Contributor

Please check with @dding3 on how this will be used?

@dding3
Copy link
Contributor

dding3 commented Dec 6, 2017

I usually set state which returned from get_hidden_state directly in set_hidden_state. And I tried this PR with simplernn/lstm/multirnncell, it works good.

@jason-dai
Copy link
Contributor

Why do you need to do that in python @dding3 ? I think this is needed in seq2seq training, and that's done in scala side?

@dding3
Copy link
Contributor

dding3 commented Dec 7, 2017

Yes, it's done in scala side.

However in scala Recurrent, we support get/setHiddenState and they are public APIs. Besides, both tf and torch support user set init state. I am thinking it would be better if we support these functionality in python as well.

@jason-dai
Copy link
Contributor

I don't think we need to add that at this moment if no one is expected use that.

@zhichao-li
Copy link
Contributor Author

BTW, the there's no overhead for get/set JActivity if without calling toPy() on this PR.

dding3 pushed a commit to dding3/BigDL that referenced this pull request Nov 17, 2021
dding3 pushed a commit to dding3/BigDL that referenced this pull request Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants