[PR #5400] [MERGED] fix: if cuda is not available fallback to cpu #8475

Closed
opened 2025-11-11 17:57:35 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/5400
Author: @thiswillbeyourgithub
Created: 9/13/2024
Status: Merged
Merged: 9/14/2024
Merged by: @tjbck

Base: devHead: fix_fallback_cuda


📝 Commits (2)

📊 Changes

2 files changed (+29 additions, -1 deletions)

View changed files

📝 backend/open_webui/__init__.py (+13 -0)
📝 backend/open_webui/env.py (+16 -1)

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

Before submitting, make sure you've checked the following:

  • [ X ] Target branch: Please verify that the pull request targets the dev branch.
  • [ X ] Description: Provide a concise description of the changes made in this pull request.
  • [ X ] Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • [ X ] Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • [ X ] Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • [ X ] Testing: Have you written and run sufficient tests for validating the changes?
  • [ X ] Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • [ X ] Prefix: To cleary categorize this pull request, prefix the pull request title, using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Description

  • If the user set USE_CUDA_DOCKER to true and (for one reason or another) CUDA is not available: fallback to CPU.

Added

  • Add check to see if torch.cuda.is_available() is True if USE_CUDA_DOCKER is true, if different then revert to CPU

Additional Information

Related to the issue that caused #5378 in my case. My CUDA was not available for reasons unrelated to Open-WebUI but no check whatsoever was done until something tried to use cuda. In my case it was the hybrid search.

@tjbck I think this too illustrates that Open-WebUI does not have appropriate checks. IMO, asserts are cheap and will save everyone a lot of headache.

If you you think you're spread too thin over this project and that makes it hard to pay attention to everything in your code then I say all the more reason to use modern coding practices. It's a time saver, not a time drain. In practice: use asserts more, display errors to admins, add optional typechecking. But never forget to take care of yourself :). If I may offer an unsolicited piece of advice, click me.

Edit: Sorry for the mess in the #5396 branch. The relevant code was moved from config.py to env.py. I did a workaround to log the exception when logging was initialized instead of moving the whole code arround. LMK if that's okay with you.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/5400 **Author:** [@thiswillbeyourgithub](https://github.com/thiswillbeyourgithub) **Created:** 9/13/2024 **Status:** ✅ Merged **Merged:** 9/14/2024 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `fix_fallback_cuda` --- ### 📝 Commits (2) - [`a7ea070`](https://github.com/open-webui/open-webui/commit/a7ea07036ed77058c7f6a1d97be926b89f1d9dc6) fix: if cuda is not available fallback to cpu - [`82b3549`](https://github.com/open-webui/open-webui/commit/82b35492afee3f0e004301facd7252e7b0f4bdcd) pep8 ### 📊 Changes **2 files changed** (+29 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/__init__.py` (+13 -0) 📝 `backend/open_webui/env.py` (+16 -1) </details> ### 📄 Description # Pull Request Checklist ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request. **Before submitting, make sure you've checked the following:** - [ X ] **Target branch:** Please verify that the pull request targets the `dev` branch. - [ X ] **Description:** Provide a concise description of the changes made in this pull request. - [ X ] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [ X ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? - [ X ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [ X ] **Testing:** Have you written and run sufficient tests for validating the changes? - [ X ] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [ X ] **Prefix:** To cleary categorize this pull request, prefix the pull request title, using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry ### Description - If the user set `USE_CUDA_DOCKER` to `true` and (for one reason or another) CUDA is not available: fallback to CPU. ### Added - Add check to see if torch.cuda.is_available() is True if USE_CUDA_DOCKER is true, if different then revert to CPU --- ### Additional Information Related to the issue that caused #5378 in my case. My CUDA was not available for reasons unrelated to Open-WebUI but no check whatsoever was done until something tried to use cuda. In my case it was the hybrid search. @tjbck I think this too illustrates that Open-WebUI does not have appropriate checks. IMO, asserts are cheap and will save everyone a lot of headache. <details> If you you think you're spread too thin over this project and that makes it hard to pay attention to everything in your code then I say all the more reason to use modern coding practices. It's a time saver, not a time drain. In practice: use asserts more, display errors to admins, add optional typechecking. But never forget to take care of yourself :). <summary> If I may offer an unsolicited piece of advice, click me. </summary> </details> Edit: Sorry for the mess in the #5396 branch. The relevant code was moved from config.py to env.py. I did a workaround to log the exception when logging was initialized instead of moving the whole code arround. LMK if that's okay with you. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-11 17:57:35 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#8475