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

profile: disable dashboard inside Colab #1914

Merged
merged 3 commits into from
Feb 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,23 @@

<dom-module id="tf-profile-dashboard">
<template>
<template is="dom-if" if="[[_isNotComplete(progress)]]">
<template is="dom-if" if="[[_isState(_topLevelState, 'IN_COLAB')]]">
<div style="max-width: 540px; margin: 80px auto 0 auto;">
Copy link
Contributor

Choose a reason for hiding this comment

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

:( prefer not to use inline style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is copy-pasted from below…which is indeed a reasonable argument for
making it a class. :-)

<h3>Profiling isn’t supported in Colab yet.</h3>
<p>
Please see
<a href="https://github.com/tensorflow/tensorboard/issues/1913">GitHub issue #1913</a>
for more information.
</p>
</div>
</template>
<template is="dom-if" if="[[_isState(_topLevelState, 'LOADING')]]">
<div id="progress-bar">
<div id="progress-msg">[[progress.msg]]</div>
<paper-progress value="[[progress.value]]"></paper-progress>
</div>
</template>
<template is="dom-if" if="[[_dataNotFound]]">
<template is="dom-if" if="[[_isState(_topLevelState, 'DATA_NOT_FOUND')]]">
<div style="max-width: 540px; margin: 80px auto 0 auto;">
<h3>No profile data was found.</h3>
<p>To collect a profile, you need to run your model on Google Cloud TPUs and
Expand All @@ -73,7 +83,7 @@ <h3>No profile data was found.</h3>
and consider filing an issue on GitHub.</p>
</div>
</template>
<template is="dom-if" if="[[!_dataNotFound]]">
<template is="dom-if" if="[[_isState(_topLevelState, 'ACTIVE')]]">
<tf-dashboard-layout>
<div class="sidebar">
<div class="allcontrols">
Expand Down Expand Up @@ -209,6 +219,35 @@ <h3>No profile data was found.</h3>
<script>
"use strict";

/**
* The main state of the profile dashboard (as distinct from any
* subtool states).
*
* @enum {string}
*/
const TopLevelState = {
/**
* Indicates that we are in a Colab notebook environment. The
* profile dashboard does not work well in Colab; the trace viewer
* does not work at all. If in Colab, we'll show only an explanatory
* message.
*/
"IN_COLAB": "IN_COLAB",
/**
* Indicates that there are no runs with profile data.
*/
"DATA_NOT_FOUND": "DATA_NOT_FOUND",
/**
* Indicates that we're loading data. This may be the case on the
* initial load or when the user switches tools.
*/
"LOADING": "LOADING",
/**
* Indicates that a tool is active (data has finished loading).
*/
"ACTIVE": "ACTIVE",
};

Polymer({
is: "tf-profile-dashboard",
properties: {
Expand All @@ -235,6 +274,17 @@ <h3>No profile data was found.</h3>
type: Array,
observer: '_activeHostsChanged'
},
_inColab: {
type: Boolean,
value: () => !!(window.TENSORBOARD_ENV || {}).IN_COLAB,
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of !!, use Boolean((window.TENSORBOARD_ENV || {}).IN_COLAB) though I understand both with ease.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

http://go/tsstyle explicitly says that !! is okay; jsstyle has no mention.

readOnly: true,
},
/** @type {TopLevelState} */
_topLevelState: {
type: String,
computed: '_computeTopLevelState(_inColab, _dataNotFound, progress)',
readOnly: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know; thanks.

},
/**
* @type {{value: number, msg: string}}
*
Expand Down Expand Up @@ -327,10 +377,6 @@ <h3>No profile data was found.</h3>
detached: function() {
this.set('_isAttached', false);
},
/** True if the progress is not complete yet (< 100 %). */
_isNotComplete: function(progress) {
return !this._dataNotFound && progress.value < 100;
},
_maybeInitializeDashboard: function(isAttached) {
if (this._initialized || !isAttached) {
// Either this dashboard is already initialized ... or we are not yet
Expand Down Expand Up @@ -534,6 +580,24 @@ <h3>No profile data was found.</h3>
// Otherwise, remove the seperator, e.g. "host1_" => "host1".
return host.slice(0, -1);
},
_computeTopLevelState: function(inColab, dataNotFound, progress) {
if (inColab)
return "IN_COLAB";
if (dataNotFound)
return "DATA_NOT_FOUND";
if (!progress || progress.value < 100)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can now remove _isNotComplete() since its logic was inlined here and it's not called anywhere else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point; done.

return "LOADING";
return "ACTIVE";
},
/**
* Check whether the two given states are equal.
*
* @param {TopLevelState} topLevelState
* @param {TopLevelState} candidateState
*/
_isState: function(actualState, candidateState) {
return actualState === candidateState;
},
});

tf_tensorboard.registerDashboard({
Expand Down