Download code/fix_step1.py from unknownBrain/survivalanalysis_checkpointing: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/datasets/unknownBrain/survivalanalysis_checkpointing/resolve/main/code/fix_step1.py
- Command line
-
hf download hf://datasets/unknownBrain/survivalanalysis_checkpointing/code/fix_step1.py
-
curl -L -o fix_step1.py https://huggingface.co/datasets/unknownBrain/survivalanalysis_checkpointing/resolve/main/code/fix_step1.py
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) | |