Description
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
Please provide a detailed written description of what you were trying to do, and what you expected llama-cpp-python
to do.
When serializing and deserializing state from a Llama instance, I expect saving and loading to work, regardless of the order of operations, and to emit meaningful exceptions if I break some piece of the usage contract.
Current Behavior
Please provide a detailed written description of what llama-cpp-python
did, instead.
If I create two saved states, and then load the states and start sampling them, loading the smaller of the two states fails with a:
GGML_ASSERT: /tmp/pip-install-xwnycgtq/llama-cpp-python_746970b4bcc64fab88efc2cbfc512184/vendor/llama.cpp/llama.cpp:9183: ctx->logits.capacity() == logits_cap
...if the smaller state is saved before the larger state.
Environment and Context
Please provide detailed information about your computer setup. This is important in case the issue is not reproducible except for under certain specific conditions.
I'm doing all dev work on Ubuntu linux; I've reproduced the issue in WSL2, an Azure VM, and bare metal running both CPU and clBLAS on GPU.
- Physical (or virtual) hardware you are using, e.g. for Linux:
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 39 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Vendor ID: GenuineIntel
Model name: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
CPU family: 6
Model: 140
Thread(s) per core: 2
Core(s) per socket: 4
Socket(s): 1
Stepping: 1
BogoMIPS: 5990.42
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse ss
e2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology tsc_reliable nonstop
_tsc cpuid pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline
_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs
ibpb stibp ibrs_enhanced tpr_shadow vnmi ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi
2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx5
12bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq
avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect flu
sh_l1d arch_capabilities
Virtualization features:
Virtualization: VT-x
Hypervisor vendor: Microsoft
Virtualization type: full
Caches (sum of all):
L1d: 192 KiB (4 instances)
L1i: 128 KiB (4 instances)
L2: 5 MiB (4 instances)
L3: 12 MiB (1 instance)
Vulnerabilities:
Itlb multihit: Not affected
L1tf: Not affected
Mds: Not affected
Meltdown: Not affected
Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling
Srbds: Not affected
Tsx async abort: Not affected
- Operating System, e.g. for Linux:
$ uname -a
Linux [REDACTED] 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
- SDK version, e.g. for Linux:
$ python3 --version
$ make --version
$ g++ --version
Python 3.10.12
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Failure Information (for bugs)
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
Steps to Reproduce
Please provide detailed steps for reproducing the issue. We are not sitting in front of your screen, so the more detail the better.
My example uses the mistralite model because the prompt format is short, but the issue appears on every model I've tried.
from llama_cpp import Llama
modelPath = "../mistrallite.Q4_K_M.gguf"
stopTokens = []
template="<|prompter|>{user_prompt}</s><|assistant|>"
llm = Llama(
model_path=modelPath, n_gpu_layers=-1, n_threads=4, numa=False, n_ctx=2048
)
hot_temperature = 0.9
cold_temperature = 0.1
max_url_content_length = 4096
def askTheQuestion(in_state, prompt):
llm.load_state(in_state)
print("Loaded state.")
llm.eval(llm.tokenize(" {prompt}</s><|assistant|> ".format(prompt=prompt).encode()))
print("Tokenized.")
token = llm.sample()
while token is not llm.token_eos() :
print(llm.detokenize([token]).decode(), end='', flush=True)
llm.eval([token])
token = llm.sample()
print("")
def createState(prefix) :
llm.reset()
llm.eval(llm.tokenize(prefix.encode()))
return llm.save_state()
first_state = createState("<|prompter|>You are a superhero named Fred. You live in Metropolis. Your nemesis is Lex Luthor. Everyone thinks you're Superman, but you're a different hero that wishes he could be recognized on his own merits.");
print("Saved First State")
second_state = createState("<|prompter|>You are a hobbit named Barney that lives in the shire.");
print("Saved Second State")
askTheQuestion(first_state, "What is happening today?")
askTheQuestion(first_state, "What is your dream?")
askTheQuestion(first_state, "What is happening today?")
# failure happens on the line below.
askTheQuestion(second_state, "What is happening today?")
askTheQuestion(second_state, "What is your favourite thing?")
As written above, the code works. If the order of creation of the first and second states is reversed, the assert fails when trying to load the second state.
Failure Logs
Success log:
llama_model_loader: loaded meta data with 21 key-value pairs and 291 tensors from ../mistrallite.Q4_K_M.gguf (version GGUF V2)
llama_model_loader: - tensor 0: token_embd.weight q4_K [ 4096, 32003, 1, 1 ]
llama_model_loader: - tensor 1: blk.0.attn_q.weight q4_K [ 4096, 4096, 1, 1 ]
[SNIP]
...............................................................................................
llama_new_context_with_model: n_ctx = 2048
llama_new_context_with_model: freq_base = 1000000.0
llama_new_context_with_model: freq_scale = 1
llama_new_context_with_model: kv self size = 256.00 MiB
llama_build_graph: non-view tensors processed: 740/740
llama_new_context_with_model: compute buffer total size = 159.07 MiB
AVX = 1 | AVX2 = 1 | AVX512 = 1 | AVX512_VBMI = 1 | AVX512_VNNI = 1 | FMA = 1 | NEON = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 |
Llama.save_state: saving llama state
Llama.save_state: got state size: 276054512
Llama.save_state: allocated state
Llama.save_state: copied llama state: 15376356
Llama.save_state: saving 15376356 bytes of llama state
Saved First State
Llama.save_state: saving llama state
Llama.save_state: got state size: 276054512
Llama.save_state: allocated state
Llama.save_state: copied llama state: 10788696
Llama.save_state: saving 10788696 bytes of llama state
Saved Second State
Loaded state.
Tokenized.
Today is your day off.
Loaded state.
Tokenized.
To one day have the world recognize that there are more than just one superhero and for people to appreciate the work of all the heroes out there.
Loaded state.
Tokenized.
Today is your day off.
Loaded state.
Tokenized.
You woke up late for work and will be late
Loaded state.
Tokenized.
Food and drink
Failure log:
llama_model_loader: loaded meta data with 21 key-value pairs and 291 tensors from ../mistrallite.Q4_K_M.gguf (version GGUF V2)
llama_model_loader: - tensor 0: token_embd.weight q4_K [ 4096, 32003, 1, 1 ]
[SNIP]
...............................................................................................
llama_new_context_with_model: n_ctx = 2048
llama_new_context_with_model: freq_base = 1000000.0
llama_new_context_with_model: freq_scale = 1
llama_new_context_with_model: kv self size = 256.00 MiB
llama_build_graph: non-view tensors processed: 740/740
llama_new_context_with_model: compute buffer total size = 159.07 MiB
AVX = 1 | AVX2 = 1 | AVX512 = 1 | AVX512_VBMI = 1 | AVX512_VNNI = 1 | FMA = 1 | NEON = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 |
Llama.save_state: saving llama state
Llama.save_state: got state size: 271574092
Llama.save_state: allocated state
Llama.save_state: copied llama state: 6308276
Llama.save_state: saving 6308276 bytes of llama state
Saved Second State
Llama.save_state: saving llama state
Llama.save_state: got state size: 276054512
Llama.save_state: allocated state
Llama.save_state: copied llama state: 15376356
Llama.save_state: saving 15376356 bytes of llama state
Saved First State
Loaded state.
Tokenized.
You are being interviewed by the Daily Planet.
Loaded state.
Tokenized.
To be a famous superhero
Loaded state.
Tokenized.
You are being interviewed by the Daily Planet.
GGML_ASSERT: /tmp/pip-install-xwnycgtq/llama-cpp-python_746970b4bcc64fab88efc2cbfc512184/vendor/llama.cpp/llama.cpp:9183: ctx->logits.capacity() == logits_cap