Llama.embed() calls LlamaBatch.add_sequence with old 3-arg signature; missing logits_array
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 65/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- python
調査の方向性
Issue は llama_cpp/llama.py の 1678 行目付近にあり、Llama.embed() が 3 つの引数で _batch.add_sequence を呼び出しています。llama_cpp/llama_embedding.py の 262 行目付近にある、4 つの引数を使った正しい呼び出しと比較してください。トークン配列、位置配列、シーケンス ID、logits 配列を使用して、シグネチャに一致するよう呼び出しを更新してください。embeddings をサポートするモデルで、提供されている再現スクリプトを実行してテストしてください。
索引モデルが issue の本文から書いたものです。
説明
Prerequisites
- 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
Llama.embed() should successfully compute embeddings when called on a model constructed with embeddings=True.
Current Behavior
Llama.embed() raises a TypeError immediately, before any embedding is computed:
TypeError: LlamaBatch.add_sequence() missing 1 required positional argument: 'logits_array'
The cause: Llama.embed() in llama_cpp/llama.py (around line 1678) calls add_sequence with three positional arguments:
self._batch.add_sequence(tokens, p_batch, logits_all)
But LlamaBatch.add_sequence in llama_cpp/_internals.py (around line 1013) requires four:
def add_sequence(
self,
token_array: Sequence[int],
pos_array: Sequence[int],
seq_ids: Sequence[Sequence[int]],
logits_array: Sequence[bool]
)
llama_cpp/llama_embedding.py (around line 262) already calls add_sequence correctly with the four-arg shape — the call site in Llama.embed() was apparently missed during the LlamaBatch.add_sequence refactor.
Environment and Context
- Hardware: x86_64, NVIDIA GeForce RTX 4090
- OS: Windows 10 22H2
- Python 3.12.9
- llama-cpp-python 0.3.36 (CUDA 12.8 prebuilt wheel)
$ python --version
Python 3.12.9
$ pip show llama-cpp-python | findstr Version
Version: 0.3.36
Failure Information (for bugs)
This is a clean regression — LlamaBatch.add_sequence was refactored from a 3-arg signature to a 4-arg one, and the call sites were updated everywhere except in Llama.embed(). llama_embedding.py shows what the new shape should look like for the embedding code path.
Steps to Reproduce
from llama_cpp import Llama
m = Llama(model_path="path/to/model.gguf", embeddings=True)
m.embed("hello")
Result:
TypeError: LlamaBatch.add_sequence() missing 1 required positional argument: 'logits_array'
Failure Logs
Traceback (most recent call last):
File "...\Lib\site-packages\llama_cpp\llama.py", line 1678, in embed
self._batch.add_sequence(tokens, p_batch, logits_all)
TypeError: LlamaBatch.add_sequence() missing 1 required positional argument: 'logits_array'
Suggested fix
Mirror the call shape already used in llama_cpp/llama_embedding.py:
# In llama.py Llama.embed(), replace:
self._batch.add_sequence(tokens, p_batch, logits_all)
# With something like:
self._batch.add_sequence(
token_array=tokens,
pos_array=list(range(len(tokens))),
seq_ids=[p_batch],
logits_array=[True] * len(tokens) if logits_all else [False] * (len(tokens) - 1) + [True],
)
Workaround
Monkey-patching LlamaBatch.add_sequence to detect 3-arg legacy calls and synthesize the missing pos_array works as a stopgap. Hit while running Tencent's HY-Motion text-to-motion model, whose text encoder uses Llama.embed() against GGUF Qwen3 weights.
- 主要言語
- Python
- スター
- 10.6k
- フォーク
- 1.5k
- 平均マージ
- 6時間 43分
- マージ済み PR(30日)
- 2
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
abetlen/llama-cpp-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
abetlen/llama-cpp-python#2371 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
abetlen/llama-cpp-python#2352 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
abetlen/llama-cpp-python#2210 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
abetlen/llama-cpp-python#2145 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
abetlen/llama-cpp-python#2135 · リアクション 4 件 ·
abetlen/llama-cpp-python の issue をすべて見る
似ている issue
-
essnmx good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
-
[Feature] 奇物选择添加优先级 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
syfoud/Simulated_Scepter#174 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Giskard-AI/giskard-oss#2840 · コメント 1 件 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success オープンarea: repo bug perceived difficulty: 2
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
yeti-platform/yeti#1380 ·