Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.data import DataLoader
from tqdm import tqdm


def train_one_epoch(model, loader: DataLoader, opt, loss_fn=None) -> float:
"""Standard training epoch. tqdm is imported lazily so that callers that
only need `distillation_loss` or `benchmark_latency` (e.g. the unit-test
path) do not pay the tqdm install cost."""
from tqdm import tqdm # noqa: PLC0415

model.train()
if loss_fn is None:
loss_fn = nn.CrossEntropyLoss()
Expand Down