Skip to content

Fix-ish hyperopt leak - #2511

Open
scarlehoff wants to merge 4 commits into
masterfrom
fix_hyperopt_leak
Open

Fix-ish hyperopt leak#2511
scarlehoff wants to merge 4 commits into
masterfrom
fix_hyperopt_leak

Conversation

@scarlehoff

Copy link
Copy Markdown
Member

I haven't been able to actually fix the memory leak, so I took a different route. Instead of fixing the leak, now each hyperopt trial is run as forked process that dies once the trial finishes.

With this we can run hyperopt for as many trials we want without hitting OOM. I'm bypassing it when running hyperopt in parallel because in that case one can just leave the database running and run many small jobs and then it would be better not to have the overhead of these changes.

Not very beautiful but functional*. I've left also my previous attempts (in internal_state.py) at cleaning up tensorflow which were not enough but they did clean up things that were dangling so I think it might be worth having them.

(tested by submitting many jobs at BSC and none of them failed due to an OOM, which was the case before! I'll add an actual benchmark)

@Radonirinaunimi

Copy link
Copy Markdown
Member

Thanks @scarlehoff for this. I will have a look ASAP before the end of this week.

@scarlehoff

Copy link
Copy Markdown
Member Author

Thanks! Turns out this is going to be important because we need to redo the hyperopt with MHOU (which certainly requires be very light on memory :__ )

@scarlehoff

Copy link
Copy Markdown
Member Author

The promised benchmark, running in montblanc in Milan, with the memory peaks:

A first run small run (so take the times with a grain of salt, since due to the computer and the size of the runcard, the overhead is irrelevant, the memory was certainly the cause of the difference)

master: 22 GB, 2.5 hours

this branch:  16 GB, 30 minutes

A second run, with a greater number of datasets and replicas

master: nothing, OOM, i got a peak of 28 GB before the OOM which happened after 1 hours

this branch: 24 GB, it finished after 6 hours

@Radonirinaunimi Radonirinaunimi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks generally fine to me. I only have very minor comments/suggestions below and they are mainly pedantic aspects. What I think are really missing though are unit tests, especially for _run_trial_in_subprocess.

We could for example have simple tests that:

  • the actual forks really have different PID than the parent
  • in case of no forks/macos it falls back directly to the current process
  • the timeout is enforced
  • ...

Comment thread n3fit/src/n3fit/backends/keras_backend/internal_state.py Outdated
Comment thread n3fit/src/n3fit/backends/keras_backend/internal_state.py Outdated
sender.close()
try:
# Wait for the child to finish running
success, ret = receiver.recv()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle, for some god knows what reasons, a child process could deadlock, causing the job to hang (with no way of telling if it's stuck or slow) (?). Should we perhaps add a timeout to avoid this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, but at the same time we don't know beforehand we don't know how long a particular architecture should take.
I think this is a problem that will be solved by the cluster admin's email saying "your job has been blocking a GPU at 0% usage for the last 24 hours" :P

(more seriously, I wouldn't know how to solve this problem effectively)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request hyperoptimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants