Skip to content

Commit dad72a2

Browse files
committed
Push final-ish state
1 parent 2c49d1a commit dad72a2

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

src/imitation/policies/replay_buffer_wrapper.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ def __init__(
137137
"""
138138
# TODO should we limit by number of batches (as this does)
139139
# or number of observations returned?
140-
self.sample_count = 0
141-
self.entropy_as_reward_samples = entropy_as_reward_samples
142-
self.k = k
143-
# TODO support n_envs > 1
144-
self.entropy_stats = util.RunningMeanAndVar(shape=(1,))
145140
super().__init__(
146141
buffer_size,
147142
observation_space,
@@ -150,14 +145,18 @@ def __init__(
150145
reward_fn=reward_fn,
151146
**kwargs,
152147
)
148+
self.sample_count = 0
149+
self.k = k
150+
# TODO support n_envs > 1
151+
self.entropy_stats = util.RunningMeanAndVar(shape=(1,))
152+
self.entropy_as_reward_samples = entropy_as_reward_samples
153153

154-
# TODO this seems to never actually get called?
155154
def sample(self, *args, **kwargs):
156155
self.sample_count += 1
157156
samples = super().sample(*args, **kwargs)
158-
print(self.sample_count)
159-
print(self.entropy_as_reward_samples)
160-
if self.sample_count > 500:
157+
# For some reason self.entropy_as_reward_samples seems to get cleared,
158+
# and I have no idea why.
159+
if self.sample_count > self.entropy_as_reward_samples:
161160
return samples
162161
# TODO we really ought to reset the reward network once we are done w/
163162
# the entropy based pre-training. We also have no reason to train

tests/policies/test_replay_buffer_wrapper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def reset(self):
190190

191191
def test_entropy_wrapper_class(tmpdir, rng):
192192
buffer_size = 20
193-
entropy_samples = 40
193+
entropy_samples = 500
194194
k = 4
195195

196196
venv = DummyVecEnv([ActionIsObsEnv])
@@ -211,17 +211,17 @@ def test_entropy_wrapper_class(tmpdir, rng):
211211

212212
rl_algo.learn(total_timesteps=buffer_size)
213213
initial_entropy = util.compute_state_entropy(
214-
th.Tensor(rl_algo.replay_buffer.observations),
215-
th.Tensor(rl_algo.replay_buffer.observations),
214+
th.Tensor(rl_algo.replay_buffer.replay_buffer.observations),
215+
th.Tensor(rl_algo.replay_buffer.replay_buffer.observations),
216216
k=k,
217217
)
218218

219219
rl_algo.learn(total_timesteps=entropy_samples - buffer_size)
220220
# Expect that the entropy of our replay buffer is now higher,
221221
# since we trained with that as the reward.
222222
trained_entropy = util.compute_state_entropy(
223-
th.Tensor(rl_algo.replay_buffer.observations),
224-
th.Tensor(rl_algo.replay_buffer.observations),
223+
th.Tensor(rl_algo.replay_buffer.replay_buffer.observations),
224+
th.Tensor(rl_algo.replay_buffer.replay_buffer.observations),
225225
k=k,
226226
)
227227
assert trained_entropy.mean() > initial_entropy.mean()

0 commit comments

Comments
 (0)