Closed USGZVReB9cJ6Crcp8CXHcR closed 5 months ago
Update: I was able to confirm over the weekend that this issue is not related to CPU/GPU, nor to the servlet or core functionality. Rather it seems related to this:
I was able to confirm that if I run the exact same request, but without an grammar constraint, i.e., response_format=None
, then the process never stalls or hangs, even across several thousand requests, whereas with the JSON format constraint included it will always fail, typically within 10-20 requests, and always before we hit 100 iterations.
Just to add a bit more here. The 'hanging' decodes for JSON format responses do eventually return, but the times are exhorbitant. Always using the same example, the 'average' on my machine is about 5s per request. However when it gets 'stuck', this balloons to 34 min.
AVERAGE
llama_print_timings: load time = 1101.40 ms
llama_print_timings: sample time = 319.11 ms / 31 runs ( 10.29 ms per token, 97.15 tokens per second)
llama_print_timings: prompt eval time = 1101.01 ms / 147 tokens ( 7.49 ms per token, 133.51 tokens per second)
llama_print_timings: eval time = 3397.84 ms / 30 runs ( 113.26 ms per token, 8.83 tokens per second)
llama_print_timings: total time = 4914.17 ms / 177 tokens
TIME: ~5sec
PROBLEM
llama_print_timings: load time = 1103.95 ms
llama_print_timings: sample time = 105427.67 ms / 14150 runs ( 7.45 ms per token, 134.22 tokens per second)
llama_print_timings: prompt eval time = 1103.56 ms / 147 tokens ( 7.51 ms per token, 133.21 tokens per second)
llama_print_timings: eval time = 1790583.72 ms / 14149 runs ( 126.55 ms per token, 7.90 tokens per second)
llama_print_timings: total time = 2057352.09 ms / 14296 tokens
TIME: 34min
I was able to resolve this finally. The issue was essentially user error on my part. I was providing a grammar like:
{
"type": "json_object",
"properties": {
"first_name": {
"type": "string"
},
"birthplace": {
"type": "string"
},
"last_name": {
"type": "string"
}
},
"required": ["first_name", "last_name", "birthplace"]
}
but I needed to provide a grammar like:
{
"type": "json_object",
"schema": {
"type": "object",
"properties": {
"first_name": {
"type": "string",
"minLength": 2
},
"birthplace": {
"type": "string",
"minLength": 2,
"maxLength": 10
},
"last_name": {
"type": "string",
"minLength": 2
}
},
"required": ["first_name", "last_name", "birthplace"]
}
}
particularly, I needed to provide the top-level additional schema
key, and the additional "type" : "object"
under that. I think what threw me off was that it seemed to 'mostly work' until it froze up, and this lead me to believe that there was something more fundamental going wrong at a lower level. I also note that, initially I was not making this error, and it is indeed correctly explained in the documentation (https://llama-cpp-python.readthedocs.io/en/latest/#json-schema-mode). So it was definitely my fault.
Interesting to note that the parser still tried, and succeeded in producing a convoluted parse of the half-broken object I was providing, and this then worked repeatedly "until it didn't". Maybe it would make sense to try and run a quick validation of the object first before sending it to the parser/converter? Or insist on the "schema" key?
Closing this with the self-admonishment: be careful!
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Expected Behavior
Please provide a detailed written description of what you were trying to do, and what you expected
llama-cpp-python
to do.I have installed the latest source (commit 165b4dc6c188f8fda2fc6161). In order to minimize confusion, I compiled with CPU only support:
I then attempted to build a minimal servlet of my own:
I run this server with:
then I call it via curl with:
where my request looks like:
the first couple of requests work fine and return the expected result. However inevitably, after 3, or 5 or 15 or sometimes 40 requests the servlet will just hang. What am I missing here?
Current Behavior
Please provide a detailed written description of what
llama-cpp-python
did, instead.After 3, 5, 15, 30 requests - different each time, the server will simply stop responding and the final result will hang. I have tried switching the GPU on and off, I have tried immitating the async and run_in_threadpool configuration in the main llama_cpp_python server lib, and using the context reset, and a variety of other things all to no avail. I assume I must need to reset something but I cannot figure it out.
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.
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.