-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Allow Jupyter+TensorBoard to work w/ hostname other than localhost #2407
Allow Jupyter+TensorBoard to work w/ hostname other than localhost #2407
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @cliffwoolley—thanks for this PR! The high-level plan of using the
enclosing hostname seems reasonable to me. Requested some changes to the
implementation; see inline.
Signed-off-by: Cliff Woolley <[email protected]>
ccc6776
to
462bd9f
Compare
Hi @wchargin ; anything further you'd like me to change for this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies for the delay; it wasn’t possible for me to test this until
this week (for entirely unrelated reasons). I’ll test it and approve and
merge if everything looks good. In the meantime, just a few nits. :-)
thank you for your patience!
tensorboard/notebook.py
Outdated
height=height, | ||
width="100%", | ||
) | ||
import cgi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please pull these imports to the top of the file. (We late-import
IPython
so that this module can be imported in environments that don’t
have IPython, but these three modules are part of the standard library.)
tensorboard/notebook.py
Outdated
|
||
frame_id = "tensorboard-frame-{:08x}".format(random.randrange(0, 1 << 64)) | ||
shell = """ | ||
<iframe id="%HTML_ID%" width="100%" height="%HEIGHT%" frameborder="0"></iframe> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Please break a line before </iframe>
to stay within 80 columns.
tensorboard/notebook.py
Outdated
</script> | ||
""" | ||
replacements = [ | ||
("%HTML_ID%", cgi.escape(frame_id, quote=True)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: +2 spaces of indentation for continuations, please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tensorboard/notebook.py
Outdated
import json | ||
import random | ||
|
||
frame_id = "tensorboard-frame-{:08x}".format(random.randrange(0, 1 << 64)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: random.randrange(0, 1 << 64)
can be random.getrandbits(64)
,
which is a bit clearer (in particular about the boundary condition).
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
@googlebot I consent. |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
I’ve gone ahead and fixed the nits for you, since they were all trivial. |
@cliffwoolley: Thanks again for the contribution! |
Thanks for taking care of those last nits! |
Motivation for features / changes
Fixes %tensorboard magic: host other than localhost #1956 to allow the combination of Jupyter+TensorBoard to work when the browser is running on a system other than TensorBoard's localhost .
Technical description of changes
Rather than
localhost
being hardcoded, we use a short JavaScript snippet in the IFrame source to have the client determine for itself the hostname that should be contacted. This allows the solution also to work from inside a container, where we might not know the host's outward-facing IP address.Test Plan:
Install Docker and
nvidia-docker
, then runto get a Docker shell. Inside the container, run
and navigate to the provided notebook URL via a hostname other than
localhost
(e.g., your machine’shostname
). Create a new IPythonnotebook and execute the cell
and verify that the output contains a working TensorBoard iframe whose
src
attribute is under the main frame’s origin (e.g., your machine’shostname
), notlocalhost
.