-
Notifications
You must be signed in to change notification settings - Fork 305
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
Pickle remote task for Jupyter Notebook Environment #2733
Conversation
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
…e init_remote() & update doc Signed-off-by: Mecoli1219 <[email protected]>
…python_check Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
@pingsutw I noticed the map_task wasn’t using the DefaultNotebookTaskResolver, so I’ve updated it. Could you please approve the CI test? |
we have to use |
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Signed-off-by: Mecoli1219 <[email protected]>
Update comment: Map task:For Nevertheless, I believe we need to have a more determined behavior for extracting information about pickled tasks or tasks from the Jupyter Notebook cells. |
Signed-off-by: Mecoli1219 <[email protected]>
I do not want to use I implemented a way to run in a jupyter notebook without |
@thomasjpfan Thank you for your support. I completely understand the concerns around using |
@thomasjpfan / @Mecoli1219 i would love to get this merged :). how can we move to get this done? |
@kumare3 The code for interactive mode in the Jupyter notebook is ready. However, the current approach requires using Let me know if there’s anything else I can assist with to get this merged! |
I opened #2784 to update I tested this PR with my updates to |
Signed-off-by: Thomas J. Fan <[email protected]>
Signed-off-by: Thomas J. Fan <[email protected]>
Signed-off-by: Thomas J. Fan <[email protected]>
Signed-off-by: Thomas J. Fan <[email protected]>
Signed-off-by: Thomas J. Fan <[email protected]>
Signed-off-by: Thomas J. Fan <[email protected]>
hey @Mecoli1219 few comments on the pr. first thank you though for taking it across the finish line. had a few questions and wanted to revisit some things though...
more structural stuff:
Thank you! |
@wild-endeavor Thank you for your comments! I apologize for any inconvenience this PR may have caused. Here are some clarifications and further thoughts based on our discussion: Quick Response
you’re right about the Promise part. We don’t need to pickle the Promise object anymore. The issue was caused by some previously unorganized and faulty code, which has since been cleaned up.
I agree that we should add the basename to Discussion
I’m not entirely sure what you mean by “non-mutating” in this context. In this code snippet the serialization settings are being updated as well. Nevertheless, after revisiting the code, I think there is another possible alternative is that we can pickle the file within
Currently, file_uploader uses the I believe this restructuring could simplify the code, but I’m not sure if it’s too late to implement such changes at this stage. What are your thoughts? |
Update: I found that pickling the file within
I understand the concern around using network calls in translator.py, but I couldn’t find a better solution for now. Nevertheless, I think that using |
* Use Jupyter notebooks to execute tasks Signed-off-by: Ketan Umare <[email protected]> * More updates Signed-off-by: Ketan Umare <[email protected]> * map task update Signed-off-by: Ketan Umare <[email protected]> * entrypoint fix Signed-off-by: Ketan Umare <[email protected]> * Working map task Signed-off-by: Ketan Umare <[email protected]> * updated for map tasks and removed unnecessary prints Signed-off-by: Ketan Umare <[email protected]> * Almost working, dynamic needs work in remote Signed-off-by: Ketan Umare <[email protected]> * Dynamic task trial Signed-off-by: Ketan Umare <[email protected]> * dynamic update Signed-off-by: Ketan Umare <[email protected]> * Updates Signed-off-by: Ketan Umare <[email protected]> * map task fix Signed-off-by: Ketan Umare <[email protected]> * create interface for task & workflow for jupyter notebook Signed-off-by: Mecoli1219 <[email protected]> * lint & docstring Signed-off-by: Mecoli1219 <[email protected]> * enable computed version Signed-off-by: Mecoli1219 <[email protected]> * add version for workflow Signed-off-by: Mecoli1219 <[email protected]> * disable file upload for workflow Signed-off-by: Mecoli1219 <[email protected]> * lint Signed-off-by: Mecoli1219 <[email protected]> * Add testing jupyter interaction Signed-off-by: Mecoli1219 <[email protected]> * lint & fix import script error Signed-off-by: Mecoli1219 <[email protected]> * Update unit test Signed-off-by: Mecoli1219 <[email protected]> * Make it thread safe Signed-off-by: Mecoli1219 <[email protected]> * Enable options for both init_remote() and remote() & restrict one-time init_remote() & update doc Signed-off-by: Mecoli1219 <[email protected]> * [Still Trying...] Store the interactive_mode_enabled to avoid using ipython_check Signed-off-by: Mecoli1219 <[email protected]> * Add interactive mode enable for init_remote & fix unit test Signed-off-by: Mecoli1219 <[email protected]> * Fix intergration test Signed-off-by: Mecoli1219 <[email protected]> * Fix unit-test Signed-off-by: Mecoli1219 <[email protected]> * Update integration test names & skip the unsupported test Signed-off-by: Mecoli1219 <[email protected]> * lint Signed-off-by: Mecoli1219 <[email protected]> * enable verbosity & small update & update docstring Signed-off-by: Mecoli1219 <[email protected]> * Enable map_task with partial_fn & Add unit test Signed-off-by: Mecoli1219 <[email protected]> * save from merge Signed-off-by: Mecoli1219 <[email protected]> * Add translator unit test for interactive Signed-off-by: Mecoli1219 <[email protected]> * Remove fast_register_file_uploader Signed-off-by: Mecoli1219 <[email protected]> * Fix merge error Signed-off-by: Mecoli1219 <[email protected]> * Remove future Signed-off-by: Mecoli1219 <[email protected]> * Fix unit-test Signed-off-by: Mecoli1219 <[email protected]> * Fix entrypoint Signed-off-by: Mecoli1219 <[email protected]> * lint Signed-off-by: Kevin Su <[email protected]> * update tracker Signed-off-by: Kevin Su <[email protected]> * Fix I/O on closed file error Signed-off-by: Mecoli1219 <[email protected]> * Update integration test Signed-off-by: Mecoli1219 <[email protected]> * Update integration test Signed-off-by: Mecoli1219 <[email protected]> * Remove unused try & error for event loop Signed-off-by: Mecoli1219 <[email protected]> * Set size limit to pickled file Signed-off-by: Mecoli1219 <[email protected]> * Remove nest_asyncio Signed-off-by: Mecoli1219 <[email protected]> * Remove some args for pyflyte-execute Signed-off-by: Mecoli1219 <[email protected]> * Remove changes to entrypoint Signed-off-by: Mecoli1219 <[email protected]> * Fix map task Signed-off-by: Mecoli1219 <[email protected]> * Remove unnecessary code Signed-off-by: Mecoli1219 <[email protected]> * Remove unnecessary code Signed-off-by: Mecoli1219 <[email protected]> * Add more test Signed-off-by: Mecoli1219 <[email protected]> * fix unit test Signed-off-by: Mecoli1219 <[email protected]> * notebook task resolver Signed-off-by: Kevin Su <[email protected]> * set resolver Signed-off-by: Kevin Su <[email protected]> * Update test Signed-off-by: Mecoli1219 <[email protected]> * Update test Signed-off-by: Mecoli1219 <[email protected]> * Update test Signed-off-by: Mecoli1219 <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * fix unit test Signed-off-by: Kevin Su <[email protected]> * fix unit test Signed-off-by: Kevin Su <[email protected]> * interactive_mode_enabled=True Signed-off-by: Kevin Su <[email protected]> * display_ipython_warning Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Mecoli1219 <[email protected]> * fix unit test Signed-off-by: Mecoli1219 <[email protected]> * Move pkl.gz to global variable Signed-off-by: Mecoli1219 <[email protected]> * change logging level Signed-off-by: Mecoli1219 <[email protected]> * Fix map task not using notebook resolver Signed-off-by: Mecoli1219 <[email protected]> * Add map task serialization unit test Signed-off-by: Mecoli1219 <[email protected]> * moving some codes & fix map_task problem Signed-off-by: Mecoli1219 <[email protected]> * Fix map task extract pickled task module error Signed-off-by: Mecoli1219 <[email protected]> * wrap the ipython check into a function Signed-off-by: Mecoli1219 <[email protected]> * Fix test Signed-off-by: Thomas J. Fan <[email protected]> * Adds integration test for jupyter Signed-off-by: Thomas J. Fan <[email protected]> * Install kernel before using KernelManager Signed-off-by: Thomas J. Fan <[email protected]> * Add a module scope kernel install Signed-off-by: Thomas J. Fan <[email protected]> --------- Signed-off-by: Ketan Umare <[email protected]> Signed-off-by: Mecoli1219 <[email protected]> Signed-off-by: Kevin Su <[email protected]> Signed-off-by: Thomas J. Fan <[email protected]> Co-authored-by: Ketan Umare <[email protected]> Co-authored-by: Kevin Su <[email protected]> Co-authored-by: Thomas J. Fan <[email protected]>
* Use Jupyter notebooks to execute tasks Signed-off-by: Ketan Umare <[email protected]> * More updates Signed-off-by: Ketan Umare <[email protected]> * map task update Signed-off-by: Ketan Umare <[email protected]> * entrypoint fix Signed-off-by: Ketan Umare <[email protected]> * Working map task Signed-off-by: Ketan Umare <[email protected]> * updated for map tasks and removed unnecessary prints Signed-off-by: Ketan Umare <[email protected]> * Almost working, dynamic needs work in remote Signed-off-by: Ketan Umare <[email protected]> * Dynamic task trial Signed-off-by: Ketan Umare <[email protected]> * dynamic update Signed-off-by: Ketan Umare <[email protected]> * Updates Signed-off-by: Ketan Umare <[email protected]> * map task fix Signed-off-by: Ketan Umare <[email protected]> * create interface for task & workflow for jupyter notebook Signed-off-by: Mecoli1219 <[email protected]> * lint & docstring Signed-off-by: Mecoli1219 <[email protected]> * enable computed version Signed-off-by: Mecoli1219 <[email protected]> * add version for workflow Signed-off-by: Mecoli1219 <[email protected]> * disable file upload for workflow Signed-off-by: Mecoli1219 <[email protected]> * lint Signed-off-by: Mecoli1219 <[email protected]> * Add testing jupyter interaction Signed-off-by: Mecoli1219 <[email protected]> * lint & fix import script error Signed-off-by: Mecoli1219 <[email protected]> * Update unit test Signed-off-by: Mecoli1219 <[email protected]> * Make it thread safe Signed-off-by: Mecoli1219 <[email protected]> * Enable options for both init_remote() and remote() & restrict one-time init_remote() & update doc Signed-off-by: Mecoli1219 <[email protected]> * [Still Trying...] Store the interactive_mode_enabled to avoid using ipython_check Signed-off-by: Mecoli1219 <[email protected]> * Add interactive mode enable for init_remote & fix unit test Signed-off-by: Mecoli1219 <[email protected]> * Fix intergration test Signed-off-by: Mecoli1219 <[email protected]> * Fix unit-test Signed-off-by: Mecoli1219 <[email protected]> * Update integration test names & skip the unsupported test Signed-off-by: Mecoli1219 <[email protected]> * lint Signed-off-by: Mecoli1219 <[email protected]> * enable verbosity & small update & update docstring Signed-off-by: Mecoli1219 <[email protected]> * Enable map_task with partial_fn & Add unit test Signed-off-by: Mecoli1219 <[email protected]> * save from merge Signed-off-by: Mecoli1219 <[email protected]> * Add translator unit test for interactive Signed-off-by: Mecoli1219 <[email protected]> * Remove fast_register_file_uploader Signed-off-by: Mecoli1219 <[email protected]> * Fix merge error Signed-off-by: Mecoli1219 <[email protected]> * Remove future Signed-off-by: Mecoli1219 <[email protected]> * Fix unit-test Signed-off-by: Mecoli1219 <[email protected]> * Fix entrypoint Signed-off-by: Mecoli1219 <[email protected]> * lint Signed-off-by: Kevin Su <[email protected]> * update tracker Signed-off-by: Kevin Su <[email protected]> * Fix I/O on closed file error Signed-off-by: Mecoli1219 <[email protected]> * Update integration test Signed-off-by: Mecoli1219 <[email protected]> * Update integration test Signed-off-by: Mecoli1219 <[email protected]> * Remove unused try & error for event loop Signed-off-by: Mecoli1219 <[email protected]> * Set size limit to pickled file Signed-off-by: Mecoli1219 <[email protected]> * Remove nest_asyncio Signed-off-by: Mecoli1219 <[email protected]> * Remove some args for pyflyte-execute Signed-off-by: Mecoli1219 <[email protected]> * Remove changes to entrypoint Signed-off-by: Mecoli1219 <[email protected]> * Fix map task Signed-off-by: Mecoli1219 <[email protected]> * Remove unnecessary code Signed-off-by: Mecoli1219 <[email protected]> * Remove unnecessary code Signed-off-by: Mecoli1219 <[email protected]> * Add more test Signed-off-by: Mecoli1219 <[email protected]> * fix unit test Signed-off-by: Mecoli1219 <[email protected]> * notebook task resolver Signed-off-by: Kevin Su <[email protected]> * set resolver Signed-off-by: Kevin Su <[email protected]> * Update test Signed-off-by: Mecoli1219 <[email protected]> * Update test Signed-off-by: Mecoli1219 <[email protected]> * Update test Signed-off-by: Mecoli1219 <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Kevin Su <[email protected]> * fix unit test Signed-off-by: Kevin Su <[email protected]> * fix unit test Signed-off-by: Kevin Su <[email protected]> * interactive_mode_enabled=True Signed-off-by: Kevin Su <[email protected]> * display_ipython_warning Signed-off-by: Kevin Su <[email protected]> * nit Signed-off-by: Mecoli1219 <[email protected]> * fix unit test Signed-off-by: Mecoli1219 <[email protected]> * Move pkl.gz to global variable Signed-off-by: Mecoli1219 <[email protected]> * change logging level Signed-off-by: Mecoli1219 <[email protected]> * Fix map task not using notebook resolver Signed-off-by: Mecoli1219 <[email protected]> * Add map task serialization unit test Signed-off-by: Mecoli1219 <[email protected]> * moving some codes & fix map_task problem Signed-off-by: Mecoli1219 <[email protected]> * Fix map task extract pickled task module error Signed-off-by: Mecoli1219 <[email protected]> * wrap the ipython check into a function Signed-off-by: Mecoli1219 <[email protected]> * Fix test Signed-off-by: Thomas J. Fan <[email protected]> * Adds integration test for jupyter Signed-off-by: Thomas J. Fan <[email protected]> * Install kernel before using KernelManager Signed-off-by: Thomas J. Fan <[email protected]> * Add a module scope kernel install Signed-off-by: Thomas J. Fan <[email protected]> --------- Signed-off-by: Ketan Umare <[email protected]> Signed-off-by: Mecoli1219 <[email protected]> Signed-off-by: Kevin Su <[email protected]> Signed-off-by: Thomas J. Fan <[email protected]> Co-authored-by: Ketan Umare <[email protected]> Co-authored-by: Kevin Su <[email protected]> Co-authored-by: Thomas J. Fan <[email protected]>
Tracking issue
flyteorg/flyte#5907
#2579
Original PR: #2618
Why are the changes needed?
Some people may love to develop tasks and workflows in notebooks and run them from the notebook.
Feel free to check out previous Pull Requests. This PR's goal is just to split two functions into separate PRs.
What changes were proposed in this pull request?
Jupyter Notebooks store code in a different format, as a JSON structure, rather than a standard Python script. It is also difficult to locate the code during runtime because Jupyter does not provide direct access to the file path or the exact code location in a standard
__file__
variable. This makes it challenging for Flytekit to extract the task code or module when registering a task, as it relies on standard Python modules or scripts for task registration.Main Idea: Pickle the task function entity during runtime and upload it to a remote location (e.g., S3) when running in a Jupyter Notebook environment.
To implement this, the following modules were modified:
interactive_mode_enabled
field inSerializationSettings
:flytekit/tools/translator.py::get_serializable_task
, the Python task entity is pickled and uploaded to an S3 bucket. TheFastSerializationSettings
inSerializationSettings
is updated to ensure that the remote task can download the entity from S3 before execution.DefaultTaskResolver
class inflyte/core/python_auto_container.py
:interactive_mode_enabled
is set inSerializationSettings
. If so, we add an extrapkl
argument to signal that the resolver should download the task entity from S3 inload_task()
.download_distribution
function inflytekit/tools/fast_registration.py
:pkl.gz
file as a special case that can bypass the distribution format check.Promise
class:Promise
objects inpartial
functions (commonly used in map tasks) can lead to an infinite loop. To address this, I implemented custom__getstate__
and__setstate__
methods to handle the pickling process properly as suggested here.interactive_mode_enabled
property inFlyteRemote
:FlyteRemote
allows it to be specified once during the construction of theFlyteRemote
object. Afterward,FlyteRemote
will handle pickling and uploading tasks during registration.upload_file
function to manage how the Python task entity is uploaded to S3.Map task:
For
map_task
, we will only pickle theactual_task
of themap_task
, and upload the pickled file to the remote environment. However, when initializingArrayNodeMapTask
in the remote, it will try to get thename
of the array node and callextract_task_module
function to determine some information about the task. This will cause errors as the pickled entity is not a Python code, so we couldn't determine the module withinspect.getmodule(f)
in the_task_module_from_callable
function. As the naming process in initializingArrayNodeMapTask
doesn't really need the module name, I'll simply make the function successful if the task is pickled.Nevertheless, I believe we need to have a more determined behavior for extracting information about pickled tasks or tasks from the Jupyter Notebook cells.
TODO
interactive_mode_enabled
=> check pickle & no dest-dirHow was this patch tested?
Setup process
Simple Task & Workflow & map_task:
task:
workflow:
map_task:
Run k8s plugin (pytorch)
Moving the code from flytesnacks/kfpytorch_plugin/pytorch_mnist.py into a Jupyter notebook cell.
Run File Sensor Agent
Follow the link of the doc, and copy the code to the Jupyter Notebook.
Check all the applicable boxes
Related PRs
#2579
#2618
Docs link