unknownBrain's picture
Upload all remaining preprocessing, standalone, test and utility files
ee594f0 verified
Raw History Blame Contribute Delete
1.17 kB
import re
with open('Train_CMTLNet_Step1.py', 'r') as f:
content = f.read()
# Remove tqdm import
content = re.sub(r'from tqdm import tqdm.*?\n', '', content)
# Remove Checkpoint prints
content = re.sub(r' *print\("\[Checkpoint \d/6\].*?\n', '', content)
# Replace tqdm loop with regular loop and add print statement
content = content.replace(
'pbar = tqdm(range(len(train_loader_1p19q)), desc=f"Epoch {epoch}/{config.epochs_s1}", dynamic_ncols=True)\n \n for batch_idx in pbar:',
'for batch_idx in range(len(train_loader_1p19q)):'
)
content = content.replace('pbar.set_postfix({"RAM": f"{mem_gb:.2f} GB"})', '')
# Insert the batch print
target = 'scaler.update()\n # --------------------------------------------------'
replacement = '''scaler.update()
# --------------------------------------------------
if batch_idx % 10 == 0:
print(f" [Epoch {epoch}] Batch {batch_idx}/{len(train_loader_1p19q)} | Loss: {total_loss.item():.4f} | RAM: {mem_gb:.2f} GB")'''
content = content.replace(target, replacement)
with open('Train_CMTLNet_Step1.py', 'w') as f:
f.write(content)