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

blog: DVC with Jupyter notebooks #96

Closed
efiop opened this issue Oct 21, 2018 · 20 comments
Closed

blog: DVC with Jupyter notebooks #96

efiop opened this issue Oct 21, 2018 · 20 comments
Labels
A: docs Area: user documentation (gatsby-theme-iterative) C: blog TEMPORARY Content of /blog status: stale You've been groomed!

Comments

@efiop
Copy link
Contributor

efiop commented Oct 21, 2018

No description provided.

@efiop efiop added the A: docs Area: user documentation (gatsby-theme-iterative) label Oct 21, 2018
@efiop
Copy link
Contributor Author

efiop commented Oct 22, 2018

@jurasan

@shcheklein shcheklein added the help wanted Contributors especially welcome label Nov 27, 2018
@colllin
Copy link

colllin commented Jan 9, 2019

If you have any quick tips here, I would appreciate them. I typically use notebooks for development and inline visualization, and I'm trying to migrate a project to dvc right now — my first dvc project 🎉. I'm thinking it might be best to develop and debug in the notebook as usual, then when I'm ready to run the notebook end-to-end, use e.g. dvc run -d train.ipynb -o training.html -o checkpoint.pt jupyter nbconvert --to html --execute train.ipynb.

@efiop
Copy link
Contributor Author

efiop commented Jan 9, 2019

Hi @colllin !

I see by the name of the notebook train.ipynb, that you are splitting your pipeline into separate steps, that you then plan to run using dvc. That is precisely what we usually recommend! You should be all set 🎉 Please don't hesitate to share your experience, we would really appreciate it. 🙂

@mlisovyi
Copy link

mlisovyi commented Mar 9, 2019

Any progress on such example?

@colllin
Copy link

colllin commented Mar 9, 2019

@mlisovyi I’ve been using Jupyter in a pipeline with a command like:

jupyter nbconvert Train.ipynb --clear-output --inplace --execute --ExecutePreprocessor.timeout=-1

This executes the notebook and overwrites it in-place, as if I had opened it in Jupyter and ran the entire notebook manually and saved it. I then commit the resulting notebook to git. I also specify some outputs which are cached: a directory for model checkpoints and a directory for logs. For dependencies, I specify the notebook itself as well as a directory of supporting modules.

I believe the initial command to set it up looked something like

dvc run -d Train.ipynb -d src/ -o checkpoints/ -o logs/ jupyter nbconvert Train.ipynb --clear-output --inplace --execute --ExecutePreprocessor.timeout=-1

You might also need to specify a name for the pipeline step somewhere in that command — I used train.dvc, which I can then execute using dvc repro train.dvc.

@shcheklein shcheklein changed the title docs: add "Jupyter notebook" article to "Use Cases" add "Jupyter notebook" article to "Use Cases" Mar 25, 2019
@shcheklein shcheklein added the type: enhancement Something is not clear, small updates, improvement suggestions label Mar 25, 2019
@dashohoxha dashohoxha mentioned this issue Oct 25, 2019
10 tasks
@shcheklein shcheklein changed the title add "Jupyter notebook" article to "Use Cases" add "Jupyter notebook" article Nov 13, 2019
@jorgeorpinel jorgeorpinel changed the title add "Jupyter notebook" article guide/blog: add "Jupyter notebook" article Sep 27, 2021
@jorgeorpinel
Copy link
Contributor

Do we envision this as a regular part of our DVC user guide, or as a blog post? Cc WDYT @flippedcoder thanks

@jorgeorpinel jorgeorpinel changed the title guide/blog: add "Jupyter notebook" article guide or blog? Add "Jupyter notebook" article Sep 27, 2021
@jorgeorpinel jorgeorpinel changed the title guide or blog? Add "Jupyter notebook" article blog: DVC with Jupyter notebooks Oct 12, 2021
@jorgeorpinel jorgeorpinel added A: docs Area: user documentation (gatsby-theme-iterative) and removed A: docs Area: user documentation (gatsby-theme-iterative) labels Oct 12, 2021
@jorgeorpinel
Copy link
Contributor

Cc WDYT @flippedcoder thanks

Cc @jendefig

Also cc @dberenbaum — I think we discussed this topic at some point. Do you still have your DVC/Jupyter Notebook examples handy? Thanks

@dberenbaum
Copy link
Collaborator

There are a couple different ways to use notebooks with DVC.

The comments above are about running a notebook end-to-end as a DVC stage. I think the examples above give some good ideas about how best to do that.

Another way to integrate DVC and notebooks is to use DVC within the notebook. This could either be running DVC commands, like running experiments/stages from within the notebook, or doing some analysis or otherwise using artifacts or info from an existing DVC project. We plan to work on an experiments API in the future, which will probably be a good point at which to have some notebook examples like this.

@jendefig
Copy link
Contributor

I would think a best practices for migration would be good for the docs and blog post. Showing different ways to do it in a series of blog posts?

@daavoo
Copy link
Contributor

daavoo commented Oct 13, 2021

For me, the ultimate DVC-Jupyter integration (requiring quite some work) would be to provide users with something like custom IPython magic commands in order to generate DVC stuff. Similar to some of the functions that nbdev provides.

This would be in line with the workflow: 1. hacky prototype on notebook -> 2. move to python scripts -> 3. add DVC for reproducibility. These hypothetical DVC magic commands would help to go from 1 to 3 more easily.

For example (roughly speaking and with no details), given a jupyter cell:

EPOCHS = 10

for epoch in range(EPOCHS):
    print(epoch)

User would add the magic commands:

%%dvc stage train

%dvc param
EPOCHS = 10

for epoch in range(EPOCHS):
    print(epoch)

And the commands would generate something like a python script and updating DVC params/stage:

# train.py

if __name__ == "__main__":
    params = yaml.safe_load(params)
    EPOCHS = params["train"]["EPOCHS"]
    
    for epoch in range(EPOCHS):
       print(epoch)
# dvc.yaml
stages:
    train:
        cmd: python train.py params.yaml
        params:
            - train
# params.yaml
train:
    EPOCHS: 10

So user went from a Jupyter cell to being able to run dvc exp run -p train.EPOCHS=20

@iesahin
Copy link
Contributor

iesahin commented Oct 13, 2021

That's a very nice idea @daavoo

I also believe that if there could be some kind of dependency resolution among the Jupyter cells, we could define and run the whole pipeline in a notebook.

%%stage params

EPOCHS=10

and another stage

%%stage train

model.train(epochs=EPOCHS)

Defining a pipeline like,

%%pipeline my-exp

%%depend train param

and running the experiment like

%%exp my-exp

one should be able to mimic most of the pipeline features. Later, it's possible to create DVC-files from these definitions by creating code files, params.yaml, etc.

@dberenbaum
Copy link
Collaborator

Can we move this to https://github.com/iterative/dvc/discussions? We can keep this ticket to document patterns like #96 (comment), but the discussion is now moving towards new feature ideas. Also related to the above suggestions: iterative/dvc#6011.

@jorgeorpinel
Copy link
Contributor

@daavoo @iesahin I agree with @dberenbaum the feature suggestions are great but should be in the core repo please 🙂

Is there a recommendation/decision as to writing docs or a blog based on current features? Thanks

@iesahin iesahin added the C: blog TEMPORARY Content of /blog label Oct 21, 2021
@casperdcl
Copy link
Contributor

casperdcl commented Jan 25, 2022

Strongly would recommend taking a look at https://github.com/nteract/papermill which integrates quite nicely with DVC :)

Essentially substitute python script.py with papermill notebook.ipynb. There are also lots of ways to play around with params, deps & outputs.

@jorgeorpinel jorgeorpinel added status: stale You've been groomed! and removed type: enhancement Something is not clear, small updates, improvement suggestions help wanted Contributors especially welcome labels Aug 4, 2022
@jorgeorpinel
Copy link
Contributor

jorgeorpinel commented Aug 4, 2022

Ping @jendefig 🙂 (I think you were looking for ideas, well this is the oldest open ticket one in this repo)

@jendefig
Copy link
Contributor

jendefig commented Aug 8, 2022

@jorge Thanks! @flippedcoder is finishing up one on this now here. Not sure she is familiar with Papermill @casperdcl. With what you know could you take a look and see if there are any significant advantages over the approach being used now?

@casperdcl
Copy link
Contributor

done

@jorgeorpinel
Copy link
Contributor

Does https://iterative.ai/blog/jupyter-notebook-dvc-pipeline close this? WDYT @dberenbaum @jendefig

Cc @RCdeWit is there an issue for the planned blog follow-up? (Getting to an actual pipeline)

Thanks

@jendefig
Copy link
Contributor

jendefig commented Nov 4, 2022

Does https://iterative.ai/blog/jupyter-notebook-dvc-pipeline close this? WDYT @dberenbaum @jendefig

Cc @RCdeWit is there an issue for the planned blog follow-up? (Getting to an actual pipeline)

Thanks

@jorgeorpinel I would think that until the follow-up one to the papermill one is done this isn't quite closed. But plans for the next one are already in our backlog, so it won't be lost.

@shcheklein
Copy link
Member

I think we can close this for now. No need to track it here as a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: docs Area: user documentation (gatsby-theme-iterative) C: blog TEMPORARY Content of /blog status: stale You've been groomed!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants