@@ -97,7 +97,7 @@ export class Engine implements TensorManager, DataMover {
97
97
98
98
// Keep Tensors that parallel the tapes.
99
99
private activeScope : ScopeState ;
100
- private scopeStack : ScopeState [ ] ;
100
+ private scopeStack : ScopeState [ ] = [ ] ;
101
101
private keepTensors : Set < number > = new Set ( ) ;
102
102
private profiler : Profiler ;
103
103
@@ -112,9 +112,6 @@ export class Engine implements TensorManager, DataMover {
112
112
constructor (
113
113
public backend : KernelBackend , public safeMode : boolean ,
114
114
private debugMode : ( ) => boolean ) {
115
- // Create a default outer scope.
116
- this . activeScope = { track : [ ] , name : 'default scope' } ;
117
- this . scopeStack = [ this . activeScope ] ;
118
115
this . profiler = new Profiler ( backend ) ;
119
116
this . activeProfile =
120
117
{ newBytes : 0 , newTensors : 0 , peakBytes : 0 , kernels : [ ] , result : null } ;
@@ -454,7 +451,7 @@ export class Engine implements TensorManager, DataMover {
454
451
455
452
const oldScope = this . scopeStack . pop ( ) ;
456
453
this . activeScope = this . scopeStack . length === 0 ?
457
- { track : [ ] , name : 'default scope' } :
454
+ null :
458
455
this . scopeStack [ this . scopeStack . length - 1 ] ;
459
456
460
457
// Track the current result in the parent scope.
@@ -612,7 +609,9 @@ export class Engine implements TensorManager, DataMover {
612
609
'Safe mode is ON. Enclose all tensor operations inside tf.tidy(): ' +
613
610
'tf.tidy(() => {op();...}); to avoid memory leaks.' ) ;
614
611
}
615
- this . activeScope . track . push ( result ) ;
612
+ if ( this . activeScope != null ) {
613
+ this . activeScope . track . push ( result ) ;
614
+ }
616
615
return result ;
617
616
}
618
617
}
0 commit comments