rlworkgroup / garage

A toolkit for reproducible reinforcement learning research.
MIT License
1.84k stars 309 forks source link

Snapshotter loads wrong itr when asked to load last itr #2300

Closed guyk1971 closed 2 years ago

guyk1971 commented 2 years ago

Hi, When trying to load 'last' snapshot there's a bug as it doesnt always load the last one. consider the case we have itr_0.pkl,itr_20.pkl,itr_40.pkl,....,itr_120.pkl.

if we want to load the 'last' snapshot, the snapshotter load code search for 'params.pkl' and if not found it sorts the list of files with itr_{}.pkl template (snapshotter.py line 162):

files.sort()

and then take the last.

However, sorting this way will not yield the last iteration pkl but itr_80.pkl because this is the highest alphabetical value.

a proposed fix would be to replace line 162 with the following:

files.sort(key=lambda x: int(os.path.splitext(x)[0].split('itr_')[1]))

which isolate the iteration number and sort by its numerical value.

Thanks,

krzentner commented 2 years ago

This is indeed a fairly large bug. Thank you for reporting it, I wish I had noticed it sooner.