Seven llama_sampler_init_* bindings admit keyword arguments that the ctypes function object silently drops
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 88/100
Rechercherichtung
Beginne in llama_cpp/llama_cpp.py bei den sieben Definitionen von llama_sampler_init_* ungefähr in den Zeilen 4553-4606 und lies dann ctypes_function in llama_cpp/_ctypes_extensions.py:146-152, um zu bestätigen, wie die exportierten Funktionen erstellt werden. Mache die sieben Binding-Parameter positional-only, entsprechend den umgebenden Definitionen, und überprüfe, dass ihre Signaturen nicht mehr zu Aufrufen mit Schlüsselwortargumenten einladen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
In llama_cpp/llama_cpp.py, seven bindings are declared as defs whose parameters are NOT
positional-only, while every other decorated binding in the file uses /:
line (main d736646) |
def |
|---|---|
| 4553 | def llama_sampler_init_dist(seed: int) -> llama_sampler_p |
| 4560 | def llama_sampler_init_top_k(k: int) -> llama_sampler_p |
| 4570 | def llama_sampler_init_top_p(p: float, min_keep: int) -> llama_sampler_p |
| 4580 | def llama_sampler_init_min_p(p: float, min_keep: int) -> llama_sampler_p |
| 4590 | def llama_sampler_init_typical(p: float, min_keep: int) -> llama_sampler_p |
| 4596 | def llama_sampler_init_temp(t: float) -> llama_sampler_p |
| 4606 | def llama_sampler_init_temp_ext(t: float, delta: float, exponent: float) -> llama_sampler_p |
ctypes_function (llama_cpp/_ctypes_extensions.py:146-152) replaces the def with the
ctypes function object:
def decorator(f):
if enabled:
func = getattr(lib, name)
func.argtypes = argtypes
func.restype = restype
functools.wraps(f)(func)
return func
so the name the module exports IS getattr(lib, "llama_sampler_init_top_k"). A ctypes
function object without paramflags binds no argument by name, but functools.wraps and
the (f: F) -> F typing make inspect.signature, pyright and IDEs show the def's
signature — which invites keyword calls the object cannot honour.
What happens (CPython 3.12.10, ctypes)
>>> import ctypes; lib = ctypes.CDLL(None); f = lib.abs
>>> f.argtypes = [ctypes.c_int]; f.restype = ctypes.c_int
>>> f(-3, x=1) # an extra keyword is DROPPED silently
3
>>> f(x=-3) # all-keyword: refused
TypeError: this function takes at least 1 argument (0 given)
Applied to these bindings:
llama_sampler_init_top_k(k=40)— type-checks clean, raisesTypeErrorat run time.llama_sampler_init_top_p(0.9, min_keep=2)— type-checks clean, runs, and passes ONE
positional to a two-parameter C function:min_keepis silently dropped and the C side
reads whatever the register/stack held for it.
No caller inside the repository is affected today (_internals.py:705-732 and the server
pass positionals), so this is a latent API hazard rather than a current bug — but the
signature is public and the failure is invisible to every static check.
Fix
Make the seven defs positional-only, as the other bindings already are:
def llama_sampler_init_top_k(k: int, /) -> llama_sampler_p: ...
(Alternatively, build the functions through a CFUNCTYPE prototype with paramflags,
which does bind by name — but the one-character fix matches the file's convention.)
Found with SemLinker, a cross-language contract checker we are developing; happy to send a PR.
- Vorherrschende Sprache
- Python
- Sterne
- 10.6k
- Forks
- 1.5k
- Ø Merge
- 3 Std. 57 Min.
- Gemergte PRs (30 T.)
- 4
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus abetlen/llama-cpp-python
-
uv add llama-cpp-python wheels fails for versions above 0.3.30Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
abetlen/llama-cpp-python#2352 · 1 Kommentar · 2 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
-
Docs: consolidate build-from-source and GPU backend guideEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
abetlen/llama-cpp-python#2314 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Llama.embed() calls LlamaBatch.add_sequence with old 3-arg signature; missing logits_arrayEvtl. wieder frei @lxcxjxhx hat das vor 95 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
abetlen/llama-cpp-python#2211 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Llama() silently accepts and discards `embedding` kwarg; .embed() then raises confusinglyEvtl. vergeben @Anai-Guo hat das vor 36 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
abetlen/llama-cpp-python#2210 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Improve error messagesEvtl. vergeben @Anai-Guo hat das vor 173 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
abetlen/llama-cpp-python#2145 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in abetlen/llama-cpp-python
Ähnliche Issues
-
feedback simulation workshop
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 73/100
githubnext/gh-aw-workshop#4455 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Triage 🩺
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
[BUG] Container scenario crashes without expected_recovery_time, kube DNS example uses retry_waitOffenneeds-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
krkn-chaos/krkn#1627 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
NousResearch/hermes-agent#136483 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag