Skip to content

RKLLM backend uses NPU correctly after rkllama#4 fix, but model enters an unexpected generation loop #1740

Description

@mandresve

Environment

  • Version: beta.35 / latest testing branch
  • Platform: Orange Pi 5 Pro (RK3588, 16GB)
  • OS: Debian 12 (Bookworm) ARM64
  • Backend: rkllama with manual application of rkllama#4 fix
  • Model tested: qwen2.5-1.5b-rkllm

Description

After applying the fix from rkllama#4 manually, the RKLLM backend is now correctly using the NPU and inference starts successfully.

This confirms that the previous backend initialization issues are resolved.

However, when running a taOS Agent instance with qwen2.5-1.5b-rkllm, the model appears to enter an unexpected generation loop. The generated output does not correspond to the user prompt and instead starts producing unrelated task/planning text repeatedly.

This behavior appears to be generated by the model itself rather than a backend availability issue.

Steps to Reproduce

  1. Apply the rkllama#4 fix manually.
  2. Start taOS Agent.
  3. Select qwen2.5-1.5b-rkllm.
  4. Send a simple prompt: "Test"
  5. Observe the generated response.

Expected Behavior

  • The model should return a normal response to the user prompt.
  • For a simple prompt like "Test" the model should generate a short conversational response.

Actual Behavior

  • The backend successfully receives the request.
  • RKLLM starts inference.
  • NPU execution works.
  • The request returns HTTP 200.
  • However, the model generates unrelated structured task output and appears to continue an internal workflow instead of answering the prompt.

The output resembles an agent/task state template, for example:

  • Objective
  • Important Details
  • Work State
  • Completed
  • Active
  • Blocked
  • Next Move

This continues until the context limit is reached.

Additional Observations

The backend reports that the prompt size exceeds the model context window: Prompt is 11543 tokens but the model context window is 4096 tokens. Later requests also show large prompt sizes.

This may indicate that:

  • taOS Agent is sending an unexpectedly large system prompt/history.
  • The model context configuration is not aligned with the model capabilities.
  • The model is receiving an agent-oriented prompt format that is incompatible with this specific RKLLM conversion.

Current Status

The following issues appear resolved:

  • RKLLM backend starts correctly.
  • NPU is detected and used.
  • Model inference executes successfully.

The remaining issue seems to be related to the interaction between:

  • taOS Agent prompt formatting
  • model context size
  • qwen2.5-1.5b-rkllm behavior

Logs

Jul 08 09:00:47 orangepi5pro python[1272]: 2026-07-08 09:00:47,702 - rkllama.worker - INFO - Worker for model qwen2.5-1.5b-rkllm created and running...
Jul 08 09:00:48 orangepi5pro python[1272]: 2026-07-08 09:00:48,465 - rkllama.server_utils - WARNING - Prompt is 11543 tokens but the model context window is 4096 tokens. Reduce the prompt or conversation history, or increase num_>
Jul 08 09:00:48 orangepi5pro python[1272]: 2026-07-08 09:00:48,466 - werkzeug - INFO - 127.0.0.1 - - [08/Jul/2026 09:00:48] "POST /api/chat HTTP/1.1" 400 -
Jul 08 09:00:50 orangepi5pro python[1272]: 2026-07-08 09:00:50,182 - rkllama.server_utils - WARNING - Prompt is 11543 tokens but the model context window is 4096 tokens. Reduce the prompt or conversation history, or increase num_>
Jul 08 09:00:50 orangepi5pro python[1272]: 2026-07-08 09:00:50,183 - werkzeug - INFO - 127.0.0.1 - - [08/Jul/2026 09:00:50] "POST /api/chat HTTP/1.1" 400 -
Jul 08 09:00:52 orangepi5pro python[1272]: 2026-07-08 09:00:52,649 - rkllama.server_utils - WARNING - Prompt is 11543 tokens but the model context window is 4096 tokens. Reduce the prompt or conversation history, or increase num_>
Jul 08 09:00:52 orangepi5pro python[1272]: 2026-07-08 09:00:52,649 - werkzeug - INFO - 127.0.0.1 - - [08/Jul/2026 09:00:52] "POST /api/chat HTTP/1.1" 400 -
Jul 08 09:00:55 orangepi5pro python[2902]: 2026-07-08 09:00:55,893 - rkllama.worker - INFO - Running inference for model qwen2.5-1.5b-rkllm...
Jul 08 09:00:55 orangepi5pro python[2902]: 2026-07-08 09:00:55,894 - rkllama.rkllm - WARNING - Not found expected prompt cache file for fast inference: /root/rkllama/models/qwen2.5-1.5b-rkllm/cache/AHZ1dJl-E6lK3ZcCP9AMeS9tNF3PDQQ>
Jul 08 09:00:57 orangepi5pro python[2902]: I rkllm: saved prompt cache to /root/rkllama/models/qwen2.5-1.5b-rkllm/cache/AHZ1dJl-E6lK3ZcCP9AMeS9tNF3PDQQgQw5CSI9TNKQ_005
Jul 08 09:00:57 orangepi5pro python[2902]: ##
Jul 08 09:00:57 orangepi5pro python[1272]: 2026-07-08 09:00:57,435 - werkzeug - INFO - 127.0.0.1 - - [08/Jul/2026 09:00:57] "POST /api/chat HTTP/1.1" 200 -
Jul 08 09:00:57 orangepi5pro python[2902]:  Objective
Jul 08 09:00:58 orangepi5pro python[2902]: - [Create a new function to generate JSON data based on input parameters.]
Jul 08 09:01:42 orangepi5pro python[2902]: ## Important Details
Jul 08 09:01:42 orangepi5pro python[2902]: - (none)
Jul 08 09:01:43 orangepi5pro python[2902]: ## Work State
Jul 08 09:01:43 orangepi5pro python[2902]: ### Completed
Jul 08 09:01:44 orangepi5pro python[2902]: - The initial version of the function successfully generates a single sample JSON object.
Jul 08 09:01:45 orangepi5pro python[2902]: - However, it lacks comprehensive error handling and validation checks.
Jul 08 09:01:45 orangepi5pro python[2902]: ### Active
Jul 08 09:01:46 orangepi5pro python[2902]: - Current code snippet for generating JSON data is ready.
Jul 08 09:01:46 orangepi5pro python[2902]: ### Blocked
Jul 08 09:01:47 orangepi5pro python[2902]: -
Jul 08 09:01:47 orangepi5pro python[1272]: 2026-07-08 09:01:47,091 - werkzeug - INFO - 127.0.0.1 - - [08/Jul/2026 09:01:47] "GET /api/tags HTTP/1.1" 200 -
Jul 08 09:01:47 orangepi5pro python[2902]:  There are no known blockages
Jul 08 09:01:47 orangepi5pro python[1272]: 2026-07-08 09:01:47,571 - werkzeug - INFO - 127.0.0.1 - - [08/Jul/2026 09:01:47] "GET /api/tags HTTP/1.1" 200 -
Jul 08 09:01:48 orangepi5pro python[2902]:  preventing the process from continuing.
Jul 08 09:01:48 orangepi5pro python[2902]: ### Next Move
Jul 08 09:01:50 orangepi5pro python[2902]: 1. Implement comprehensive error handling to manage potential issues such as invalid input or network errors during data retrieval.
Jul 08 09:01:52 orangepi5pro python[2902]: 2. Add additional validation logic to ensure the generated JSON adheres to specific schema requirements for all possible scenarios.
Jul 08 09:01:52 orangepi5pro python[2902]: 2026-07-08 09:01:52,056 - rkllama.worker - INFO - Clearing KV cache for model qwen2.5-1.5b-rkllm...
Jul 08 09:01:53 orangepi5pro python[1272]: 2026-07-08 09:01:53,009 - rkllama.server_utils - WARNING - Prompt is 7849 tokens but the model context window is 4096 tokens. Reduce the prompt or conversation history, or increase num_ctx.
...
...
(endless loop)

Metadata

Metadata

Assignees

No one assigned

    Labels

    kilo-triagedAuto-generated label by Kilo

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions