Add CPU and GPU deployment modes#87
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the deployment flexibility of the Riverst server by introducing explicit support for both CPU-only and GPU-accelerated environments. It provides clear configuration options for building and running the server, allowing users to optimize performance based on their available hardware. A key improvement is the graceful handling of GPU-specific dependencies, ensuring that CPU deployments can proceed without issues even if optional GPU components are not present. This change makes the application more adaptable and accessible across a wider range of computing infrastructures. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively adds explicit controls for CPU and GPU deployments, which is a great enhancement for flexibility. The changes are well-implemented across Docker configurations, application code, and documentation. Using environment variables (RIVERST_DEPLOYMENT_TARGET and RIVERST_COMPUTE_DEVICE) provides a clear and standard way to manage deployment modes. The fallback mechanism in the VideoProcessor for when ONNX is unavailable is a nice touch for ensuring CPU deployments remain functional. The addition of unit tests for the new device selection logic is also a great practice. I've found one potential issue in the test setup that could lead to flaky tests, for which I've left a specific comment and suggestion.
| def setUp(self): | ||
| self.modules_backup = { | ||
| "torch": sys.modules.get("torch"), | ||
| "bot.utils.device_utils": sys.modules.get("bot.utils.device_utils"), | ||
| "bot.utils": sys.modules.get("bot.utils"), | ||
| "bot": sys.modules.get("bot"), | ||
| } | ||
| sys.modules["torch"] = make_fake_torch() | ||
| self.device_utils = importlib.import_module("bot.utils.device_utils") |
There was a problem hiding this comment.
The current test setup for mocking torch might be flaky. If bot.utils.device_utils or its parent packages are imported by another test before this one runs, importlib.import_module will return the cached module. This cached module would have been loaded with the original torch module, not your mock, causing tests to fail or behave unexpectedly.
To ensure the module under test always uses the mocked torch, you should explicitly remove it and its parent packages from sys.modules before re-importing. This forces a reload with the mock in place. The tearDown method will correctly restore the original state.
def setUp(self):
self.modules_backup = {
"torch": sys.modules.get("torch"),
"bot.utils.device_utils": sys.modules.get("bot.utils.device_utils"),
"bot.utils": sys.modules.get("bot.utils"),
"bot": sys.modules.get("bot"),
}
# Force reload of module under test and its parents by removing from cache
for module_name in ["bot.utils.device_utils", "bot.utils", "bot"]:
sys.modules.pop(module_name, None)
sys.modules["torch"] = make_fake_torch()
self.device_utils = importlib.import_module("bot.utils.device_utils")
Summary
Testing