fix(engine): lazy import of tqdm so the test path stays import-free#4
Merged
Conversation
`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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: movefrom tqdm import tqdmfrom module level intotrain_one_epoch, the only function that uses it. Behavior at training time is unchanged (first call totrain_one_epochimports tqdm exactly once).Validation
python -m ruff check .locally: clean.python -m pytest -q tests/locally: 14 tests pass.from src.engine import distillation_loss, benchmark_latency, evaluatesucceeds in an environment where tqdm is unavailable (simulated viasys.modules["tqdm"] = None).Risk
low. Behavior at training time is unchanged: tqdm is imported on first call totrain_one_epoch. No CI surface fortrain.pyexists yet.Out of scope
ci/cnn-compression-lab-workflowPR 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-asrPR #4 (fix for torchaudio). Tracked context: CI run on PR #3 failed withModuleNotFoundError: No module named 'tqdm'attests/test_engine.pycollection time.