def clean(self, global_epoch_idx):
if self.cleaned:<EOL><INDENT>return<EOL><DEDENT>self.cleaned = True<EOL>self.backend.clean(global_epoch_idx)<EOL>self._make_sure_dir_exists()<EOL>for x in os.listdir(self.model_config.checkpoint_dir()):<EOL><INDENT>match = re.match('<STR_LIT>', x)<EOL>if match:<EOL><INDENT>idx = int(match[<NUM_LIT:1>])<EOL>if idx > global_epoch_idx:<EOL><INDENT>os.remove(os.path.join(self.model_config.checkpoint_dir(), x))<EOL><DEDENT><DEDENT>match = re.match('<STR_LIT>', x)<EOL>if match:<EOL><INDENT>idx = int(match[<NUM_LIT:1>])<EOL>if idx > global_epoch_idx:<EOL><INDENT>os.remove(os.path.join(self.model_config.checkpoint_dir(), x))<EOL><DEDENT><DEDENT>match = re.match('<STR_LIT>', x)<EOL>if match:<EOL><INDENT>idx = int(match[<NUM_LIT:1>])<EOL>if idx > global_epoch_idx:<EOL><INDENT>os.remove(os.path.join(self.model_config.checkpoint_dir(), x))<EOL><DEDENT><DEDENT><DEDENT>
Clean old checkpoints