@@ -158,7 +158,10 @@ public string save(Session sess,
158158 string model_checkpoint_path = "" ;
159159 string checkpoint_file = "" ;
160160
161- checkpoint_file = $ "{ save_path } -{ global_step } ";
161+ if ( global_step > 0 )
162+ checkpoint_file = $ "{ save_path } -{ global_step } ";
163+ else
164+ checkpoint_file = save_path ;
162165
163166 var save_path_parent = Path . GetDirectoryName ( save_path ) ;
164167
@@ -291,15 +294,13 @@ private void _RecordLastCheckpoint(string latest_save_path)
291294 if ( _saver_def . MaxToKeep <= 0 ) return ;
292295
293296 // Remove first from list if the same name was used before.
294- foreach ( var p in _last_checkpoints )
295- if ( latest_save_path == _CheckpointFilename ( ( p . Key , p . Value ) ) )
296- _last_checkpoints . Remove ( p . Key ) ;
297-
298- // Append new path to list
299- _last_checkpoints . Add ( latest_save_path , Python . time ( ) ) ;
297+ var _existed_checkpoints = _last_checkpoints . FirstOrDefault ( p => latest_save_path == _CheckpointFilename ( ( p . Key , p . Value ) ) ) ;
298+ if ( _existed_checkpoints . Key != null )
299+ _last_checkpoints . Remove ( _existed_checkpoints . Key ) ;
300+ _last_checkpoints . Add ( latest_save_path , time ( ) ) ;
300301
301302 // If more than max_to_keep, remove oldest.
302- if ( _last_checkpoints . Count > _saver_def . MaxToKeep )
303+ if ( _last_checkpoints . Count > _saver_def . MaxToKeep )
303304 {
304305 var first = _last_checkpoints . First ( ) ;
305306 _last_checkpoints . Remove ( first . Key ) ;
0 commit comments