Skip to content

fix(llama): mark seven llama_sampler_init_* bindings positional-only - #2372

Open
Belal0066 wants to merge 2 commits into
abetlen:mainfrom
Belal0066:fix/sampler-init-positional-only
Open

Belal0066 wants to merge 2 commits into
abetlen:mainfrom
Belal0066:fix/sampler-init-positional-only

Conversation

@Belal0066

Copy link
Copy Markdown

Fixes #2371.

ctypes function objects built without paramflags only bind arguments positionally, but functools.wraps copies each def's type-hinted signature onto them anyway, so a keyword call type-checks fine but either raises a confusing TypeError or silently drops an argument at runtime.

  • Mark llama_sampler_init_dist, _top_k, _top_p, _min_p, _typical, _temp, and _temp_ext positional-only with a trailing /, matching every other binding in llama_cpp.py.
  • Checked all 239 @ctypes_function bindings in the file; these seven were the only ones missing it.
  • Regression tests cover both cases, including one documenting that this closes the static-typing gap only — the ctypes-level silent drop is unaffected.

ctypes function objects built without paramflags only bind arguments
positionally, but functools.wraps copies each def's type-hinted
signature onto them anyway, so the public signature looks
keyword-friendly even though calling by keyword either raises a
confusing TypeError or silently drops an argument at the ctypes layer.

Every other ctypes_function binding in this file already guards
against this with a trailing `/`. llama_sampler_init_dist, _top_k,
_top_p, _min_p, _typical, _temp, and _temp_ext were missed; this was
the only class of binding in the file without it.

Closes abetlen#2371
Covers the seven bindings fixed for abetlen#2371: each gets a test confirming
a keyword call that's short on positional arguments is rejected
outright with TypeError.

Also adds one test documenting a related but unfixed case: once every
positional slot is already filled, ctypes silently ignores an extra
keyword instead of raising. Positional-only marking can't close that,
since there's no unfilled slot left for it to protect.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Seven llama_sampler_init_* bindings admit keyword arguments that the ctypes function object silently drops

1 participant