Implementation:Tensorflow Tfjs Graph Executor: Difference between revisions
Appearance
Auto-imported from implementations/Tensorflow_Tfjs_Graph_Executor.md |
Sync from local file |
||
| Line 105: | Line 105: | ||
== Related Pages == | == Related Pages == | ||
* [[Tensorflow_Tfjs_Layer_Variables]] - Variables that hold layer weights evaluated during execution | * [[Implementation:Tensorflow_Tfjs_Layer_Variables]] - Variables that hold layer weights evaluated during execution | ||
* [[Tensorflow_Tfjs_Backend_Operations]] - Backend operations called by layers during graph execution | * [[Implementation:Tensorflow_Tfjs_Backend_Operations]] - Backend operations called by layers during graph execution | ||
* [[Tensorflow_Tfjs_Generic_Utils]] - Utility functions like <code>toList</code> used by the executor | * [[Implementation:Tensorflow_Tfjs_Generic_Utils]] - Utility functions like <code>toList</code> used by the executor | ||
[[Category:Implementations]] | [[Category:Implementations]] | ||
[[Category:Implementations]] | [[Category:Implementations]] | ||
Latest revision as of 10:52, 27 September 2026
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, Layers_API |
| Last Updated | 2026-02-10 06:00 GMT |
Overview
The executor.ts module implements the graph execution engine for TensorFlow.js Layers models. It evaluates SymbolicTensor nodes in a computation graph by recursively resolving their dependencies through topological sorting. The module provides the FeedDict class for mapping symbolic tensors to concrete values, an execute() function that drives inference, and LRU caching of topological sort results for repeated executions.
Key components:
- FeedDict: Maps
SymbolicTensorkeys to concreteTensorvalues (and optional masks). - execute(): The core inference function that topologically sorts the computation graph, iterates over nodes, and evaluates each layer's
apply()method. - Topological sorting: Computed once per unique fetch/feed combination and cached via
LruCache. - Memory management: Intermediate tensors are disposed during non-training execution when their recipient count reaches zero.
Code Reference
Source Location
tfjs-layers/src/engine/executor.ts (View on GitHub)
Key Signatures
export class FeedDict {
constructor(feeds?: Feed[] | FeedDict);
add(key: SymbolicTensor, value: Tensor, mask?: Tensor): FeedDict;
addFeed(feed: Feed): void;
hasKey(key: SymbolicTensor): boolean;
names(): string[];
getValue(key: SymbolicTensor | string): Tensor;
getMask(key: SymbolicTensor | string): Tensor;
disposeMasks(): void;
}
export function execute(
fetches: SymbolicTensor | SymbolicTensor[],
feedDict: FeedDict,
kwargs?: Kwargs,
probe?: ExecutionProbe
): Tensor | Tensor[] | [Tensor | Tensor[]];
export function updateCacheMaxEntries(maxEntries: number): void;
export interface ExecutionProbe {
maxNumTensors?: number;
minNumTensors?: number;
}
Import
import { execute, FeedDict, Feed } from '../engine/executor';
I/O Contract
FeedDict
- Input: An optional array of
Feedobjects ({key: SymbolicTensor, value: Tensor}) or anotherFeedDictfor copy-construction. - Output: A dictionary that maps SymbolicTensor IDs/names to concrete Tensor values and optional mask Tensors.
- Constraints: Duplicate keys throw a
ValueError. Feed values are cast to match the key's dtype when possible.
execute()
- Input:
fetches: One or moreSymbolicTensornodes to evaluate.feedDict: AFeedDictcontaining concrete values for input nodes.kwargs(optional): May includetrainingboolean andmask.probe(optional): AnExecutionProbeobject for memory profiling.
- Output: A single
Tensorif a single fetch was provided, or an array ofTensors for multiple fetches. - Behavior: Performs topological sort of the graph, iterates nodes, calls
srcLayer.apply(inputValues, kwargs), and disposes intermediate tensors during inference.
Usage Examples
import { execute, FeedDict } from './engine/executor';
// Create a feed dictionary with input values
const feedDict = new FeedDict([
{ key: model.input as SymbolicTensor, value: inputTensor }
]);
// Execute the model graph
const output = execute(model.output as SymbolicTensor, feedDict);
// Execute with memory profiling
const probe: ExecutionProbe = {};
const result = execute(fetches, feedDict, {}, probe);
console.log('Max tensors during execution:', probe.maxNumTensors);
Related Pages
- Implementation:Tensorflow_Tfjs_Layer_Variables - Variables that hold layer weights evaluated during execution
- Implementation:Tensorflow_Tfjs_Backend_Operations - Backend operations called by layers during graph execution
- Implementation:Tensorflow_Tfjs_Generic_Utils - Utility functions like
toListused by the executor