Skip to content

fix(engine): lazy import of tqdm so the test path stays import-free#4

Merged
Mathos34 merged 1 commit into
mainfrom
fix/cnn-compression-lab-lazy-tqdm
Jun 5, 2026
Merged

fix(engine): lazy import of tqdm so the test path stays import-free#4
Mathos34 merged 1 commit into
mainfrom
fix/cnn-compression-lab-lazy-tqdm

Conversation

@Mathos34

@Mathos34 Mathos34 commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Objective

Unblock CI PR #3 by removing the implicit dependency on tqdm when callers only need the distillation loss, evaluator, or latency benchmark helpers (the three functions exercised by tests/).

Changes

  • src/engine.py: move from tqdm import tqdm from module level into train_one_epoch, the only function that uses it. Behavior at training time is unchanged (first call to train_one_epoch imports tqdm exactly once).

Validation

  • python -m ruff check . locally: clean.
  • python -m pytest -q tests/ locally: 14 tests pass.
  • Confirmed from src.engine import distillation_loss, benchmark_latency, evaluate succeeds in an environment where tqdm is unavailable (simulated via sys.modules["tqdm"] = None).

Risk

low. Behavior at training time is unchanged: tqdm is imported on first call to train_one_epoch. No CI surface for train.py exists yet.

Out of scope

  • The CI workflow itself (ci/cnn-compression-lab-workflow PR ci: add lint + unit test workflow #3) is the consumer of this fix; once this PR merges, that one will go green automatically on re-run.

Same lazy-import pattern as spoken-digits-asr PR #4 (fix for torchaudio). Tracked context: CI run on PR #3 failed with ModuleNotFoundError: No module named 'tqdm' at tests/test_engine.py collection time.

`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).
@Mathos34 Mathos34 merged commit b0d254a into main Jun 5, 2026
@Mathos34 Mathos34 deleted the fix/cnn-compression-lab-lazy-tqdm branch June 5, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant