[bugfix] Lazy import cv2#26869
Conversation
Signed-off-by: angelayi <yiangela7@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request correctly implements lazy loading for the cv2 module to fix a test failure. The current approach of moving the import into each function that uses it is valid. However, I've suggested using the LazyLoader utility, which is a more idiomatic and maintainable pattern within the vLLM codebase for handling lazy dependencies. This centralizes the lazy-loading logic and avoids repetitive import statements in functions. My review includes a concrete suggestion to adopt this pattern.
| from functools import lru_cache | ||
| from typing import Any, ClassVar, Literal | ||
|
|
||
| import cv2 |
There was a problem hiding this comment.
Instead of moving the cv2 import inside each function, consider using the LazyLoader utility from vllm.utils. This is a cleaner and more idiomatic approach for lazy loading in this project, as seen with other modules. It avoids repeating import statements and keeps the function bodies cleaner, while still achieving the goal of lazy loading.
| import cv2 | |
| from vllm.utils import LazyLoader | |
| cv2 = LazyLoader("cv2", globals(), "cv2") |
| import cv2 | ||
|
|
Signed-off-by: angelayi <yiangela7@gmail.com> Signed-off-by: bbartels <benjamin@bartels.dev>
Signed-off-by: angelayi <yiangela7@gmail.com> Signed-off-by: Alberto Perdomo <aperdomo@redhat.com>
Signed-off-by: angelayi <yiangela7@gmail.com>
Signed-off-by: angelayi <yiangela7@gmail.com>
Signed-off-by: angelayi <yiangela7@gmail.com> Signed-off-by: 0xrushi <6279035+0xrushi@users.noreply.github.com>
Signed-off-by: angelayi <yiangela7@gmail.com> Signed-off-by: 0xrushi <6279035+0xrushi@users.noreply.github.com>
Signed-off-by: angelayi <yiangela7@gmail.com>
Signed-off-by: angelayi <yiangela7@gmail.com>
Purpose
Fixes
pytest -sv tests/standalone_tests/lazy_imports.pyfailure which I saw in this runTest Plan
pytest -sv tests/standalone_tests/lazy_imports.pyTest Result
test passes
cc @ProExpertProg