Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Multiple calls to create_chat_completion() fail with "llama_decode: failed to decode, ret = -1"

Đang mở
#2,140 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
ai, backend-api-design

Hướng nghiên cứu

Issue nằm trong phương thức create_chat_completion của lớp llama_cpp.Llama. Hãy xem mã nguồn của phương thức đó và các C++ bindings bên dưới để hiểu context và KV cache được quản lý như thế nào giữa các lần gọi. Người dùng phát hiện rằng gọi llm.reset() hoặc llm._ctx.kv_cache_clear() có tác dụng, vì vậy bản sửa có thể sẽ liên quan đến việc tự động reset state sau một completion. Kiểm tra test suite để tìm các pattern tương tự. “Hoàn tất” là khi hai lần gọi create_chat_completion liên tiếp đều thành công mà không cần reset thủ công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest code. Development is very rapid so there are no tagged versions as of now.
  • I carefully followed the README.md.
  • I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
  • I reviewed the Discussions, and have a new bug or useful enhancement to share.

Expected Behavior

I am running LiquidAI's LFM2.5-1.2B-Instruct model. Calling create_chat_completion() multiple times should not throw error.

Current Behavior

When trying to call create_chat_completion twice in a row, the model throws error "llama_decode: failed to decode, ret = -1"

Environment and Context

I am using llama-cpp-python v0.3.16. Python version is 3.13.9.

  • Windows 11

Failure Information (for bugs)

On tracing back the issue, it looks like there needs to be a context and cache reset after each chat_completion call, which isn't happening yet.

Steps to Reproduce


from pathlib import Path
from llama_cpp import Llama
llm = Llama(
    model_path=str(Path.home() / "AppData/Local/llama.cpp/LiquidAI_LFM2.5-1.2B-Instruct-GGUF_LFM2.5-1.2B-Instruct-Q4_K_M.gguf"),
    n_ctx=1000
)

system_prompt = """
\nYou are a helpful assistant
"""
prompt = """
suggest me places to visit during winter season
"""
response = llm.create_chat_completion(
      messages =  [{"role": "system", "content": system_prompt}, {"role": "user", "content": prompt}],
)
print(response)
# llm.reset()                                               # Using this works
# llm._ctx.kv_cache_clear()                        # Using this works
response = llm.create_chat_completion(
      messages =  [{"role": "system", "content": system_prompt}, {"role": "user", "content": prompt}],
)
print(response)

Failure Logs

init: the tokens of sequence 0 in the input batch have inconsistent sequence positions:
 - the last position stored in the memory module of the context (i.e. the KV cache) for sequence 0 is X = 519
 - the tokens for sequence 0 in the input batch have a starting position of Y = 29
 it is required that the sequence positions remain consecutive: Y = X + 1
decode: failed to initialize batch
llama_decode: failed to decode, ret = -1
Ngôn ngữ chính
Python
Star
10.6k
Fork
1.5k
Merge trung bình
3 giờ 57 phút
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của abetlen/llama-cpp-python

Tất cả issue của abetlen/llama-cpp-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.