Increasing num_keep/num_predict causes multiple <thinking> tabs #3520

Closed
opened 2025-11-11 15:33:14 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @Babyhamsta on GitHub (Jan 31, 2025).

Bug Report

Installation Method

Pip install (v0.5.7)

Environment

Confirmation:

  • I have read and followed all the instructions provided in the README.md.
  • I am on the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below.

Expected Behavior:

Thinking tab should only be created once and should update multiple times with new data/information.

Actual Behavior:

The thinking tab was created for each step I believe.

Description

Bug Summary:
When asking R1 for some assistance with a bug I was having with C# code. I wanted a larger context length and potential response so I increased the 2 settings num_keep/num_predict. After doing so the AI/UI proceeded to bug out and create many many many thinking tabs. It ran for quite a long time and I didn't allow it finish it's response as it ran longer than 10 minutes.

Reproduction Details

Steps to Reproduce:
Increase num_keep/num_predict:
Num_keep: 1002776
Num_predict: 20000

My exact prompt:

Can you help me fix my zooming functionality in C#? Currently it zooms in but the crosshair doesn't render correctly when zoomed in nor does the label match where we are drawing when zoomed in when we zoom back out. If we create a label before zooming in it doesn't stay in place where it should be which is part of the problem.

C# Code:
// Zoom
private float zoomFactor = 1.0f;
private const float zoomStep = 0.1f;
private Point zoomCenter = Point.Empty;
private Matrix transformMatrix = new Matrix();

private void ResizeLabel(LabelData label, ResizeHandleType handleType, Point mousePos)
{
int x = label.Rect.X;
int y = label.Rect.Y;
int width = label.Rect.Width;
int height = label.Rect.Height;
switch (handleType)
{
case ResizeHandleType.TopLeft:
width += x - mousePos.X;
height += y - mousePos.Y;
x = mousePos.X;
y = mousePos.Y;
break;
case ResizeHandleType.TopRight:
width = mousePos.X - x;
height += y - mousePos.Y;
y = mousePos.Y;
break;
case ResizeHandleType.BottomLeft:
width += x - mousePos.X;
x = mousePos.X;
height = mousePos.Y - y;
break;
case ResizeHandleType.BottomRight:
width = mousePos.X - x;
height = mousePos.Y - y;
break;
case ResizeHandleType.Left:
width += x - mousePos.X;
x = mousePos.X;
break;
case ResizeHandleType.Right:
width = mousePos.X - x;
break;
case ResizeHandleType.Top:
height += y - mousePos.Y;
y = mousePos.Y;
break;
case ResizeHandleType.Bottom:
height = mousePos.Y - y;
break;
}
label.Rect = new Rectangle(x, y, Math.Max(10, width), Math.Max(10, height));
}
private ResizeHandleType GetResizeHandle(Point mousePos, Rectangle rect)
{
int s = resizeHandleSize;
Rectangle[] handles =
{
new Rectangle(rect.Left - s, rect.Top - s, s 2, s 2), // Top Left
new Rectangle(rect.Right - s, rect.Top - s, s 2, s 2), // Top Right
new Rectangle(rect.Left - s, rect.Bottom - s, s 2, s 2),// Bottom Left
new Rectangle(rect.Right - s, rect.Bottom - s, s 2, s 2),// Bottom Right
new Rectangle(rect.Left - s, rect.Top + rect.Height / 2 - s, s 2, s 2), // Left
new Rectangle(rect.Right - s, rect.Top + rect.Height / 2 - s, s 2, s 2), // Right
new Rectangle(rect.Left + rect.Width / 2 - s, rect.Top - s, s 2, s 2), // Top
new Rectangle(rect.Left + rect.Width / 2 - s, rect.Bottom - s, s 2, s 2) // Bottom
};
ResizeHandleType[] types = { ResizeHandleType.TopLeft, ResizeHandleType.TopRight,
ResizeHandleType.BottomLeft, ResizeHandleType.BottomRight,
ResizeHandleType.Left, ResizeHandleType.Right,
ResizeHandleType.Top, ResizeHandleType.Bottom };
for (int i = 0; i < handles.Length; i++)
{
if (handles[i].Contains(mousePos))
return types[i];
}
return ResizeHandleType.None;
}
private void DrawResizeHandles(Graphics g, Rectangle rect)
{
int s = resizeHandleSize;
Rectangle[] handles =
{
new Rectangle(rect.Left - s, rect.Top - s, s _2, s_ 2), // Top Left
new Rectangle(rect.Right - s, rect.Top - s, s _2, s_ 2), // Top Right
new Rectangle(rect.Left - s, rect.Bottom - s, s _2, s_ 2),// Bottom Left
new Rectangle(rect.Right - s, rect.Bottom - s, s _2, s_ 2),// Bottom Right
new Rectangle(rect.Left - s, rect.Top + rect.Height / 2 - s, s _2, s_ 2), // Left
new Rectangle(rect.Right - s, rect.Top + rect.Height / 2 - s, s _2, s_ 2), // Right
new Rectangle(rect.Left + rect.Width / 2 - s, rect.Top - s, s _2, s_ 2), // Top
new Rectangle(rect.Left + rect.Width / 2 - s, rect.Bottom - s, s _2, s_ 2) // Bottom
};
foreach (var handle in handles)
{
g.FillRectangle(Brushes.Black, handle);
}
}
private void DrawCrosshair(Graphics g)
{
if (cursorPosition == Point.Empty) return;
using Pen crosshairPen = new(crosshairColor, crosshairSize);
// Draw horizontal line
g.DrawLine(crosshairPen, new Point(0, cursorPosition.Y), new Point(LoadedImage.Width, cursorPosition.Y));
// Draw vertical line
g.DrawLine(crosshairPen, new Point(cursorPosition.X, 0), new Point(cursorPosition.X, LoadedImage.Height));
}
// Adjusts a rectangle based on the current zoom transformation
private Rectangle TransformRectangle(Rectangle rect)
{
return new Rectangle(
(int)(rect.X * zoomFactor),
(int)(rect.Y * zoomFactor),
(int)(rect.Width * zoomFactor),
(int)(rect.Height * zoomFactor)
);
}
// Convert mouse coordinates to actual image coordinates
private Point TransformPoint(Point p)
{
return new Point((int)(p.X / zoomFactor), (int)(p.Y / zoomFactor));
}
private void PictureBox_MouseWheel(object sender, MouseEventArgs e)
{
if (Control.ModifierKeys == Keys.Control && LoadedImage.Image != null)
{
float oldZoomFactor = zoomFactor;
if (e.Delta > 0)
zoomFactor *= 1 + zoomStep;
else if (e.Delta < 0)
zoomFactor /= 1 + zoomStep;
// Prevent zooming out beyond the original image size
zoomFactor = Math.Max(1.0f, Math.Min(zoomFactor, 5.0f));
// Calculate zoom center relative to image
zoomCenter = e.Location;
// Update transformation matrix
transformMatrix.Reset();
transformMatrix.Translate(-zoomCenter.X, -zoomCenter.Y, MatrixOrder.Append);
transformMatrix.Scale(zoomFactor, zoomFactor, MatrixOrder.Append);
transformMatrix.Translate(zoomCenter.X, zoomCenter.Y, MatrixOrder.Append);
LoadedImage.Invalidate();
}
}
private void PictureBox_MouseDown(object sender, MouseEventArgs e)
{
if (LoadedImage.Image == null) return;
Point imagePoint = TransformPoint(e.Location);
bool clickedOnLabel = false;
foreach (var label in labels)
{
resizeHandleType = GetResizeHandle(imagePoint, label.Rect);
if (resizeHandleType != ResizeHandleType.None)
{
selectedLabel = label;
isResizing = true;
dragStart = imagePoint;
clickedOnLabel = true;
break;
}
if (label.Rect.Contains(imagePoint))
{
selectedLabel = label;
isDragging = true;
dragStart = imagePoint;
clickedOnLabel = true;
break;
}
}
if (!clickedOnLabel)
{
isDrawing = true;
startPoint = imagePoint;
currentRect = new Rectangle(startPoint, Size.Empty);
selectedLabel = null;
LabelListBox.ClearSelected();
}
}
private void PictureBox_MouseMove(object sender, MouseEventArgs e)
{
cursorPosition = TransformPoint(e.Location);
LoadedImage.Invalidate();
if (isDrawing)
{
currentRect = new Rectangle(
Math.Min(startPoint.X, cursorPosition.X),
Math.Min(startPoint.Y, cursorPosition.Y),
Math.Abs(cursorPosition.X - startPoint.X),
Math.Abs(cursorPosition.Y - startPoint.Y)
);
return;
}
if (selectedLabel == null) return;
if (isResizing)
{
ResizeLabel(selectedLabel, resizeHandleType, TransformPoint(e.Location));
}
else if (isDragging)
{
int dx = cursorPosition.X - dragStart.X;
int dy = cursorPosition.Y - dragStart.Y;
selectedLabel.Rect = new Rectangle(selectedLabel.Rect.X + dx, selectedLabel.Rect.Y + dy,
selectedLabel.Rect.Width, selectedLabel.Rect.Height);
dragStart = cursorPosition;
}
}
private void PictureBox_MouseUp(object sender, MouseEventArgs e)
{
if (isDrawing)
{
isDrawing = false;
if (currentRect.Width > 10 && currentRect.Height > 10)
{
var newLabel = new LabelData { Rect = currentRect, Name = $"Label {labels.Count + 1}" };
labels.Add(newLabel);
LabelListBox.Items.Add(newLabel.Name);
}
}
isDragging = false;
isResizing = false;
}
private void PictureBox_Paint(object sender, PaintEventArgs e)
{
if (LoadedImage.Image == null) return;
e.Graphics.Transform = transformMatrix;
// Draw image
e.Graphics.DrawImage(LoadedImage.Image, new Rectangle(0, 0, LoadedImage.Image.Width, LoadedImage.Image.Height));
// Draw labels at the correct scale
using Pen pen = new(Color.Red, 2 / zoomFactor); // Adjust pen thickness
foreach (var label in labels)
{
Rectangle zoomedRect = TransformRectangle(label.Rect);
e.Graphics.DrawRectangle(pen, zoomedRect);
if (selectedLabel == label)
{
DrawResizeHandles(e.Graphics, zoomedRect);
}
}
// Draw current drawing rectangle correctly scaled
if (isDrawing)
{
Rectangle zoomedRect = TransformRectangle(currentRect);
e.Graphics.DrawRectangle(pen, zoomedRect);
}
DrawCrosshair(e.Graphics);
}

Logs and Screenshots

Browser Console Logs:

Image
Image
Image

Docker Container Logs:
[Include relevant Docker container logs, if applicable]

Screenshots/Screen Recordings (if applicable):

Image
Image

Additional Information

Like I said that is about it, just increased those two params, maybe they were a bit extreme but I'm not really sure.

Note

If the bug report is incomplete or does not follow the provided instructions, it may not be addressed. Please ensure that you have followed the steps outlined in the README.md and troubleshooting.md documents, and provide all necessary information for us to reproduce and address the issue. Thank you!

Originally created by @Babyhamsta on GitHub (Jan 31, 2025). # Bug Report ## Installation Method Pip install (v0.5.7) ## Environment - **Open WebUI Version:** 0.5.7 - **Ollama (if applicable):** 0.5.7 - **Operating System:** Windows 10 - **Browser (if applicable):** Ungoogled Chromium (https://github.com/ungoogled-software/ungoogled-chromium) **Confirmation:** - [x] I have read and followed all the instructions provided in the README.md. - [x] I am on the latest version of both Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below. ## Expected Behavior: Thinking tab should only be created once and should update multiple times with new data/information. ## Actual Behavior: The thinking tab was created for each step I believe. ## Description **Bug Summary:** When asking R1 for some assistance with a bug I was having with C# code. I wanted a larger context length and potential response so I increased the 2 settings num_keep/num_predict. After doing so the AI/UI proceeded to bug out and create many many many thinking tabs. It ran for quite a long time and I didn't allow it finish it's response as it ran longer than 10 minutes. ## Reproduction Details **Steps to Reproduce:** Increase num_keep/num_predict: Num_keep: 1002776 Num_predict: 20000 My exact prompt: ```c# Can you help me fix my zooming functionality in C#? Currently it zooms in but the crosshair doesn't render correctly when zoomed in nor does the label match where we are drawing when zoomed in when we zoom back out. If we create a label before zooming in it doesn't stay in place where it should be which is part of the problem. C# Code: // Zoom private float zoomFactor = 1.0f; private const float zoomStep = 0.1f; private Point zoomCenter = Point.Empty; private Matrix transformMatrix = new Matrix(); private void ResizeLabel(LabelData label, ResizeHandleType handleType, Point mousePos) { int x = label.Rect.X; int y = label.Rect.Y; int width = label.Rect.Width; int height = label.Rect.Height; switch (handleType) { case ResizeHandleType.TopLeft: width += x - mousePos.X; height += y - mousePos.Y; x = mousePos.X; y = mousePos.Y; break; case ResizeHandleType.TopRight: width = mousePos.X - x; height += y - mousePos.Y; y = mousePos.Y; break; case ResizeHandleType.BottomLeft: width += x - mousePos.X; x = mousePos.X; height = mousePos.Y - y; break; case ResizeHandleType.BottomRight: width = mousePos.X - x; height = mousePos.Y - y; break; case ResizeHandleType.Left: width += x - mousePos.X; x = mousePos.X; break; case ResizeHandleType.Right: width = mousePos.X - x; break; case ResizeHandleType.Top: height += y - mousePos.Y; y = mousePos.Y; break; case ResizeHandleType.Bottom: height = mousePos.Y - y; break; } label.Rect = new Rectangle(x, y, Math.Max(10, width), Math.Max(10, height)); } private ResizeHandleType GetResizeHandle(Point mousePos, Rectangle rect) { int s = resizeHandleSize; Rectangle[] handles = { new Rectangle(rect.Left - s, rect.Top - s, s 2, s 2), // Top Left new Rectangle(rect.Right - s, rect.Top - s, s 2, s 2), // Top Right new Rectangle(rect.Left - s, rect.Bottom - s, s 2, s 2),// Bottom Left new Rectangle(rect.Right - s, rect.Bottom - s, s 2, s 2),// Bottom Right new Rectangle(rect.Left - s, rect.Top + rect.Height / 2 - s, s 2, s 2), // Left new Rectangle(rect.Right - s, rect.Top + rect.Height / 2 - s, s 2, s 2), // Right new Rectangle(rect.Left + rect.Width / 2 - s, rect.Top - s, s 2, s 2), // Top new Rectangle(rect.Left + rect.Width / 2 - s, rect.Bottom - s, s 2, s 2) // Bottom }; ResizeHandleType[] types = { ResizeHandleType.TopLeft, ResizeHandleType.TopRight, ResizeHandleType.BottomLeft, ResizeHandleType.BottomRight, ResizeHandleType.Left, ResizeHandleType.Right, ResizeHandleType.Top, ResizeHandleType.Bottom }; for (int i = 0; i < handles.Length; i++) { if (handles[i].Contains(mousePos)) return types[i]; } return ResizeHandleType.None; } private void DrawResizeHandles(Graphics g, Rectangle rect) { int s = resizeHandleSize; Rectangle[] handles = { new Rectangle(rect.Left - s, rect.Top - s, s _2, s_ 2), // Top Left new Rectangle(rect.Right - s, rect.Top - s, s _2, s_ 2), // Top Right new Rectangle(rect.Left - s, rect.Bottom - s, s _2, s_ 2),// Bottom Left new Rectangle(rect.Right - s, rect.Bottom - s, s _2, s_ 2),// Bottom Right new Rectangle(rect.Left - s, rect.Top + rect.Height / 2 - s, s _2, s_ 2), // Left new Rectangle(rect.Right - s, rect.Top + rect.Height / 2 - s, s _2, s_ 2), // Right new Rectangle(rect.Left + rect.Width / 2 - s, rect.Top - s, s _2, s_ 2), // Top new Rectangle(rect.Left + rect.Width / 2 - s, rect.Bottom - s, s _2, s_ 2) // Bottom }; foreach (var handle in handles) { g.FillRectangle(Brushes.Black, handle); } } private void DrawCrosshair(Graphics g) { if (cursorPosition == Point.Empty) return; using Pen crosshairPen = new(crosshairColor, crosshairSize); // Draw horizontal line g.DrawLine(crosshairPen, new Point(0, cursorPosition.Y), new Point(LoadedImage.Width, cursorPosition.Y)); // Draw vertical line g.DrawLine(crosshairPen, new Point(cursorPosition.X, 0), new Point(cursorPosition.X, LoadedImage.Height)); } // Adjusts a rectangle based on the current zoom transformation private Rectangle TransformRectangle(Rectangle rect) { return new Rectangle( (int)(rect.X * zoomFactor), (int)(rect.Y * zoomFactor), (int)(rect.Width * zoomFactor), (int)(rect.Height * zoomFactor) ); } // Convert mouse coordinates to actual image coordinates private Point TransformPoint(Point p) { return new Point((int)(p.X / zoomFactor), (int)(p.Y / zoomFactor)); } private void PictureBox_MouseWheel(object sender, MouseEventArgs e) { if (Control.ModifierKeys == Keys.Control && LoadedImage.Image != null) { float oldZoomFactor = zoomFactor; if (e.Delta > 0) zoomFactor *= 1 + zoomStep; else if (e.Delta < 0) zoomFactor /= 1 + zoomStep; // Prevent zooming out beyond the original image size zoomFactor = Math.Max(1.0f, Math.Min(zoomFactor, 5.0f)); // Calculate zoom center relative to image zoomCenter = e.Location; // Update transformation matrix transformMatrix.Reset(); transformMatrix.Translate(-zoomCenter.X, -zoomCenter.Y, MatrixOrder.Append); transformMatrix.Scale(zoomFactor, zoomFactor, MatrixOrder.Append); transformMatrix.Translate(zoomCenter.X, zoomCenter.Y, MatrixOrder.Append); LoadedImage.Invalidate(); } } private void PictureBox_MouseDown(object sender, MouseEventArgs e) { if (LoadedImage.Image == null) return; Point imagePoint = TransformPoint(e.Location); bool clickedOnLabel = false; foreach (var label in labels) { resizeHandleType = GetResizeHandle(imagePoint, label.Rect); if (resizeHandleType != ResizeHandleType.None) { selectedLabel = label; isResizing = true; dragStart = imagePoint; clickedOnLabel = true; break; } if (label.Rect.Contains(imagePoint)) { selectedLabel = label; isDragging = true; dragStart = imagePoint; clickedOnLabel = true; break; } } if (!clickedOnLabel) { isDrawing = true; startPoint = imagePoint; currentRect = new Rectangle(startPoint, Size.Empty); selectedLabel = null; LabelListBox.ClearSelected(); } } private void PictureBox_MouseMove(object sender, MouseEventArgs e) { cursorPosition = TransformPoint(e.Location); LoadedImage.Invalidate(); if (isDrawing) { currentRect = new Rectangle( Math.Min(startPoint.X, cursorPosition.X), Math.Min(startPoint.Y, cursorPosition.Y), Math.Abs(cursorPosition.X - startPoint.X), Math.Abs(cursorPosition.Y - startPoint.Y) ); return; } if (selectedLabel == null) return; if (isResizing) { ResizeLabel(selectedLabel, resizeHandleType, TransformPoint(e.Location)); } else if (isDragging) { int dx = cursorPosition.X - dragStart.X; int dy = cursorPosition.Y - dragStart.Y; selectedLabel.Rect = new Rectangle(selectedLabel.Rect.X + dx, selectedLabel.Rect.Y + dy, selectedLabel.Rect.Width, selectedLabel.Rect.Height); dragStart = cursorPosition; } } private void PictureBox_MouseUp(object sender, MouseEventArgs e) { if (isDrawing) { isDrawing = false; if (currentRect.Width > 10 && currentRect.Height > 10) { var newLabel = new LabelData { Rect = currentRect, Name = $"Label {labels.Count + 1}" }; labels.Add(newLabel); LabelListBox.Items.Add(newLabel.Name); } } isDragging = false; isResizing = false; } private void PictureBox_Paint(object sender, PaintEventArgs e) { if (LoadedImage.Image == null) return; e.Graphics.Transform = transformMatrix; // Draw image e.Graphics.DrawImage(LoadedImage.Image, new Rectangle(0, 0, LoadedImage.Image.Width, LoadedImage.Image.Height)); // Draw labels at the correct scale using Pen pen = new(Color.Red, 2 / zoomFactor); // Adjust pen thickness foreach (var label in labels) { Rectangle zoomedRect = TransformRectangle(label.Rect); e.Graphics.DrawRectangle(pen, zoomedRect); if (selectedLabel == label) { DrawResizeHandles(e.Graphics, zoomedRect); } } // Draw current drawing rectangle correctly scaled if (isDrawing) { Rectangle zoomedRect = TransformRectangle(currentRect); e.Graphics.DrawRectangle(pen, zoomedRect); } DrawCrosshair(e.Graphics); } ``` ## Logs and Screenshots **Browser Console Logs:** ![Image](https://github.com/user-attachments/assets/39791dd6-9571-421e-9462-dd5c0bbe3c62) ![Image](https://github.com/user-attachments/assets/f5a35cee-7f51-4914-b22f-39ea4c11b8e0) ![Image](https://github.com/user-attachments/assets/03246807-4501-40dd-9842-d87628250479) **Docker Container Logs:** [Include relevant Docker container logs, if applicable] **Screenshots/Screen Recordings (if applicable):** ![Image](https://github.com/user-attachments/assets/a1cb5a74-c4c4-499b-9f4b-c498875649f8) ![Image](https://github.com/user-attachments/assets/fa066fbe-b58b-4aa1-a683-2d3f88d24cf3) ## Additional Information Like I said that is about it, just increased those two params, maybe they were a bit extreme but I'm not really sure. ## Note If the bug report is incomplete or does not follow the provided instructions, it may not be addressed. Please ensure that you have followed the steps outlined in the README.md and troubleshooting.md documents, and provide all necessary information for us to reproduce and address the issue. Thank you!
Author
Owner

@Babyhamsta commented on GitHub (Jan 31, 2025):

Actually I see that I was increasing the wrong ones, should of done Context and num_predict vs keep. But I still wonder why it recreates the think each time.

@Babyhamsta commented on GitHub (Jan 31, 2025): Actually I see that I was increasing the wrong ones, should of done Context and num_predict vs keep. But I still wonder why it recreates the think each time.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#3520