Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Idea) fix: lazy memory limit #204

Merged
merged 2 commits into from
Jun 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions handyrl/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,16 @@ def feed_episodes(self, episodes):
self.generation_results[model_id] = n + 1, r + outcome, r2 + outcome ** 2

# store generated episodes
mem = psutil.virtual_memory()
mem_used_ratio = mem.used / mem.total
mem_ok = mem_used_ratio <= 0.95
maximum_episodes = self.args['maximum_episodes'] if mem_ok else len(self.trainer.episodes)
self.trainer.episodes.extend([e for e in episodes if e is not None])

mem_percent = psutil.virtual_memory().percent
mem_ok = mem_percent <= 95
maximum_episodes = self.args['maximum_episodes'] if mem_ok else int(len(self.trainer.episodes) * 95 / mem_percent)

if not mem_ok and 'memory_over' not in self.flags:
warnings.warn("memory usage %.1f%% with buffer size %d" % (mem_used_ratio * 100, len(self.trainer.episodes)))
warnings.warn("memory usage %.1f%% with buffer size %d" % (mem_percent, len(self.trainer.episodes)))
self.flags.add('memory_over')

self.trainer.episodes.extend([e for e in episodes if e is not None])
while len(self.trainer.episodes) > maximum_episodes:
self.trainer.episodes.popleft()

Expand Down