Update code/model.py with chunked cross-entropy and H200 turbo speed optimizations
Browse files- code/model.py +2 -4
code/model.py
CHANGED
|
@@ -195,7 +195,7 @@ class ViuAI(nn.Module):
|
|
| 195 |
tgt = targets
|
| 196 |
|
| 197 |
total_loss = torch.zeros(1, device=x.device, dtype=torch.float32)
|
| 198 |
-
total_active =
|
| 199 |
seq_len = hidden.size(1)
|
| 200 |
|
| 201 |
for i in range(0, seq_len, ce_chunk):
|
|
@@ -206,11 +206,9 @@ class ViuAI(nn.Module):
|
|
| 206 |
chunk_logits.view(-1, V), chunk_tgt.view(-1),
|
| 207 |
ignore_index=-100, reduction="sum"
|
| 208 |
)
|
| 209 |
-
chunk_active = (chunk_tgt != -100).sum().item()
|
| 210 |
total_loss = total_loss + chunk_loss
|
| 211 |
-
total_active += chunk_active
|
| 212 |
|
| 213 |
-
loss = total_loss /
|
| 214 |
|
| 215 |
# z-loss: stabilizes logit magnitudes during pretraining; disable for SFT (z_loss_weight=0)
|
| 216 |
if self.cfg.z_loss_weight > 0:
|
|
|
|
| 195 |
tgt = targets
|
| 196 |
|
| 197 |
total_loss = torch.zeros(1, device=x.device, dtype=torch.float32)
|
| 198 |
+
total_active = (tgt != -100).sum().clamp(min=1)
|
| 199 |
seq_len = hidden.size(1)
|
| 200 |
|
| 201 |
for i in range(0, seq_len, ce_chunk):
|
|
|
|
| 206 |
chunk_logits.view(-1, V), chunk_tgt.view(-1),
|
| 207 |
ignore_index=-100, reduction="sum"
|
| 208 |
)
|
|
|
|
| 209 |
total_loss = total_loss + chunk_loss
|
|
|
|
| 210 |
|
| 211 |
+
loss = total_loss / total_active
|
| 212 |
|
| 213 |
# z-loss: stabilizes logit magnitudes during pretraining; disable for SFT (z_loss_weight=0)
|
| 214 |
if self.cfg.z_loss_weight > 0:
|