File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -436,12 +436,19 @@ def encode(self, batch: LlamaBatch):
436436 raise RuntimeError (f"llama_encode returned { return_code } " )
437437
438438 def decode (self , batch : LlamaBatch ):
439- return_code = llama_cpp .llama_decode (
440- self .ctx ,
441- batch .batch ,
442- )
443- if return_code != 0 :
444- raise RuntimeError (f"llama_decode returned { return_code } " )
439+ return_code = llama_cpp .llama_decode (self .ctx , batch .batch )
440+
441+ if return_code == 0 :
442+ return
443+
444+ error_map = {
445+ 1 : "No KV slot available: try reducing batch size or increasing context window" ,
446+ 2 : "Decoding aborted" ,
447+ - 1 : "Invalid input batch" ,
448+ }
449+
450+ msg = error_map .get (return_code , "Fatal internal error" )
451+ raise RuntimeError (f"llama_decode failed (code { return_code } ): { msg } " )
445452
446453 def set_n_threads (self , n_threads : int , n_threads_batch : int ):
447454 llama_cpp .llama_set_n_threads (self .ctx , n_threads , n_threads_batch )
You can’t perform that action at this time.
0 commit comments