Upload folder using huggingface_hub
Browse files- src/train.py +4 -4
src/train.py
CHANGED
|
@@ -6,7 +6,7 @@ import torch
|
|
| 6 |
import torch.nn as nn
|
| 7 |
import torch.optim as optim
|
| 8 |
from torch.utils.data import DataLoader
|
| 9 |
-
from torch.cuda.amp import GradScaler, autocast
|
| 10 |
import numpy as np
|
| 11 |
import pandas as pd
|
| 12 |
from tqdm import tqdm
|
|
@@ -307,7 +307,7 @@ def validate_loss(model, valid_loader, criterion, device):
|
|
| 307 |
tax_vector = batch['tax_vector'].to(device)
|
| 308 |
labels = batch['labels'].to(device)
|
| 309 |
|
| 310 |
-
with autocast():
|
| 311 |
logits = model(input_ids, attention_mask, tax_vector)
|
| 312 |
loss = criterion(logits, labels)
|
| 313 |
|
|
@@ -439,7 +439,7 @@ def main():
|
|
| 439 |
optimizer, T_0=args.T_0, T_mult=args.T_mult, eta_min=args.min_lr
|
| 440 |
)
|
| 441 |
|
| 442 |
-
scaler = GradScaler()
|
| 443 |
|
| 444 |
# Pre-Load Ontology and GT for Evaluation
|
| 445 |
ontologies = None
|
|
@@ -512,7 +512,7 @@ def main():
|
|
| 512 |
|
| 513 |
optimizer.zero_grad()
|
| 514 |
|
| 515 |
-
with autocast():
|
| 516 |
logits = model(input_ids, attention_mask, tax_vector)
|
| 517 |
loss = criterion(logits, labels)
|
| 518 |
|
|
|
|
| 6 |
import torch.nn as nn
|
| 7 |
import torch.optim as optim
|
| 8 |
from torch.utils.data import DataLoader
|
| 9 |
+
# from torch.cuda.amp import GradScaler, autocast # Deprecated
|
| 10 |
import numpy as np
|
| 11 |
import pandas as pd
|
| 12 |
from tqdm import tqdm
|
|
|
|
| 307 |
tax_vector = batch['tax_vector'].to(device)
|
| 308 |
labels = batch['labels'].to(device)
|
| 309 |
|
| 310 |
+
with torch.amp.autocast(device_type=device.type):
|
| 311 |
logits = model(input_ids, attention_mask, tax_vector)
|
| 312 |
loss = criterion(logits, labels)
|
| 313 |
|
|
|
|
| 439 |
optimizer, T_0=args.T_0, T_mult=args.T_mult, eta_min=args.min_lr
|
| 440 |
)
|
| 441 |
|
| 442 |
+
scaler = torch.cuda.amp.GradScaler(enabled=(device.type == 'cuda'))
|
| 443 |
|
| 444 |
# Pre-Load Ontology and GT for Evaluation
|
| 445 |
ontologies = None
|
|
|
|
| 512 |
|
| 513 |
optimizer.zero_grad()
|
| 514 |
|
| 515 |
+
with torch.amp.autocast(device_type=device.type):
|
| 516 |
logits = model(input_ids, attention_mask, tax_vector)
|
| 517 |
loss = criterion(logits, labels)
|
| 518 |
|