Skip to content

Fix for Captum to be served in Colab notebooks#255

Closed
J0Nreynolds wants to merge 1 commit into
meta-pytorch:masterfrom
J0Nreynolds:export-D19590439
Closed

Fix for Captum to be served in Colab notebooks#255
J0Nreynolds wants to merge 1 commit into
meta-pytorch:masterfrom
J0Nreynolds:export-D19590439

Conversation

@J0Nreynolds

Copy link
Copy Markdown
Contributor

Summary:
This change uses TensorBoard's example of Colab serving to support serving Captum Insights in Colab. The main changes are:

  • Display a script in Colab which does the following upon execution
    • Set the base URL to localhost:PORT where PORT is the port that the Insights server is using (this ensures requests are directed properly)
    • Fetch "." and get the HTML response
    • Insert the HTML into the DOM
    • For each script and css file in the HTML, remove and reinsert them in DOM to force them to be loaded.
  • Replace request.json with request.get_json(force=True). This is necessary since Colab doesn't respect Content-Type header when forwarding requests through proxy, and force=True forces the request body to be parsed as JSON

Differential Revision: D19590439

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D19590439

J0Nreynolds added a commit to J0Nreynolds/captum that referenced this pull request Feb 5, 2020
Summary:
Pull Request resolved: meta-pytorch#255

This change uses TensorBoard's example of Colab serving to support serving Captum Insights in Colab. The main changes are:
- Display a script in Colab which does the following upon execution
  - Set the base URL to localhost:PORT where PORT is the port that the Insights server is using (this ensures requests are directed properly)
  - Fetch "." and get the HTML response
  - Insert the HTML into the DOM
  - For each script and css file in the HTML, remove and reinsert them in DOM to force them to be loaded.
- Replace request.json with request.get_json(force=True). This is necessary since Colab doesn't respect Content-Type header when forwarding requests through proxy, and force=True forces the request body to be parsed as JSON

Reviewed By: edward-io

Differential Revision: D19590439

fbshipit-source-id: fc5cad83780db35076071555318abfc5b746b620
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D19590439

@J0Nreynolds

Copy link
Copy Markdown
Contributor Author

All failures are due to linter error:
./captum/insights/api.py:50:9: F401 'google.colab' imported but unused

However, we need to import google.colab in order to test for notebook context. All changes have been retested in Colab, and the widget functions properly.

Comment thread captum/insights/api.py Outdated
# returned by `IPython.get_ipython` does not have a `get_trait`
# method.
try:
import google.colab

@edward-io edward-io Feb 5, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add # noqa: F401 to the end of the import line to silence linter errors.

J0Nreynolds added a commit to J0Nreynolds/captum that referenced this pull request Feb 6, 2020
Summary:
Pull Request resolved: meta-pytorch#255

This change uses TensorBoard's example of Colab serving to support serving Captum Insights in Colab. The main changes are:
- Display a script in Colab which does the following upon execution
  - Set the base URL to localhost:PORT where PORT is the port that the Insights server is using (this ensures requests are directed properly)
  - Fetch "." and get the HTML response
  - Insert the HTML into the DOM
  - For each script and css file in the HTML, remove and reinsert them in DOM to force them to be loaded.
- Replace request.json with request.get_json(force=True). This is necessary since Colab doesn't respect Content-Type header when forwarding requests through proxy, and force=True forces the request body to be parsed as JSON

Reviewed By: edward-io

Differential Revision: D19590439

fbshipit-source-id: 40f4d951256f36390f28bcfa10e0751938054dbc
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D19590439

J0Nreynolds added a commit to J0Nreynolds/captum that referenced this pull request Feb 6, 2020
Summary:
Pull Request resolved: meta-pytorch#255

This change uses TensorBoard's example of Colab serving to support serving Captum Insights in Colab. The main changes are:
- Display a script in Colab which does the following upon execution
  - Set the base URL to localhost:PORT where PORT is the port that the Insights server is using (this ensures requests are directed properly)
  - Fetch "." and get the HTML response
  - Insert the HTML into the DOM
  - For each script and css file in the HTML, remove and reinsert them in DOM to force them to be loaded.
- Replace request.json with request.get_json(force=True). This is necessary since Colab doesn't respect Content-Type header when forwarding requests through proxy, and force=True forces the request body to be parsed as JSON

Reviewed By: edward-io

Differential Revision: D19590439

fbshipit-source-id: 1cbd835e51cd31ea8287335c3234b16f506b719b
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D19590439

Summary:
Pull Request resolved: meta-pytorch#255

This change uses TensorBoard's example of Colab serving to support serving Captum Insights in Colab. The main changes are:
- Display a script in Colab which does the following upon execution
  - Set the base URL to localhost:PORT where PORT is the port that the Insights server is using (this ensures requests are directed properly)
  - Fetch "." and get the HTML response
  - Insert the HTML into the DOM
  - For each script and css file in the HTML, remove and reinsert them in DOM to force them to be loaded.
- Replace request.json with request.get_json(force=True). This is necessary since Colab doesn't respect Content-Type header when forwarding requests through proxy, and force=True forces the request body to be parsed as JSON

Reviewed By: edward-io

Differential Revision: D19590439

fbshipit-source-id: 51893cd6f77aa6fd77f19e70c946cdefe2895f33
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D19590439

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 22cb33b.

NarineK pushed a commit to NarineK/captum-1 that referenced this pull request Nov 19, 2020
Summary:
Pull Request resolved: meta-pytorch#255

This change uses TensorBoard's example of Colab serving to support serving Captum Insights in Colab. The main changes are:
- Display a script in Colab which does the following upon execution
  - Set the base URL to localhost:PORT where PORT is the port that the Insights server is using (this ensures requests are directed properly)
  - Fetch "." and get the HTML response
  - Insert the HTML into the DOM
  - For each script and css file in the HTML, remove and reinsert them in DOM to force them to be loaded.
- Replace request.json with request.get_json(force=True). This is necessary since Colab doesn't respect Content-Type header when forwarding requests through proxy, and force=True forces the request body to be parsed as JSON

Reviewed By: edward-io

Differential Revision: D19590439

fbshipit-source-id: 53d2180321ceb710ac2c06d0859c4913f4d01040
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants