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

[Docs] Add Google Colab support to tutorials #10706

Closed
guberti opened this issue Mar 22, 2022 · 8 comments
Closed

[Docs] Add Google Colab support to tutorials #10706

guberti opened this issue Mar 22, 2022 · 8 comments

Comments

@guberti
Copy link
Member

guberti commented Mar 22, 2022

Add "Open in Google Colab" button to .ipynb tutorials

On Tensorflow's doc sites, each interactive tutorial has a one-click open to open it on Google Colab - Google's interactive web editor for Python notebooks. See this example for post training integer quantization (screenshot below).
image

I'm currently messing around with some microTVM tutorials, so I'll see if I can get a demo of this running there. "Open in Colab" is one of my favorite things about the Tensorflow and Keras docs, and I'd love to integrate the feature here too.

Additions/Changes Requested

While the buttons look fancy, each is just a URL underneath. The "view source on Github" link is just a hardcoded URL to the Github repo - nothing fancy. For the open in Colab button, we just take that same hardcoded URL, but prepend "colab.research.google.com" and Colab takes care of the rest. Here's the link that powers the button above:

https://colab.research.google.com/github/tensorflow/tensorflow/blob/master/tensorflow/lite/g3doc/performance/post_training_integer_quant.ipynb

@Wheest
Copy link
Contributor

Wheest commented Mar 23, 2022

For this to be effective, perhaps it would be good to have a pre-build Colab binary of TVM than can be wget'd into the notebook's VM?

Otherwise the notebook would always need to begin with the user downloading and building TVM from scratch.

@guberti
Copy link
Member Author

guberti commented Mar 23, 2022

As of December this year, we had a pip installable version, and I was able to get TVM building in Google Colab notebooks - I used it for my TVMCon talk. It's not quite a full-featured version, but you can still do interesting things with it.

@Wheest
Copy link
Contributor

Wheest commented Mar 23, 2022

That's great, I must have missed that talk. Do you have a link for it?

Is this the TLCPack mentioned in the current docs, or some other system?

@guberti
Copy link
Member Author

guberti commented Mar 23, 2022

Yep, it's TLCPack - you just have to run:

pip install tlcpack-nightly -f https://tlcpack.ai/wheels

You can see the talk here - I use a Python notebook to compile a model for Arduino. I'm currently working on adapting a version of that notebook to be included with the docs (working on and off - I'm in school right now) but that's my motivation for this feature/

@guberti guberti changed the title [Docs] Add Google Colab support to .ipynb tutorials [Docs] Add Google Colab support to tutorials Mar 24, 2022
@mehrdadh
Copy link
Member

@guberti we are in the process of adding TVM pip release. So we should be able to use pip install apache-tvm sometimes in near future.

@guberti
Copy link
Member Author

guberti commented Apr 13, 2022

Over the last two weeks, I've spent some cycles trying to understand how this would work. On the surface, it is simple enough - just add a link to the TVM site repo. For example, clicking on this URL will open the micro_tflite tutorial in Colab, which can be done without modifying the code at all:

https://colab.research.google.com/github/apache/tvm-site/blob/asf-site/docs/_downloads/5b279d8a8718816263fa65b0eef1a5c0/micro_tflite.ipynb

However, if you try messing around with that .ipynb notebook, you will find it does not work. This is for two reasons - (a), the Bash blocks (which install dependencies) are not runnable, and (b) code often needs slight tweaks to run as a Python notebook. These issues are not unique to Google Colab at all - very few of the .ipynb files you can download from the documentation website actually work.

At some point, we ought to have a discussion about whether sphinx-gallery is the right tool for our documentation. However, that's a separate issue, so I did some work and made two pull requests to sphinx-gallery to fix the two issues mentioned above:

Once these pull requests get merged, then if we choose to update our sphinx-gallery version, we will be able to generate .ipynb files that actually work as intended. This will also allow us to have a "open in Google Colab" button.

@guberti
Copy link
Member Author

guberti commented Apr 15, 2022

I have a prototype of this working! See #10921, though it still requires those changes to Sphinx Gallery mentioned above. You can also check out the HTML tutorial at:
https://guberti.github.io/tvm-docs-proof-of-concept/
Currently, some parts of this are a little hacky, but improving them is my next step. However, I'm going to hold off on making any more changes until the sphinx-gallery PRs are merged or rejected, as how useful the "Open in Colab" stuff is depends on whether those are merged.

@guberti
Copy link
Member Author

guberti commented Jun 17, 2022

This feature is now working on production! See https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_train.html. Hopefully having a working example makes it easier for other tutorial writers to also add Colab support.

@guberti guberti closed this as completed Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants