Skip to content

Commit

Permalink
Internal changes
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 713786152
  • Loading branch information
Google AI Edge authored and copybara-github committed Jan 9, 2025
1 parent efd140f commit 410bcb0
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/ui/src/components/home_page/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ export class HomePage implements AfterViewInit {
),
enableSubgraphSelection: this.urlService.enableSubgraphSelection,
enableExportToResource: this.urlService.enableExportToResource,
enableExcludeFromQuantization:
this.urlService.enableExcludeFromQuantization,
keepLayersWithASingleChild: this.settingsService.getBooleanValue(
SETTING_KEEP_LAYERS_WITH_A_SINGLE_CHILD,
),
Expand Down
4 changes: 4 additions & 0 deletions src/ui/src/components/visualizer/common/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,9 @@ export const EXTERNAL_LOCAL_DEV_PORT = 8081;
/** The command to export to resource. */
export const EXPORT_TO_RESOURCE_CMD = 'model-explorer-export-to-resource';

/** The command to exclude from quantization. */
export const EXCLUDE_FROM_QUANTIZATION_CMD =
'model-explorer-exclude-from-quantization';

/** The line height of node label. */
export const NODE_LABEL_LINE_HEIGHT = 14;
3 changes: 3 additions & 0 deletions src/ui/src/components/visualizer/common/visualizer_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export declare interface VisualizerConfig {
/** Whether to enable export to resource. */
enableExportToResource?: boolean;

/** Whether to enable exclude from quantization. */
enableExcludeFromQuantization?: boolean;

/** Whether to keep layers with a single child. */
keepLayersWithASingleChild?: boolean;

Expand Down
6 changes: 6 additions & 0 deletions src/ui/src/components/visualizer/selection_panel.ng.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
Export to resource
</button>
}
@if (enableExcludeFromQuantization) {
<button mat-flat-button color="primary" (click)="handleClickExcludeFromQuantization()">
<mat-icon>block</mat-icon>
Exclude from quantization
</button>
}
</div>
</div>
}
23 changes: 22 additions & 1 deletion src/ui/src/components/visualizer/selection_panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import {MatIconModule} from '@angular/material/icon';
import {setAnchorHref} from 'safevalues/dom';

import {AppService} from './app_service';
import {EXCLUDE_FROM_QUANTIZATION_CMD} from './common/consts';
import {exportToResource} from './common/utils';
import {SubgraphSelectionService} from './subgraph_selection_service';

/** A component to handle drag events. */
/** A component to show actions for selected nodes. */
@Component({
standalone: true,
selector: 'selection-panel',
Expand Down Expand Up @@ -88,7 +89,27 @@ export class SelectionPanel {
]);
}

handleClickExcludeFromQuantization() {
// Send the selected nodes and the model graph info to the parent window
// through postMessage.
const selectedNodes = this.subgraphSelectionService.selectedNodes();
const modelGraph = this.appService.getModelGraphFromPane(this.paneId);
window.parent.postMessage(
{
'cmd': EXCLUDE_FROM_QUANTIZATION_CMD,
'nodes': selectedNodes,
'graph_collection_label': modelGraph?.collectionLabel ?? '',
'graph_id': modelGraph?.id ?? '',
},
'*',
);
}

get enableExportToResource(): boolean {
return this.appService.config()?.enableExportToResource === true;
}

get enableExcludeFromQuantization(): boolean {
return this.appService.config()?.enableExcludeFromQuantization === true;
}
}
16 changes: 14 additions & 2 deletions src/ui/src/components/visualizer/subgraph_selection_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* ==============================================================================
*/

import {Injectable, computed, signal} from '@angular/core';
import {Injectable, Signal, computed, signal} from '@angular/core';
import {AppService} from './app_service';
import {Graph, GraphNode} from './common/input_graph';
import {ModelGraph} from './common/model_graph';
import {ModelGraph, OpNode} from './common/model_graph';
import {IncomingEdge} from './common/types';
import {isGroupNode, isOpNode} from './common/utils';

Expand All @@ -36,6 +36,18 @@ export class SubgraphSelectionService {
() => Object.keys(this.selectedNodeIds()).length,
);

readonly selectedNodes: Signal<OpNode[]> = computed(() => {
if (!this.modelGraph) {
return [];
}
const selectedNodeIds = Object.keys(this.selectedNodeIds()).filter(
(nodeId) => this.selectedNodeIds()[nodeId],
);
return selectedNodeIds.map(
(nodeId) => this.modelGraph!.nodesById[nodeId] as OpNode,
);
});

paneId = '';

constructor(private readonly appService: AppService) {}
Expand Down
8 changes: 8 additions & 0 deletions src/ui/src/services/url_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum QueryParamKey {
BENCHMARK = 'benchmark',
ENABLE_SUBGRAPH_SELECTION = 'ess',
ENABLE_EXPORT_TO_RESOURCE = 'eetr',
ENABLE_EXCLUDE_FROM_QUANTIZATION = 'eefq',
INTERNAL_COLAB = 'internal_colab',
}

Expand Down Expand Up @@ -78,6 +79,7 @@ export class UrlService {
benchmark = false;
enableSubgraphSelection = false;
enableExportToResource = false;
enableExcludeFromQuantization = false;

constructor(private readonly router: Router) {
this.decodeUrl();
Expand Down Expand Up @@ -155,6 +157,10 @@ export class UrlService {
.enableExportToResource
? '1'
: '0';
queryParams[QueryParamKey.ENABLE_EXCLUDE_FROM_QUANTIZATION] = this
.enableExcludeFromQuantization
? '1'
: '0';
} else {
queryParams[QueryParamKey.BENCHMARK] = '1';
}
Expand Down Expand Up @@ -220,6 +226,8 @@ export class UrlService {
params.get(QueryParamKey.ENABLE_SUBGRAPH_SELECTION) === '1';
this.enableExportToResource =
params.get(QueryParamKey.ENABLE_EXPORT_TO_RESOURCE) === '1';
this.enableExcludeFromQuantization =
params.get(QueryParamKey.ENABLE_EXCLUDE_FROM_QUANTIZATION) === '1';
this.benchmark = params.get(QueryParamKey.BENCHMARK) === '1';
}
}

0 comments on commit 410bcb0

Please sign in to comment.