From 82b34fc53a1be52da8e60b338f1cf7ee2c655695 Mon Sep 17 00:00:00 2001 From: Mathis Lacombe <81530082+Mathos34@users.noreply.github.com> Date: Fri, 5 Jun 2026 11:32:46 +0200 Subject: [PATCH] fix(engine): lazy import of tqdm so the test path stays import-free `src/engine.py` previously imported tqdm at module level. As a side effect, any caller that wanted only `distillation_loss`, `benchmark_latency`, or `evaluate` (the three functions exercised by `tests/`) was forced to install tqdm just to load the module. Move `from tqdm import tqdm` inside `train_one_epoch`, the only function that actually uses it. Behavior at training time is unchanged. This unblocks the CI workflow PR #3, whose lightweight pytest install deliberately omits tqdm. Same pattern as the spoken-digits-asr lazy torchaudio fix (PR #4 there). --- src/engine.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/engine.py b/src/engine.py index 565a35e..e7d75d5 100644 --- a/src/engine.py +++ b/src/engine.py @@ -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()