openlrc icon indicating copy to clipboard operation
openlrc copied to clipboard

lack of module ’google.generativeai‘ when use cpu version of torch suites

Open MaleicAcid opened this issue 8 months ago • 1 comments

It’s great to see openlrc have been migrated to the uv and released 1.6.1 version. Sincerely thank you for your efforts! After selecting the cpu version of torch suites in my downstream project and trying to run, I got the following error:

  File "/home/user00/gitspace/video_tools/.venv/lib/python3.10/site-packages/openlrc/chatbot.py", line 13, in <module>
    import google.generativeai as genai
ModuleNotFoundError: No module named 'google.generativeai'

I use uv add google.generativeai to fix it. It seems if user choose the cu124 torch kit, this package will be covered.

In my downstream project, I use uv sync --extra cpu to switch torch suites. Below is part of my pyproject.yaml file:

[project.optional-dependencies]
cpu = ["torch==2.6.0+cpu", "torchaudio==2.6.0+cpu", "torchvision==0.21.0+cpu"]
cu124 = ["torch==2.6.0", "torchaudio==2.6.0", "torchvision==0.21.0"]

[tool.uv]
package = true
conflicts = [[{ extra = "cpu" }, { extra = "cu124" }]]

[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true

[[tool.uv.index]]
name = "pytorch-cu124"
url = "https://download.pytorch.org/whl/cu124"
explicit = true

[tool.uv.sources]
torch = [
    { index = "pytorch-cpu", extra = "cpu" },
    { index = "pytorch-cu124", extra = "cu124" },
]
torchaudio = [
    { index = "pytorch-cpu", extra = "cpu" },
    { index = "pytorch-cu124", extra = "cu124" },
]
torchvision = [
    { index = "pytorch-cpu", extra = "cpu" },
    { index = "pytorch-cu124", extra = "cu124" },
]

MaleicAcid avatar Apr 30 '25 10:04 MaleicAcid

The google.generativeai package should have been removed, in version 1.6.1 the 13-th line of chatbot.py is: https://github.com/zh-plus/openlrc/blob/b78547dfd6688bd1ca03f74f04b7626abf076fa2/openlrc/chatbot.py#L13

, having conflict with your error message:

File "/home/user00/gitspace/video_tools/.venv/lib/python3.10/site-packages/openlrc/chatbot.py", line 13, in import google.generativeai as genai ModuleNotFoundError: No module named 'google.generativeai'

Please check the version of the openlrc package installed on your machine. This issue may be occurring because the CPU-only version points to 1.6.0 rather than 1.6.1.

I'll investigate updating the pyproject.toml file to improve compatibility between GPU and CPU-only machines.

Thanks for reporting this issue!

zh-plus avatar May 06 '25 03:05 zh-plus