Skip to content

Commit

Permalink
Update tfjs-converter/src/executor/graph_executor.ts
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Soulanille <[email protected]>
  • Loading branch information
axinging and mattsoulanille committed Nov 4, 2022
1 parent de84a0e commit 1c7fedf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tfjs-converter/src/executor/graph_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class GraphExecutor implements FunctionExecutor {
this.graph, this.weightMap, executionInfo);
}

private cloneTensorMap(tensorsMap: NamedTensorsMap) {
private cloneTensorMap(tensorsMap: NamedTensorsMap): NamedTensorsMap {
return Object.fromEntries(
Object.entries(tensorsMap).map(([name, tensorsList]) => {
return [
Expand All @@ -189,6 +189,9 @@ export class GraphExecutor implements FunctionExecutor {
return null;
}
const clone = tensor.clone();
// Keep the clone because `model.execute()` may be called within
// a `tidy()`, but the user may inspect these tensors after the
// tidy.
keep(clone);
return clone;
})
Expand All @@ -206,6 +209,8 @@ export class GraphExecutor implements FunctionExecutor {
* outputs array.
*/
execute(inputs: NamedTensorMap, outputs?: string[]): Tensor[] {
// Dispose any tensors from a prior run to avoid leaking them.
this.disposeIntermediateTensors();
inputs = this.mapInputs(inputs);
const names = Object.keys(inputs).sort();
this.checkInputs(inputs);
Expand Down Expand Up @@ -389,6 +394,8 @@ export class GraphExecutor implements FunctionExecutor {
inputs: NamedTensorMap, outputs?: string[], isFunctionExecution = false,
tensorArrayMap: TensorArrayMap = {},
tensorListMap: TensorListMap = {}): Promise<Tensor[]> {
// Dispose any tensors from a prior run to avoid leaking them.
this.disposeIntermediateTensors();
if (!isFunctionExecution) {
inputs = this.mapInputs(inputs);
this.checkInputs(inputs);
Expand Down

0 comments on commit 1c7fedf

Please sign in to comment.