Upload sft_03_train.py with huggingface_hub
Browse files- sft_03_train.py +6 -4
sft_03_train.py
CHANGED
|
@@ -305,8 +305,10 @@ def main():
|
|
| 305 |
for _ in range(GRAD_ACCUM_STEPS):
|
| 306 |
x, y, m = train_ds.get_batch(rng)
|
| 307 |
with torch.amp.autocast(device_type="cuda", dtype=DTYPE):
|
| 308 |
-
|
| 309 |
-
loss
|
|
|
|
|
|
|
| 310 |
if torch.isnan(loss) or loss.item() == 0.0:
|
| 311 |
continue
|
| 312 |
(loss / GRAD_ACCUM_STEPS).backward()
|
|
@@ -351,8 +353,8 @@ def main():
|
|
| 351 |
with torch.amp.autocast(device_type="cuda", dtype=DTYPE):
|
| 352 |
for _ in range(20):
|
| 353 |
x, y, m = val_ds.get_batch(val_rng)
|
| 354 |
-
logits, _ = model(x)
|
| 355 |
-
vl = masked_ce_loss(logits, y, m, softcap=
|
| 356 |
if not torch.isnan(vl) and vl.item() > 0:
|
| 357 |
val_losses.append(vl.item())
|
| 358 |
model.train()
|
|
|
|
| 305 |
for _ in range(GRAD_ACCUM_STEPS):
|
| 306 |
x, y, m = train_ds.get_batch(rng)
|
| 307 |
with torch.amp.autocast(device_type="cuda", dtype=DTYPE):
|
| 308 |
+
# targets=y geciyoruz → full (B,T,V) logits + softcap uygulanmis
|
| 309 |
+
# Donen loss'u atip kendi mask'li CE'mizi hesapliyoruz
|
| 310 |
+
logits, _ = model(x, y)
|
| 311 |
+
loss = masked_ce_loss(logits, y, m, softcap=0.0)
|
| 312 |
if torch.isnan(loss) or loss.item() == 0.0:
|
| 313 |
continue
|
| 314 |
(loss / GRAD_ACCUM_STEPS).backward()
|
|
|
|
| 353 |
with torch.amp.autocast(device_type="cuda", dtype=DTYPE):
|
| 354 |
for _ in range(20):
|
| 355 |
x, y, m = val_ds.get_batch(val_rng)
|
| 356 |
+
logits, _ = model(x, y)
|
| 357 |
+
vl = masked_ce_loss(logits, y, m, softcap=0.0)
|
| 358 |
if not torch.isnan(vl) and vl.item() > 0:
|
| 359 |
val_losses.append(vl.item())
|
| 360 |
model.train()
|