Skip to content

Commit a04067e

Browse files
committed
profile: disable dashboard inside Colab (tensorflow#1914)
Summary: The profile dashboard now shows a “disabled” message on the frontend when we detect that we’re running in a Colab notebook. See tensorflow#1913. This commit does _not_ cause the profile dashboard to be marked inactive by the main TensorBoard UI. We might want to do that, but it’s less straightforward: currently, the backend is responsible for telling the frontend which plugins are active, and the backend can’t know whether we’re running in Colab. As a quick hack, we could add special-case logic in `tf-tensorboard.html` to check for the profile plugin specifically. As a longer-term solution, we could let the `tf_tensorboard.Dashboard` interface specify an `isActive` callback, defaulting to `() => true`. ![Screenshot of the “Profiling isn’t yet supported in Colab” message][s] [s]: https://user-images.githubusercontent.com/4317806/53541886-b83b1880-3ad0-11e9-9501-299f5e671d7a.png The implementation includes a small refactor to the profile dashboard to make it easier to introduce a new state. Test Plan: Evaluate `!!(window.TENSORBOARD_ENV || {}).IN_COLAB` in both standalone TensorBoard and Colab `%tensorboard`, and note that each evaluates to the appropriate boolean. Run TensorBoard locally with the profile plugin’s demo data, and note that its behavior is unchanged. To trigger the loading state, it suffices to load the dashboard, then throttle your network to “Slow 3G”, then change the selected tool. To trigger the “no data” state, relaunch TensorBoard pointing at a different log directory. Then, test the Colab behavior by either pointing TensorBoard at a log directory that does not contain profile data, then executing ```js window.TENSORBOARD_ENV = window.TENSORBOARD_ENV || {}; window.TENSORBOARD_ENV["IN_COLAB"] = true; ``` in the main TensorBoard pane before switching to the inactive profile dashboard. Note that this is the same setup JavaScript as is injected into the Colab output frame by `notebook.py`. wchargin-branch: profile-disable-colab
1 parent 86ef13d commit a04067e

File tree

1 file changed

+71
-7
lines changed

1 file changed

+71
-7
lines changed

tensorboard/plugins/profile/tf_profile_dashboard/tf-profile-dashboard.html

+71-7
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,23 @@
4343

4444
<dom-module id="tf-profile-dashboard">
4545
<template>
46-
<template is="dom-if" if="[[_isNotComplete(progress)]]">
46+
<template is="dom-if" if="[[_isState(_topLevelState, 'IN_COLAB')]]">
47+
<div style="max-width: 540px; margin: 80px auto 0 auto;">
48+
<h3>Profiling isn’t supported in Colab yet.</h3>
49+
<p>
50+
Please see
51+
<a href="https://github.com/tensorflow/tensorboard/issues/1913">GitHub issue #1913</a>
52+
for more information.
53+
</p>
54+
</div>
55+
</template>
56+
<template is="dom-if" if="[[_isState(_topLevelState, 'LOADING')]]">
4757
<div id="progress-bar">
4858
<div id="progress-msg">[[progress.msg]]</div>
4959
<paper-progress value="[[progress.value]]"></paper-progress>
5060
</div>
5161
</template>
52-
<template is="dom-if" if="[[_dataNotFound]]">
62+
<template is="dom-if" if="[[_isState(_topLevelState, 'DATA_NOT_FOUND')]]">
5363
<div style="max-width: 540px; margin: 80px auto 0 auto;">
5464
<h3>No profile data was found.</h3>
5565
<p>To collect a profile, you need to run your model on Google Cloud TPUs and
@@ -73,7 +83,7 @@ <h3>No profile data was found.</h3>
7383
and consider filing an issue on GitHub.</p>
7484
</div>
7585
</template>
76-
<template is="dom-if" if="[[!_dataNotFound]]">
86+
<template is="dom-if" if="[[_isState(_topLevelState, 'ACTIVE')]]">
7787
<tf-dashboard-layout>
7888
<div class="sidebar">
7989
<div class="allcontrols">
@@ -209,6 +219,35 @@ <h3>No profile data was found.</h3>
209219
<script>
210220
"use strict";
211221

222+
/**
223+
* The main state of the profile dashboard (as distinct from any
224+
* subtool states).
225+
*
226+
* @enum {string}
227+
*/
228+
const TopLevelState = {
229+
/**
230+
* Indicates that we are in a Colab notebook environment. The
231+
* profile dashboard does not work well in Colab; the trace viewer
232+
* does not work at all. If in Colab, we'll show only an explanatory
233+
* message.
234+
*/
235+
"IN_COLAB": "IN_COLAB",
236+
/**
237+
* Indicates that there are no runs with profile data.
238+
*/
239+
"DATA_NOT_FOUND": "DATA_NOT_FOUND",
240+
/**
241+
* Indicates that we're loading data. This may be the case on the
242+
* initial load or when the user switches tools.
243+
*/
244+
"LOADING": "LOADING",
245+
/**
246+
* Indicates that a tool is active (data has finished loading).
247+
*/
248+
"ACTIVE": "ACTIVE",
249+
};
250+
212251
Polymer({
213252
is: "tf-profile-dashboard",
214253
properties: {
@@ -235,6 +274,17 @@ <h3>No profile data was found.</h3>
235274
type: Array,
236275
observer: '_activeHostsChanged'
237276
},
277+
_inColab: {
278+
type: Boolean,
279+
value: () => !!(window.TENSORBOARD_ENV || {}).IN_COLAB,
280+
readOnly: true,
281+
},
282+
/** @type {TopLevelState} */
283+
_topLevelState: {
284+
type: String,
285+
computed: '_computeTopLevelState(_inColab, _dataNotFound, progress)',
286+
readOnly: true,
287+
},
238288
/**
239289
* @type {{value: number, msg: string}}
240290
*
@@ -327,10 +377,6 @@ <h3>No profile data was found.</h3>
327377
detached: function() {
328378
this.set('_isAttached', false);
329379
},
330-
/** True if the progress is not complete yet (< 100 %). */
331-
_isNotComplete: function(progress) {
332-
return !this._dataNotFound && progress.value < 100;
333-
},
334380
_maybeInitializeDashboard: function(isAttached) {
335381
if (this._initialized || !isAttached) {
336382
// Either this dashboard is already initialized ... or we are not yet
@@ -534,6 +580,24 @@ <h3>No profile data was found.</h3>
534580
// Otherwise, remove the seperator, e.g. "host1_" => "host1".
535581
return host.slice(0, -1);
536582
},
583+
_computeTopLevelState: function(inColab, dataNotFound, progress) {
584+
if (inColab)
585+
return "IN_COLAB";
586+
if (dataNotFound)
587+
return "DATA_NOT_FOUND";
588+
if (!progress || progress.value < 100)
589+
return "LOADING";
590+
return "ACTIVE";
591+
},
592+
/**
593+
* Check whether the two given states are equal.
594+
*
595+
* @param {TopLevelState} topLevelState
596+
* @param {TopLevelState} candidateState
597+
*/
598+
_isState: function(actualState, candidateState) {
599+
return actualState === candidateState;
600+
},
537601
});
538602

539603
tf_tensorboard.registerDashboard({

0 commit comments

Comments
 (0)