[GH-ISSUE #8274] Ollama hangs without timeout, Ollama model is consuming full CPU or GPU #31052

Closed
opened 2026-04-22 11:10:46 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @ttww on GitHub (Dec 31, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/8274

What is the issue?

Doing Ollama connections with langchain the API hangs, depending on the input.
No information is loggend on the Ollama serve side with debug option 3.

I have attached a test case (Python program, test image, and README) to reproduce it.
ollama_hang.tgz

Changing the prompt, may change the situation (see c't Forum)

OS

Linux, macOS

GPU

Intel, Apple

CPU

AMD, Apple

Ollama version

0.5.4

Originally created by @ttww on GitHub (Dec 31, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/8274 ### What is the issue? Doing Ollama connections with langchain the API hangs, depending on the input. No information is loggend on the Ollama serve side with debug option 3. I have attached a test case (Python program, test image, and README) to reproduce it. [ollama_hang.tgz](https://github.com/user-attachments/files/18281727/ollama_hang.tgz) Changing the prompt, may change the situation (see [c't Forum](https://www.heise.de/forum/heise-online/Kommentare/Wie-eine-lokale-KI-die-Fotosammlung-auf-dem-NAS-verschlagworten-kann/Haengt-sich-bei-jedem-2-3-Bild-auf/thread-7564685/#posting_43932391)) ### OS Linux, macOS ### GPU Intel, Apple ### CPU AMD, Apple ### Ollama version 0.5.4
GiteaMirror added the bug label 2026-04-22 11:10:46 -05:00
Author
Owner

@rick-github commented on GitHub (Dec 31, 2024):

ollama seems to work fine.

$ ollama run llava:v1.6 Please find very precise keywords and separate them with commas. ./IMG_8240.JPG 
Added image './IMG_8240.JPG'
 insect, bug, aquatic, microscope, pest, nature, water, tiny, creature, monitor, image, screen, photo, health, environment, ecosystem, biodiversity, science, observation, species 
<!-- gh-comment-id:2566509907 --> @rick-github commented on GitHub (Dec 31, 2024): ollama seems to work fine. ```console $ ollama run llava:v1.6 Please find very precise keywords and separate them with commas. ./IMG_8240.JPG Added image './IMG_8240.JPG' insect, bug, aquatic, microscope, pest, nature, water, tiny, creature, monitor, image, screen, photo, health, environment, ecosystem, biodiversity, science, observation, species ```
Author
Owner

@rick-github commented on GitHub (Dec 31, 2024):

--- ollama_hang/ollama_hang.py	2024-12-31 23:08:01.000000000 +1000
+++ ollama_hang.8274/ollama_hang.py	2025-01-01 01:04:02.098282867 +1000
@@ -27,7 +27,7 @@
 
 def main():
     # Open connection
-    llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True)
+    llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True, num_predict=200)
     prompt = "Please find very precise keywords and separate them with commas."
 
     # Loop over images
$ docker compose up
[+] Running 1/0
 ✔ Container ollama_hang8274-i8274-1  Created                                                                                                                                                       0.0s 
Attaching to i8274-1
i8274-1  | /app/ollama_hang.py:30: LangChainDeprecationWarning: The class `Ollama` was deprecated in LangChain 0.3.1 and will be removed in 1.0.0. An updated version of the class exists in the :class:`~langchain-ollama package and should be used instead. To use it run `pip install -U :class:`~langchain-ollama` and import as `from :class:`~langchain_ollama import OllamaLLM``.
i8274-1  |   llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True, num_predict=200)
i8274-1  | Marker scan hit start of image data
i8274-1  | Image 'test_images/IMG_8240.JPG' processing...
i8274-1  | crab,aquatic,animal,screen,monitor,image,computer,mouse,finger,person,hand,water,fish,tank,pet,home,indoor,outdoor,nature,wildlife,insect,shell,claw,antennae,eye,leg,body,color,texture,pattern,habitat,environment,ocean,sea,river,lake,pond,beach,sand,rock,coral,algae,plant,food,diet,survival,adaptation,evolution,biology,ecology,photography,video,technology,device,software,application,program,operatingsystem,userinterface,digital,virtual,reality,3D,imageprocessing,enhancement,zoom,focus,resolution,pixel,display,screensize,aspectratio,colordepth,brightness,contrast,saturation,hue,temperature,humidity,light,shadow,reflection,refraction,lens,camera,photographyequipment,tripod,
i8274-1  | ollama_hang.py
i8274-1  | save to 'test_images_results/IMG_8240_meta.jpg'
i8274-1 exited with code 0

<!-- gh-comment-id:2566522678 --> @rick-github commented on GitHub (Dec 31, 2024): ```diff --- ollama_hang/ollama_hang.py 2024-12-31 23:08:01.000000000 +1000 +++ ollama_hang.8274/ollama_hang.py 2025-01-01 01:04:02.098282867 +1000 @@ -27,7 +27,7 @@ def main(): # Open connection - llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True) + llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True, num_predict=200) prompt = "Please find very precise keywords and separate them with commas." # Loop over images ``` ```console $ docker compose up [+] Running 1/0 ✔ Container ollama_hang8274-i8274-1 Created 0.0s Attaching to i8274-1 i8274-1 | /app/ollama_hang.py:30: LangChainDeprecationWarning: The class `Ollama` was deprecated in LangChain 0.3.1 and will be removed in 1.0.0. An updated version of the class exists in the :class:`~langchain-ollama package and should be used instead. To use it run `pip install -U :class:`~langchain-ollama` and import as `from :class:`~langchain_ollama import OllamaLLM``. i8274-1 | llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True, num_predict=200) i8274-1 | Marker scan hit start of image data i8274-1 | Image 'test_images/IMG_8240.JPG' processing... i8274-1 | crab,aquatic,animal,screen,monitor,image,computer,mouse,finger,person,hand,water,fish,tank,pet,home,indoor,outdoor,nature,wildlife,insect,shell,claw,antennae,eye,leg,body,color,texture,pattern,habitat,environment,ocean,sea,river,lake,pond,beach,sand,rock,coral,algae,plant,food,diet,survival,adaptation,evolution,biology,ecology,photography,video,technology,device,software,application,program,operatingsystem,userinterface,digital,virtual,reality,3D,imageprocessing,enhancement,zoom,focus,resolution,pixel,display,screensize,aspectratio,colordepth,brightness,contrast,saturation,hue,temperature,humidity,light,shadow,reflection,refraction,lens,camera,photographyequipment,tripod, i8274-1 | ollama_hang.py i8274-1 | save to 'test_images_results/IMG_8240_meta.jpg' i8274-1 exited with code 0 ```
Author
Owner

@rick-github commented on GitHub (Dec 31, 2024):

--- ollama_hang/ollama_hang.py	2024-12-31 23:08:01.000000000 +1000
+++ ollama_hang.8274/ollama_hang.py	2025-01-01 01:12:57.593001024 +1000
@@ -27,7 +27,7 @@
 
 def main():
     # Open connection
-    llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True)
+    llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, verbose=True)
     prompt = "Please find very precise keywords and separate them with commas."
 
     # Loop over images
$ docker compose up 
[+] Running 1/0
 ✔ Container ollama_hang8274-i8274-1  Created                                                                                                                0.0s 
Attaching to i8274-1
i8274-1  | /app/ollama_hang.py:30: LangChainDeprecationWarning: The class `Ollama` was deprecated in LangChain 0.3.1 and will be removed in 1.0.0. An updated version of the class exists in the :class:`~langchain-ollama package and should be used instead. To use it run `pip install -U :class:`~langchain-ollama` and import as `from :class:`~langchain_ollama import OllamaLLM``.
i8274-1  |   llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, verbose=True)
i8274-1  | Marker scan hit start of image data
i8274-1  | Image 'test_images/IMG_8240.JPG' processing...
i8274-1  | mouse,rat,hamster,computermouse,videocamera,aquarium,fish,snail,crustacean,monitor,microscope
i8274-1  | ollama_hang.py
i8274-1  | save to 'test_images_results/IMG_8240_meta.jpg'
i8274-1 exited with code 0

<!-- gh-comment-id:2566526960 --> @rick-github commented on GitHub (Dec 31, 2024): ```diff --- ollama_hang/ollama_hang.py 2024-12-31 23:08:01.000000000 +1000 +++ ollama_hang.8274/ollama_hang.py 2025-01-01 01:12:57.593001024 +1000 @@ -27,7 +27,7 @@ def main(): # Open connection - llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True) + llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, verbose=True) prompt = "Please find very precise keywords and separate them with commas." # Loop over images ``` ```console $ docker compose up [+] Running 1/0 ✔ Container ollama_hang8274-i8274-1 Created 0.0s Attaching to i8274-1 i8274-1 | /app/ollama_hang.py:30: LangChainDeprecationWarning: The class `Ollama` was deprecated in LangChain 0.3.1 and will be removed in 1.0.0. An updated version of the class exists in the :class:`~langchain-ollama package and should be used instead. To use it run `pip install -U :class:`~langchain-ollama` and import as `from :class:`~langchain_ollama import OllamaLLM``. i8274-1 | llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, verbose=True) i8274-1 | Marker scan hit start of image data i8274-1 | Image 'test_images/IMG_8240.JPG' processing... i8274-1 | mouse,rat,hamster,computermouse,videocamera,aquarium,fish,snail,crustacean,monitor,microscope i8274-1 | ollama_hang.py i8274-1 | save to 'test_images_results/IMG_8240_meta.jpg' i8274-1 exited with code 0 ```
Author
Owner

@rick-github commented on GitHub (Dec 31, 2024):

--- ollama_hang/ollama_hang.py	2024-12-31 23:08:01.000000000 +1000
+++ ollama_hang.8274/ollama_hang.py	2025-01-01 01:25:49.994798877 +1000
@@ -28,7 +28,7 @@
 def main():
     # Open connection
     llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True)
-    prompt = "Please find very precise keywords and separate them with commas."
+    prompt = "Please find ten very precise keywords and separate them with commas."
 
     # Loop over images
     for img_filename in glob.glob(f"{SOURCE_DIR}/*.JPG"):  
$ docker compose up 
[+] Running 1/0
 ✔ Container ollama_hang8274-i8274-1  Created                                                                  0.0s 
Attaching to i8274-1
i8274-1  | /app/ollama_hang.py:30: LangChainDeprecationWarning: The class `Ollama` was deprecated in LangChain 0.3.1 and will be removed in 1.0.0. An updated version of the class exists in the :class:`~langchain-ollama package and should be used instead. To use it run `pip install -U :class:`~langchain-ollama` and import as `from :class:`~langchain_ollama import OllamaLLM``.
i8274-1  |   llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True)
i8274-1  | Marker scan hit start of image data
i8274-1  | Image 'test_images/IMG_8240.JPG' processing...
i8274-1  | insect,aquatic,microscopic,magnification,close-up,image,monitor,computer,screen,bug
i8274-1  | ollama_hang.py
i8274-1  | save to 'test_images_results/IMG_8240_meta.jpg'
i8274-1 exited with code 0

<!-- gh-comment-id:2566536094 --> @rick-github commented on GitHub (Dec 31, 2024): ```diff --- ollama_hang/ollama_hang.py 2024-12-31 23:08:01.000000000 +1000 +++ ollama_hang.8274/ollama_hang.py 2025-01-01 01:25:49.994798877 +1000 @@ -28,7 +28,7 @@ def main(): # Open connection llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True) - prompt = "Please find very precise keywords and separate them with commas." + prompt = "Please find ten very precise keywords and separate them with commas." # Loop over images for img_filename in glob.glob(f"{SOURCE_DIR}/*.JPG"): ``` ```console $ docker compose up [+] Running 1/0 ✔ Container ollama_hang8274-i8274-1 Created 0.0s Attaching to i8274-1 i8274-1 | /app/ollama_hang.py:30: LangChainDeprecationWarning: The class `Ollama` was deprecated in LangChain 0.3.1 and will be removed in 1.0.0. An updated version of the class exists in the :class:`~langchain-ollama package and should be used instead. To use it run `pip install -U :class:`~langchain-ollama` and import as `from :class:`~langchain_ollama import OllamaLLM``. i8274-1 | llava_model = Ollama(model="llava:v1.6", base_url=OLLAMA_BASE_URL, temperature=0, verbose=True) i8274-1 | Marker scan hit start of image data i8274-1 | Image 'test_images/IMG_8240.JPG' processing... i8274-1 | insect,aquatic,microscopic,magnification,close-up,image,monitor,computer,screen,bug i8274-1 | ollama_hang.py i8274-1 | save to 'test_images_results/IMG_8240_meta.jpg' i8274-1 exited with code 0 ```
Author
Owner

@ttww commented on GitHub (Jan 1, 2025):

ollama seems to work fine.

$ ollama run llava:v1.6 Please find very precise keywords and separate them with commas. ./IMG_8240.JPG 
Added image './IMG_8240.JPG'
 insect, bug, aquatic, microscope, pest, nature, water, tiny, creature, monitor, image, screen, photo, health, environment, ecosystem, biodiversity, science, observation, species 

Does it work with your changes or only with the original code?
If it works with your changes, please don’t take this the wrong way, but who can guarantee it won’t happen again with a different image?
In my view, the API needs to behave consistently. Ideally, it should show an appropriate error message indicating the cause.
Right now, it feels like luck whether it works or not. It would be best to identify and fix the root cause.

BTW: Using your prompt with the added "ten" works also in my case, but it "feels" wrong to fix it that way :-)

<!-- gh-comment-id:2567071614 --> @ttww commented on GitHub (Jan 1, 2025): > ollama seems to work fine. > > ``` > $ ollama run llava:v1.6 Please find very precise keywords and separate them with commas. ./IMG_8240.JPG > Added image './IMG_8240.JPG' > insect, bug, aquatic, microscope, pest, nature, water, tiny, creature, monitor, image, screen, photo, health, environment, ecosystem, biodiversity, science, observation, species > ``` Does it work with your changes or only with the original code? If it works with your changes, please don’t take this the wrong way, but who can guarantee it won’t happen again with a different image? In my view, the API needs to behave consistently. Ideally, it should show an appropriate error message indicating the cause. Right now, it feels like luck whether it works or not. It would be best to identify and fix the root cause. BTW: Using your prompt with the added "ten" works also in my case, but it "feels" wrong to fix it that way :-)
Author
Owner

@rick-github commented on GitHub (Jan 1, 2025):

The root cause is the imprecise prompting. When you see no response, the model is not hanging, it is generating tokens. If you limit the token generation in any of the depicted ways, the generation will stop and you get a response.

<!-- gh-comment-id:2567075286 --> @rick-github commented on GitHub (Jan 1, 2025): The root cause is the imprecise prompting. When you see no response, the model is not hanging, it is generating tokens. If you limit the token generation in any of the depicted ways, the generation will stop and you get a response.
Author
Owner

@ttww commented on GitHub (Jan 1, 2025):

The root cause is the imprecise prompting. When you see no response, the model is not hanging, it is generating tokens. If you limit the token generation in any of the depicted ways, the generation will stop and you get a response.

OK, thanks for the explanation; that makes sense.
If you know more about how the models work, it’s actually obvious.
From my perspective, we can close this issue.

A timeout parameter in the API might be useful, but that’s another topic.

<!-- gh-comment-id:2567078924 --> @ttww commented on GitHub (Jan 1, 2025): > The root cause is the imprecise prompting. When you see no response, the model is not hanging, it is generating tokens. If you limit the token generation in any of the depicted ways, the generation will stop and you get a response. OK, thanks for the explanation; that makes sense. If you know more about how the models work, it’s actually obvious. From my perspective, we can close this issue. A timeout parameter in the API might be useful, but that’s another topic.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#31052