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

Add a toggle that turns automatic high-degree node extraction off #4722

Merged
merged 21 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions tensorboard/plugins/graph/tf_graph/tf-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class TfGraph extends LegacyElementMixin(PolymerElement) {
renderHierarchy: tf_graph_render.RenderGraphInfo;
@property({type: Boolean})
traceInputs: boolean;
@property({type: Boolean})
autoExtractNodes: boolean;
@property({type: Array})
nodeContextMenuItems: unknown[];
@property({
Expand Down Expand Up @@ -172,6 +174,15 @@ class TfGraph extends LegacyElementMixin(PolymerElement) {
panToNode(nodeName) {
(this.$$('tf-graph-scene') as any).panToNode(nodeName);
}
@observe('autoExtractNodes')
_autoExtractNodesChanged() {
var graphHierarchy = this.graphHierarchy;
if (!graphHierarchy) return;
for (const node of Object.values(graphHierarchy.getNodeMap())) {
node.include = tf_graph.InclusionType.UNSPECIFIED;
}
this._buildRenderHierarchy(graphHierarchy);
}
@observe(
'graphHierarchy',
'edgeWidthFunction',
Expand Down Expand Up @@ -264,9 +275,10 @@ class TfGraph extends LegacyElementMixin(PolymerElement) {
const renderGraph = tf_graph_util.time(
'new tf_graph_render.Hierarchy',
() => {
var renderGraph = new tf_graph_render.RenderGraphInfo(
const renderGraph = new tf_graph_render.RenderGraphInfo(
graphHierarchy,
!!this.stats /** displayingStats */
!!this.stats /** displayingStats */,
this.autoExtractNodes
);
renderGraph.edgeLabelFunction = this.edgeLabelFunction;
renderGraph.edgeWidthFunction = this.edgeWidthFunction;
Expand Down
4 changes: 4 additions & 0 deletions tensorboard/plugins/graph/tf_graph_app/tf-graph-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class TfGraphApp extends LegacyElementMixin(PolymerElement) {
selected-file="{{selectedFile}}"
on-fit-tap="_fit"
trace-inputs="{{_traceInputs}}"
auto-extract-nodes="{{_autoExtractNodes}}"
></tf-graph-controls>
<tf-graph-loader
id="loader"
Expand All @@ -117,6 +118,7 @@ class TfGraphApp extends LegacyElementMixin(PolymerElement) {
render-hierarchy="{{_renderHierarchy}}"
selected-node="{{selectedNode}}"
trace-inputs="[[_traceInputs]]"
autoExtractNodes="[[_autoExtractNodes]]"
></tf-graph-board>
</div>
</div>
Expand Down Expand Up @@ -164,6 +166,8 @@ class TfGraphApp extends LegacyElementMixin(PolymerElement) {
_progress: object;
@property({type: Boolean})
_traceInputs: boolean;
@property({type: Boolean})
_autoExtractNodes: boolean;
_updateToolbar() {
(this.$$('.container') as HTMLElement).classList.toggle(
'no-toolbar',
Expand Down
3 changes: 3 additions & 0 deletions tensorboard/plugins/graph/tf_graph_board/tf-graph-board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class TfGraphBoard extends LegacyElementMixin(PolymerElement) {
handle-node-selected="[[handleNodeSelected]]"
handle-edge-selected="[[handleEdgeSelected]]"
trace-inputs="[[traceInputs]]"
auto-extract-nodes="[[autoExtractNodes]]"
></tf-graph>
</div>
<div id="info">
Expand Down Expand Up @@ -196,6 +197,8 @@ class TfGraphBoard extends LegacyElementMixin(PolymerElement) {
progress: object;
@property({type: Boolean})
traceInputs: boolean;
@property({type: Boolean})
autoExtractNodes: boolean;
@property({type: String})
colorBy: string;
@property({
Expand Down
36 changes: 23 additions & 13 deletions tensorboard/plugins/graph/tf_graph_common/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ export interface EdgeLabelFunction {
* Parameters that affect how the graph is rendered on the screen.
*/
const PARAMS = {
/**
* Whether to extract high degree nodes from the core part of the graph.
*/
enableExtraction: true,
/**
* The minimum number of nodes for a graph to have in order for high in and
* out degree nodes to be extracted in auxiliary. The aim here is to prevent
Expand Down Expand Up @@ -233,14 +229,20 @@ export class RenderGraphInfo {
[nodeName: string]: boolean;
};
root: RenderGroupNodeInfo;
traceInputs: Boolean;
traceInputs: boolean;
private autoExtractNodes: boolean;
edgeLabelFunction: EdgeLabelFunction;
// An optional function that computes the thickness of an edge given edge
// data. If not provided, defaults to encoding tensor size in thickness.
edgeWidthFunction: EdgeThicknessFunction;
constructor(hierarchy: tf_graph.Hierarchy, displayingStats: boolean) {
constructor(
hierarchy: tf_graph.Hierarchy,
displayingStats: boolean,
autoExtractNodes: boolean
) {
this.hierarchy = hierarchy;
this.displayingStats = displayingStats;
this.autoExtractNodes = autoExtractNodes;
this.index = {};
this.renderedOpNames = [];
this.computeScales();
Expand Down Expand Up @@ -942,11 +944,8 @@ export class RenderGraphInfo {
this.index[edgeObj.v].isFadedOut || this.index[edgeObj.w].isFadedOut;
coreGraph.setEdge(edgeObj.v, edgeObj.w, renderMetaedgeInfo);
});
if (
PARAMS.enableExtraction &&
renderGroupNodeInfo.node.type === NodeType.META
) {
extractHighDegrees(renderGroupNodeInfo);
if (renderGroupNodeInfo.node.type === NodeType.META) {
extractHighDegrees(renderGroupNodeInfo, this.autoExtractNodes);
}
// If there are functions, it is possible for metanodes to be dynamically
// added later. Construct the hierarchies for nodes that are predecessors to
Expand Down Expand Up @@ -2182,18 +2181,29 @@ export function mapIndexToHue(id: number): number {
* screw up the graph layout.
*
* @param {Render.Node} renderNode Node to manipulate.
* @param {boolean} autoExtractNodes Whether to automatically exclude high-degree
* nodes from the main graph. If false, only exclude predefined nodes.
*/
function extractHighDegrees(renderNode: RenderGroupNodeInfo) {
function extractHighDegrees(
renderNode: RenderGroupNodeInfo,
autoExtractNodes: boolean
) {
extractSpecifiedNodes(renderNode);

if (PARAMS.outExtractTypes.length) {
extractPredefinedSink(renderNode);
}

// This has to come before extract high in-degree to protect the core part
// that takes many variables.
if (PARAMS.inExtractTypes.length) {
extractPredefinedSource(renderNode);
}
extractHighInOrOutDegree(renderNode);

if (autoExtractNodes) {
extractHighInOrOutDegree(renderNode);
}

if (PARAMS.maxControlDegree) {
removeControlEdges(renderNode);
}
Expand Down
12 changes: 12 additions & 0 deletions tensorboard/plugins/graph/tf_graph_controls/tf-graph-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,13 @@ class TfGraphControls extends LegacyElementMixin(PolymerElement) {
</paper-toggle-button>
</div>
</div>
<div class="control-holder">
<div>
<paper-toggle-button checked="{{autoExtractNodes}}" class="title">
Auto-extract high-degree nodes
</paper-toggle-button>
</div>
</div>
<template is="dom-if" if="[[healthPillsFeatureEnabled]]">
<div class="control-holder">
<paper-toggle-button checked="{{healthPillsToggledOn}}" class="title"
Expand Down Expand Up @@ -1079,6 +1086,11 @@ class TfGraphControls extends LegacyElementMixin(PolymerElement) {
notify: true,
})
traceInputs: boolean = false;
@property({
type: Boolean,
notify: true,
})
autoExtractNodes: boolean = true;
@property({
type: Number,
observer: '_selectedTagIndexChanged',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class TfGraphDashboard extends LegacyElementMixin(PolymerElement) {
health-pills-toggled-on="{{healthPillsToggledOn}}"
on-fit-tap="_fit"
trace-inputs="{{_traceInputs}}"
auto-extract-nodes="{{_autoExtractNodes}}"
></tf-graph-controls>
<div
class$="center [[_getGraphDisplayClassName(_selectedFile, _datasets)]]"
Expand Down Expand Up @@ -160,6 +161,7 @@ class TfGraphDashboard extends LegacyElementMixin(PolymerElement) {
selected-node="{{_selectedNode}}"
stats="[[_stats]]"
trace-inputs="[[_traceInputs]]"
auto-extract-nodes="[[_autoExtractNodes]]"
></tf-graph-board>
</div>
</div>
Expand Down Expand Up @@ -304,6 +306,8 @@ class TfGraphDashboard extends LegacyElementMixin(PolymerElement) {
_compatibilityProvider: object;
@property({type: Boolean})
_traceInputs: boolean;
@property({type: Boolean})
_autoExtractNodes: boolean;
@property({type: Object})
_selectedFile: any;
attached() {
Expand Down