File size: 562 Bytes
ee594f0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import re
with open('Train_CMTLNet_Step2.py', 'r') as f:
code = f.read()
target = """ scaler.step(optimizer)
scaler.update()
# Get current learning rate"""
replacement = """ scaler.step(optimizer)
scaler.update()
global_step += 1
# Get current learning rate"""
if target in code:
code = code.replace(target, replacement)
with open('Train_CMTLNet_Step2.py', 'w') as f:
f.write(code)
print("Fixed global_step")
else:
print("Target not found")
|