-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
notebook: add experimental Jupyter integration #1813
Conversation
2825bc3
to
98c5d04
Compare
cda9875
to
dde9c6d
Compare
dde9c6d
to
cc3adb6
Compare
Summary: This commit adds a module `tensorboard.notebook` that can be loaded as a Jupyter extension, providing the `%tensorboard` cell magic to launch and display TensorBoard instances within a notebook. This code doesn’t have to be perfect right now; one main goal for this PR is to sync the structure of this code into google3, where it’s easier to work on and test Colab integration. The UI looks like this: ![Screenshot of a `%tensorboard` command in the Jupyter UI.][1] [1]: https://user-images.githubusercontent.com/4317806/52386325-7ae7eb80-2a3a-11e9-93ab-fc9a689de51c.png Test Plan: Currently, this requires a bit of path hackery to get working: 1. Run `bazel build //tensorboard` to build the main binary. 2. Run `which tensorboard` to find the `tensorboard` binary provided by your virtualenv, and hit it with `chmod -x` to make it not executable. 3. Run `export PATH="$(readlink -e ./bazel-bin/tensorboard):$PATH"` to add it to your path, and confirm that `which tensorboard` points to the built version rather than the version in your virtualenv. 4. Run `jupyter notebook` to start the Jupyter server. 5. Create a notebook and execute `%load_ext tensorboard.notebook` to load the extension; henceforth, `%tensorboard` should work until you restart the Jupyter kernel. (Step (2) is necessary because the `jupyter notebook` runtime adds the virtualenv _back_ to the front of your `PATH`. An alternative is to patch `os.environ["PATH"]` from within the Jupyter notebook.) After setting it up as above, the following makes a good test plan (assuming that you have no other TensorBoard instances running): - `%tensorboard --logdir ~/tb/mnist --port 6006` (should launch) - `%tensorboard --logdir ~/tb/mnist --port 6006` (should reuse) - `%tensorboard --logdir ~/tb/images_demo --port 6006` (should fail) - `%tensorboard --logdir ~/tb/images_demo --port 6007` (should launch) - `%tensorboard --logdir ~/tb/mnist --port 6006` (should reuse #1) - multiple `%tensorboard`s in a single cell: ```py for i in ("images_demo", "audio_demo"): %tensorboard --logdir ~/tb/$i --port 0 ``` - `from tensorboard import notebook` - `notebook.list()` (should list four instances) - `notebook.display(port=6006)` - `notebook.display(height=800)` Finally, if you skip (or revert) step (2) from the setup instructions, you can see the timeout behavior, because we’ll invoke the `tensorboard` provided by PyPI, which does not yet know how to write TensorboardInfo. wchargin-branch: notebook-jupyter
cc3adb6
to
26b973f
Compare
Updated; PTAL. |
Using def display_pid(pid, height=None):
"""Display the TensorBoard instance owned by the given process."""
port = look_up_port_by_pid(pid)
display(port, height=height) …but if def display_pid(pid, height=600):
# ...
display(port, height=height) (which is unfortunate if def display_pid(pid, *args, **kwargs):
port = look_up_port_by_pid(pid)
display(port, *args, **kwargs) …which is not what was wanted and has other downsides. The * It is technically possible to fetch the default value at runtime by |
I merged this via “Squash and merge”, but the GitHub machine broke and |
Summary: This commit adds a module `tensorboard.notebook` that can be loaded as a Jupyter extension, providing the `%tensorboard` cell magic to launch and display TensorBoard instances within a notebook. This code doesn’t have to be perfect right now; one main goal for this PR is to sync the structure of this code into google3, where it’s easier to work on and test Colab integration. The UI looks like this: ![Screenshot of a `%tensorboard` command in the Jupyter UI.][1] [1]: https://user-images.githubusercontent.com/4317806/52386325-7ae7eb80-2a3a-11e9-93ab-fc9a689de51c.png Test Plan: Currently, this requires a bit of path hackery to get working: 1. Run `bazel build //tensorboard` to build the main binary. 2. Run `which tensorboard` to find the `tensorboard` binary provided by your virtualenv, and hit it with `chmod -x` to make it not executable. 3. Run `export PATH="$(readlink -e ./bazel-bin/tensorboard):$PATH"` to add it to your path, and confirm that `which tensorboard` points to the built version rather than the version in your virtualenv. 4. Run `jupyter notebook` to start the Jupyter server. 5. Create a notebook and execute `%load_ext tensorboard.notebook` to load the extension; henceforth, `%tensorboard` should work until you restart the Jupyter kernel. (Step (2) is necessary because the `jupyter notebook` runtime adds the virtualenv _back_ to the front of your `PATH`. An alternative is to patch `os.environ["PATH"]` from within the Jupyter notebook.) After setting it up as above, the following makes a good test plan (assuming that you have no other TensorBoard instances running): - `%tensorboard --logdir ~/tb/mnist --port 6006` (should launch) - `%tensorboard --logdir ~/tb/mnist --port 6006` (should reuse) - `%tensorboard --logdir ~/tb/images_demo --port 6006` (should fail) - `%tensorboard --logdir ~/tb/images_demo --port 6007` (should launch) - `%tensorboard --logdir ~/tb/mnist --port 6006` (should reuse #1) - multiple `%tensorboard`s in a single cell: ```py for i in ("images_demo", "audio_demo"): %tensorboard --logdir ~/tb/$i --port 0 ``` - `from tensorboard import notebook` - `notebook.list()` (should list four instances) - `notebook.display(port=6006)` - `notebook.display(height=800)` Finally, if you skip (or revert) step (2) from the setup instructions, you can see the timeout behavior, because we’ll invoke the `tensorboard` provided by PyPI, which does not yet know how to write TensorboardInfo. wchargin-branch: notebook-jupyter
Summary:
This commit adds a module
tensorboard.notebook
that can be loaded as aJupyter extension, providing the
%tensorboard
cell magic to launch anddisplay TensorBoard instances within a notebook.
This code doesn’t have to be perfect right now; one main goal for this
PR is to sync the structure of this code into google3, where it’s easier
to work on and test Colab integration.
The UI looks like this:
Test Plan:
Currently, this requires a bit of path hackery to get working:
bazel build //tensorboard
to build the main binary.which tensorboard
to find thetensorboard
binary provided byyour virtualenv, and hit it with
chmod -x
to make it notexecutable.
export PATH="$(readlink -e ./bazel-bin/tensorboard):$PATH"
toadd it to your path, and confirm that
which tensorboard
points tothe built version rather than the version in your virtualenv.
jupyter notebook
to start the Jupyter server.%load_ext tensorboard.notebook
toload the extension; henceforth,
%tensorboard
should work until yourestart the Jupyter kernel.
(Step (2) is necessary because the
jupyter notebook
runtime adds thevirtualenv back to the front of your
PATH
. An alternative is topatch
os.environ["PATH"]
from within the Jupyter notebook.)After setting it up as above, the following makes a good test plan
(assuming that you have no other TensorBoard instances running):
%tensorboard --logdir ~/tb/mnist --port 6006
(should launch)%tensorboard --logdir ~/tb/mnist --port 6006
(should reuse)%tensorboard --logdir ~/tb/images_demo --port 6006
(should fail)%tensorboard --logdir ~/tb/images_demo --port 6007
(should launch)%tensorboard --logdir ~/tb/mnist --port 6006
(should reuse Get bazel build tensorboard/components/... to work. #1)multiple
%tensorboard
s in a single cell:from tensorboard import notebook
notebook.list()
(should list four instances)notebook.display(port=6006)
notebook.display(height=800)
Finally, if you skip (or revert) step (2) from the setup instructions,
you can see the timeout behavior, because we’ll invoke the
tensorboard
provided by PyPI, which does not yet know how to write TensorboardInfo.
wchargin-branch: notebook-jupyter