Fix ABI fragility: compile bindings against the real llama.h instead of hand-copied ctypes structs
llama_capi.py previously hand-copied struct field order/types from one specific llama.cpp commit's llama.h into Python ctypes Structures. A different llama.cpp build could silently reorder or resize those fields and corrupt memory rather than raising any error. Replaced with a cffi "API mode" extension (build_capi.py) that #includes the user's actual llama.h and links against their actual libllama.so. Struct layout now comes from real compilation - a genuinely incompatible field fails the build loudly instead of corrupting memory at runtime. Verified byte-for-byte identical generation output against the prior ctypes implementation at a fixed seed, plus the fork/peek logit round-trip check (0.000000 max diff). Requires a one-time `python build_capi.py` setup step (needs a C compiler, which building llama.cpp itself already requires).
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -3,6 +3,13 @@ __pycache__/
|
||||
*.log
|
||||
.claude/
|
||||
|
||||
# Compiled by build_capi.py against your local llama.cpp - machine/build
|
||||
# specific, not something to commit.
|
||||
_llama_cffi.c
|
||||
_llama_cffi.o
|
||||
_llama_cffi*.so
|
||||
build/
|
||||
|
||||
# Generated during test/dev sessions, not part of the tool itself
|
||||
resume.txt
|
||||
Prompt-response.txt
|
||||
|
||||
Reference in New Issue
Block a user