Skip to content

Commit 73157c5

Browse files
committed
add hook for deleted instructions
1 parent 9d38131 commit 73157c5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

trainer/src/trainer.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050

5151
class Trainer():
5252

53-
def __init__(self, sync_dir=None, patch_size=572, max_workers=12):
53+
def __init__(self, sync_dir=None, patch_size=572,
54+
max_workers=12,
55+
instruction_deleted_hook=None):
56+
57+
self.instruction_deleted_hook = instruction_deleted_hook
5458

5559
valid_sizes = get_valid_patch_sizes()
5660
assert patch_size in valid_sizes, (f'Specified patch size of {patch_size}'
@@ -146,7 +150,12 @@ def check_for_instructions(self):
146150
try:
147151
for fname in ls(self.instruction_dir):
148152
if self.execute_instruction(fname):
149-
os.remove(os.path.join(self.instruction_dir, fname))
153+
instruction_path = os.path.join(self.instruction_dir, fname)
154+
if self.instruction_deleted_hook:
155+
self.instruction_deleted_hook(instruction_path)
156+
os.remove(instruction_path)
157+
158+
150159
except Exception as e:
151160
print('Exception checking for instruction', e)
152161

0 commit comments

Comments
 (0)