Uh oh!
There was an error while loading. Please reload this page.
[SPARK-21685][PYTHON][ML] PySpark Params isSet state should not change after transform - #18982
[SPARK-21685][PYTHON][ML] PySpark Params isSet state should not change after transform#18982BryanCutler wants to merge 15 commits into
Conversation
SparkQA
commented
Aug 18, 2017
Test build #80813 has finished for PR 18982 at commit
|
BryanCutler
commented
Aug 18, 2017
holdenk
left a comment
There was a problem hiding this comment.
Thanks for working on this, two quick questions.
| if param in self._paramMap: | ||
| pair = self._make_java_param_pair(param, self._paramMap[param]) | ||
| self._java_obj.set(pair) | ||
| if param in self._defaultParamMap: |
There was a problem hiding this comment.
Should this be an else if? No need to transfer the default value if we've explicitly set it to another value.
There was a problem hiding this comment.
We usually make the assumption that Python defines the same default values as Java, in Spark ML at least, but given the circumstances of the JIRA - they defined their own Model - then it's still possible for hasDefault or the default value to return something different that Python would. So I'm just being overly cautious here, but it's pretty cheap to just transfer the default values anyway right?
| def test_preserve_set_state(self): | ||
| model = Binarizer() | ||
| self.assertFalse(model.isSet("threshold")) | ||
| model._transfer_params_to_java() |
There was a problem hiding this comment.
Would it make sense to do an actual transform here instead of the two inner parts of the transform?
There was a problem hiding this comment.
yeah, it would be a little better to call the actual transform, but we would still need to call _transfer_params_from_java or check isSet with a direct call to Java via py4j. I was going to do this, but the ParamTest class doesn't already create a SparkSession - I'm sure it's just a small amount of overhead but that's why I thought to just use _transfer_params_to_java.
Do you think it would be worth it to change ParamTests to inherit from SparkSessionTestCase so a session is created and I could make a DataFrame to transform?
There was a problem hiding this comment.
I think that would be a reasonable thing to do, the slight increase in testing overhead is probably worth it, it keeps us from being too closely tied to the implementation details and we already use SparkSessionTestCase in a lot of places.
BryanCutler
commented
Aug 22, 2017
Thanks for reviewing @holdenk ! You brought up some good points, let me know if you prefer me to change them. |
holdenk
commented
Sep 6, 2017
@BryanCutler sorry my slowness, responded with a note on the tests. If you have a chance to update the test and update to master I'd love to try and get this in. |
…to-java-defaults-SPARK-21685
SparkQA
commented
Sep 7, 2017
Test build #81484 has finished for PR 18982 at commit
|
BryanCutler
commented
Sep 7, 2017
Jenkins retest this please |
SparkQA
commented
Sep 7, 2017
Test build #81487 has finished for PR 18982 at commit
|
BryanCutler
commented
Sep 7, 2017
No problem @holdenk, I updated using |
BryanCutler
commented
Sep 7, 2017
Hmmm, I can repeat the error with Python3, I'll look into it tomorrow |
holdenk
commented
Sep 8, 2017
Cool, let me know if you want a hand reproing the error. |
SparkQA
commented
Sep 9, 2017
Test build #81574 has finished for PR 18982 at commit
|
BryanCutler
commented
Sep 9, 2017
@holdenk , the error was because I was calling |
SparkQA
commented
Sep 9, 2017
Test build #81577 has finished for PR 18982 at commit
|
BryanCutler
commented
Sep 11, 2017
retest this please |
SparkQA
commented
Sep 11, 2017
Test build #81647 has finished for PR 18982 at commit
|
SparkQA
commented
Nov 10, 2017
Test build #83691 has finished for PR 18982 at commit
|
holdenk
commented
Nov 18, 2017
Can we update this to master? |
…to-java-defaults-SPARK-21685
SparkQA
commented
Nov 20, 2017
Test build #84035 has finished for PR 18982 at commit
|
BryanCutler
commented
Nov 20, 2017
Hi @holdenk , this is updated. Look ok to you? |
…to-java-defaults-SPARK-21685
BryanCutler
commented
Feb 8, 2018
SparkQA
commented
Feb 8, 2018
Test build #87228 has finished for PR 18982 at commit
|
holdenk
commented
Mar 16, 2018
So between #20410 & this one which path do we want to go down? |
HyukjinKwon
commented
Mar 19, 2018
retest this please |
HyukjinKwon
commented
Mar 19, 2018
From my rough reading and based upon what I know, this seems fine. |
SparkQA
commented
Mar 19, 2018
Test build #88369 has finished for PR 18982 at commit
|
…to-java-defaults-SPARK-21685
SparkQA
commented
Mar 21, 2018
Test build #88452 has finished for PR 18982 at commit
|
HyukjinKwon
commented
Mar 21, 2018
cc @viirya too |
HyukjinKwon
commented
Mar 21, 2018
retest this please |
BryanCutler
commented
Mar 21, 2018
I think I figured out how to use params |
SparkQA
commented
Mar 21, 2018
Test build #88470 has finished for PR 18982 at commit
|
SparkQA
commented
Mar 21, 2018
Test build #88475 has finished for PR 18982 at commit
|
SparkQA
commented
Mar 21, 2018
Test build #88481 has finished for PR 18982 at commit
|
BryanCutler
commented
Mar 21, 2018
Thanks @holdenk and @HyukjinKwon ! I made a small change so that this can call the existing |
| if len(pair_defaults) > 0: | ||
| sc = SparkContext._active_spark_context | ||
| pair_defaults_seq = sc._jvm.PythonUtils.toSeq(pair_defaults) | ||
| self._java_obj.setDefault(pair_defaults_seq) |
There was a problem hiding this comment.
If java side and python side the default params are the same, do we still need to set default params for the java object? Are't they already set in java object if they are default params?
There was a problem hiding this comment.
My take is that while they should be the same, it's still possible they might not be. The user could extend their own classes or it's quite easy to change in Python. Although we don't really support this, if there was a mismatch the user would probably just get bad results and it would be really hard to figure out why. From the Python API, it would look like it was one value but actually using another in Scala.
If you all think it's overly cautious to do this, I can take it out. I just thought it would be cheap insurance to just set these values regardless.
There was a problem hiding this comment.
I think this is reasonable, a few extra lines to avoid potential unwanted user surprise is worth it.
holdenk
commented
Mar 23, 2018
Merged to master. |
BryanCutler
commented
Mar 23, 2018
Thanks @holdenk@HyukjinKwon and @viirya ! |
What changes were proposed in this pull request?
Currently when a PySpark Model is transformed, default params that have not been explicitly set are then set on the Java side on the call to
wrapper._transfer_values_to_java. This incorrectly changes the state of the Param as it should still be marked as a default value only.How was this patch tested?
Added a new test to verify that when transferring Params to Java, default params have their state preserved.