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

Unsafe save_weights/load_weights method #27

Open
Astlaan opened this issue Jun 22, 2020 · 4 comments
Open

Unsafe save_weights/load_weights method #27

Astlaan opened this issue Jun 22, 2020 · 4 comments

Comments

@Astlaan
Copy link
Contributor

Astlaan commented Jun 22, 2020

In LRFinder.find() and LRFinder.find_generator(), there is a call to the following functions:

self.model.save_weights('tmp.h5')
self.model.load_weights('tmp.h5')

This is unsafe: In the case where several python processes running LRFinder in parallel, they will all attempt to access the same file, mixing weights between processess...

A random file name should instead be generated every time, and it should be checked whether this random file name already exists or not. It should be noted that, one should prevent different processes from generating the same random file name if they are executed at the same time (this can be a problem if random uses datetime as seed).

@JonnoFTW
Copy link
Contributor

A NamedTemporaryFile is probably best in this case:

https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile

@Astlaan
Copy link
Contributor Author

Astlaan commented Jun 23, 2020

A NamedTemporaryFile is probably best in this case:

https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile

Wow that is cool ahah.

@surmenok
Copy link
Owner

Good point! Would you mind to create a PR?

@Astlaan
Copy link
Contributor Author

Astlaan commented Jul 4, 2020

Good point! Would you mind to create a PR?

I actually just fixed it in my local clone by saving the weights in memory instead of on disk.

According to this, even a 50-layer ResNet uses around ~168MB, so I suppose keeping them in memory will be just fine for most cases? The weights are saved and loaded immediately after, the lr search anyway.

In this case, I made a pull request #28.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants