Skip to content

Commit 76bda5a

Browse files
authored
Merge pull request #165 from danielferr85/main
Improvements in Expiration Date for models in long inference sessions
2 parents 3a283ff + 3357698 commit 76bda5a

5 files changed

Lines changed: 42 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# RKLLama: LLM Server and Client for Rockchip 3588/3576
22

3-
### [Version: 0.0.74](#New-Version)
3+
### [Version: 0.0.75](#New-Version)
44

55
Video demo ( version 0.0.1 ):
66

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "rkllama"
3-
version = "0.0.74"
3+
version = "0.0.75"
44
authors = [
55
{ name="NotPunchnox", email="punchnoxpro@gmail.com" },
66
{ name="TomJacobsUK", email="tom@tomjacobs.co.uk" },

src/rkllama/api/server_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ def generate():
342342
while not thread_finished or not final_sent:
343343
if parent_pipe.poll(timeout): # Timeout in seconds
344344
token = parent_pipe.recv()
345+
346+
# Updating expiration date for the model during token generation to prevent expiration
347+
variables.worker_manager_rkllm.update_expiration_date_for_model(model_name)
348+
345349
else:
346350
# Abort the current inference
347351
variables.worker_manager_rkllm.workers[model_name].abort_flag.value = True
@@ -704,6 +708,10 @@ def generate():
704708
while not thread_finished or not final_sent:
705709
if parent_pipe.poll(timeout): # Timeout in seconds
706710
token = parent_pipe.recv()
711+
712+
# Updating expiration date for the model during token generation to prevent expiration
713+
variables.worker_manager_rkllm.update_expiration_date_for_model(model_name)
714+
707715
else:
708716
# Abort the current inference
709717
variables.worker_manager_rkllm.workers[model_name].abort_flag.value = True

src/rkllama/api/worker.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,18 +1062,37 @@ def send_task(self, model_name, task):
10621062
# Send the TASK to the model with the task queue and the pipe to send the response
10631063
self.workers[model_name].task_queue.put((child_conn,) + task)
10641064

1065-
# CLose the not needed connection
1066-
# child_conn.close()
1067-
10681065
# Update the worker model info with the invocation
1069-
self.workers[model_name].worker_model_info.last_call = datetime.now()
1070-
self.workers[model_name].worker_model_info.expires_at = datetime.now() + timedelta(minutes=int(rkllama.config.get("model", "max_minutes_loaded_in_memory")),)
1066+
self.update_last_call_for_model(model_name)
10711067

10721068
# Return the request parent pipe
10731069
return parent_conn
10741070

10751071
return None
10761072

1073+
1074+
def update_last_call_for_model(self, model_name):
1075+
"""
1076+
Update the metadata of a worker with the last time called
1077+
Args:
1078+
model_name (str): Model to update
1079+
"""
1080+
# Update the last call of the model
1081+
self.workers[model_name].worker_model_info.last_call = datetime.now()
1082+
1083+
# Update the expiration of the model
1084+
self.update_expiration_date_for_model(model_name)
1085+
1086+
1087+
def update_expiration_date_for_model(self, model_name):
1088+
"""
1089+
Update the metadata of a worker with the expiration date for the model
1090+
Args:
1091+
model_name (str): Model to update
1092+
"""
1093+
# Update the expiration of the model
1094+
self.workers[model_name].worker_model_info.expires_at = datetime.now() + timedelta(minutes=int(rkllama.config.get("model", "max_minutes_loaded_in_memory")),)
1095+
10771096

10781097
def stop_worker(self, model_name, timeout=30):
10791098
"""

src/rkllama/server/server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ def embeddings_ollama():
12991299
def ollama_version():
13001300
"""Return a dummy version to be compatible with Ollama clients"""
13011301
return jsonify({
1302-
"version": "0.0.74"
1302+
"version": "0.0.75"
13031303
}), 200
13041304

13051305

@@ -1587,6 +1587,9 @@ def forward_request_to_llama_cpp_worker(is_openai_request,request):
15871587
logger.debug(f"Routing request to llama.cpp whith this URL: {proxy_route_url} with this data:\n{data}")
15881588

15891589
try:
1590+
# Updating last call info for the model to prevent expiration
1591+
variables.worker_manager_rkllm.update_last_call_for_model(model_name)
1592+
15901593
# Set the header for the llama-server call
15911594
headers = {
15921595
"Authorization": f"Bearer NOT_IN_USE",
@@ -1623,6 +1626,10 @@ def generate():
16231626

16241627
# Loop over the chunks returned by llama.cpp
16251628
for line in response.iter_lines():
1629+
1630+
# Updating expiration date for the model during token generation to prevent expiration
1631+
variables.worker_manager_rkllm.update_expiration_date_for_model(model_name)
1632+
16261633
# Decode the bytes line
16271634
line = line.decode("utf-8")
16281635

0 commit comments

Comments
 (0)