Skip to content

Windoze/udf improve#139

Merged
xiaoyongzhu merged 6 commits into
feathr-ai:mainfrom
windoze:windoze/udf-improve
Apr 26, 2022
Merged

Windoze/udf improve#139
xiaoyongzhu merged 6 commits into
feathr-ai:mainfrom
windoze:windoze/udf-improve

Conversation

@windoze

@windoze windoze commented Apr 19, 2022

Copy link
Copy Markdown
Member

This PR is to resolve #133.
Previously we use inspect.getsource to retrieve the UDF source code and concat it after the Python driver template, the issue is this method doesn't support functions which call any other functions, as well as lambdas and other callable object, and it also has many other limitations.
PySpark itself uses cloudpickle to serialize/deserialize Python functions and objects and transfers them between executors and drivers, this PR uses the same module to replace inspect, so it can improve the previous implementation and avoid involving new dependencies.
The PR changes the content of the generated UDF repo code, but keeps the compatibility of the interface so other parts need no change.

@hangfei

hangfei commented Apr 19, 2022

Copy link
Copy Markdown
Collaborator

@windoze

windoze commented Apr 19, 2022

Copy link
Copy Markdown
Member Author

Updated PR description.

@xiaoyongzhu xiaoyongzhu added the safe to test Tag to execute build pipeline for a PR from forked repo label Apr 19, 2022
@hangfei

hangfei commented Apr 21, 2022

Copy link
Copy Markdown
Collaborator

If a function depends on a chain of function, or a function depdends on a library that is huge, how does the pickle work? Will it still work(recursively)? Will it the function pickle become too huge?

Comment thread feathr_project/feathr/_preprocessing_pyudf_manager.py Outdated
@windoze

windoze commented Apr 21, 2022

Copy link
Copy Markdown
Member Author

@hangfei yes it will, cloudpickle serialize object recursively by value, the process stops at the module boundary, and will trigger module importing on deserialization when needed, so the only limitation appears when some local modules are not available on the remote side(there is a workaround but needs few manual steps).
The same process is used by PySpark, it uses cloudpickle to transfer compute tasks between drivers and executors.

The package size will not be significant usually, but some caution needs to be taken, i.e. if you create a 1M elements list in your UDF, the list will also be packed into the output byte array and increase its size dramatically, but this issue is actually inevitable, not matter what solution do you use.

@hangfei

hangfei commented Apr 21, 2022

Copy link
Copy Markdown
Collaborator

@hangfei yes it will, cloudpickle serialize object recursively by value, the process stops at the module boundary, and will trigger module importing on deserialization when needed, so the only limitation appears when some local modules are not available on the remote side(there is a workaround but needs few manual steps). The same process is used by PySpark, it uses cloudpickle to transfer compute tasks between drivers and executors.

The package size will not be significant usually, but some caution needs to be taken, i.e. if you create a 1M elements list in your UDF, the list will also be packed into the output byte array and increase its size dramatically, but this issue is actually inevitable, not matter what solution do you use.

module is equal to a lib?

Could you provide a user guide for this part? better with examples on their own dependencies, code that they import from their teammates or some third party libs.

@windoze

windoze commented Apr 21, 2022

Copy link
Copy Markdown
Member Author

I think we can just add a note that refers to the official cloudpickle document, no need to add too many our own words or comments.

@xiaoyongzhu

Copy link
Copy Markdown
Member

I think we can just add a note that refers to the official cloudpickle document, no need to add too many our own words or comments.

can you add a few lines in the developer doc?

@hangfei

hangfei commented Apr 21, 2022

Copy link
Copy Markdown
Collaborator

d a few lines in the de

Do you mean in addition to user guide, we can mention pickle in dev guide? I feel you are right. We should do both here but with different emphasis. User guide should not mention pickle. Dev guide should mention pickle.

@xiaoyongzhu

Copy link
Copy Markdown
Member

Not sure why the envs are not read correctly (probably because this PR is opened earlier than the PR which enables forked repo test)

@hangfei

hangfei commented Apr 25, 2022

Copy link
Copy Markdown
Collaborator

Release candidate for v0.4.0

@xiaoyongzhu xiaoyongzhu added this to the 0.4.0 milestone Apr 25, 2022
@hangfei

hangfei commented Apr 26, 2022

Copy link
Copy Markdown
Collaborator

Please fix the tests.

@xiaoyongzhu xiaoyongzhu merged commit 68acb0b into feathr-ai:main Apr 26, 2022
@xiaoyongzhu

Copy link
Copy Markdown
Member

The test fails because of credentials not found. I'm merging it to see the final CI, and will keep guys updated.

@windoze windoze mentioned this pull request Apr 26, 2022
xiaoyongzhu added a commit that referenced this pull request Apr 27, 2022
xiaoyongzhu added a commit that referenced this pull request Apr 27, 2022
xiaoyongzhu added a commit that referenced this pull request Apr 27, 2022
hangfei pushed a commit that referenced this pull request Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Tag to execute build pipeline for a PR from forked repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate ways to relax restrictions to call PySpark UDFs

3 participants