Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit 0627b39

Browse files
author
Nikhil Thorat
authored
Fixes adam optimizer to wrap variable construction in tidy() and assert 1 remaining tensor in unit tests. (#717)
1 parent 8207632 commit 0627b39

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/optimizers/adam_optimizer.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ export class AdamOptimizer extends Optimizer {
5252
// b1, b2 keep initial value of beta* hyperparameters.
5353
this.beta1 = keep(scalar(beta1));
5454
this.beta2 = keep(scalar(beta2));
55-
// accB* will be updated by batch.
56-
this.accBeta1 = variable(scalar(beta1));
57-
this.accBeta2 = variable(scalar(beta2));
55+
tidy(() => {
56+
// accB* will be updated by batch.
57+
this.accBeta1 = variable(scalar(beta1));
58+
this.accBeta2 = variable(scalar(beta2));
59+
});
5860
this.oneMinusBeta1 = keep(scalar(1 - beta1));
5961
this.oneMinusBeta2 = keep(scalar(1 - beta2));
6062
this.one = keep(scalar(1));

src/optimizers/adam_optimizer_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ describeWithFlags('AdamOptimizer', ALL_ENVS, () => {
7979
x.dispose();
8080
optimizer.dispose();
8181

82-
// There should be no more Tensors.
83-
expect(dl.memory().numTensors).toBe(0);
82+
// The only tensor remaining should be the argument to variable().
83+
expect(dl.memory().numTensors).toBe(1);
8484
});
8585

8686
it('graph', () => {

0 commit comments

Comments
 (0)