From 1144c0d1e17f5c3da70e122faa9227ff97cb10c1 Mon Sep 17 00:00:00 2001 From: sasha0552 Date: Sat, 23 Dec 2023 05:51:07 +0000 Subject: [PATCH] Fix patches --- .../0000-automatic-drop-pstate-in-idle.patch | 27 ++---------------- .../0000-koboldcpp-drop-pstate-in-idle.patch | 28 +++---------------- airootfs/usr/lib/python3.11/pstates.py | 17 +++++++++++ 3 files changed, 23 insertions(+), 49 deletions(-) create mode 100644 airootfs/usr/lib/python3.11/pstates.py diff --git a/airootfs/root/customize_airootfs/patches/0000-automatic-drop-pstate-in-idle.patch b/airootfs/root/customize_airootfs/patches/0000-automatic-drop-pstate-in-idle.patch index d044483..4e3860d 100644 --- a/airootfs/root/customize_airootfs/patches/0000-automatic-drop-pstate-in-idle.patch +++ b/airootfs/root/customize_airootfs/patches/0000-automatic-drop-pstate-in-idle.patch @@ -4,7 +4,7 @@ import subprocess from functools import lru_cache import installer -+from modules.pstates import enter_pstate_low ++from pstates import enter_pstate_high, enter_pstate_low commandline_args = os.environ.get('COMMANDLINE_ARGS', "") @@ -16,36 +16,13 @@ installer.ensure_base_requirements() init_args() # setup argparser and default folders installer.args = args -diff --git a/modules/pstates.py b/modules/pstates.py -new file mode 100644 -index 00000000..44865a87 ---- /dev/null -+++ b/modules/pstates.py -@@ -0,0 +1,17 @@ -+import os -+import subprocess -+ -+def _set_pstate(pstate): -+ visible_devices = os.getenv("CUDA_VISIBLE_DEVICES") -+ -+ if visible_devices: -+ for device in visible_devices.split(","): -+ subprocess.check_call([ "nvidia-pstate", "-i", device, "-ps", pstate ], stdout=subprocess.DEVNULL) -+ else: -+ subprocess.check_call([ "nvidia-pstate", "-ps", pstate ], stdout=subprocess.DEVNULL) -+ -+def enter_pstate_low(): -+ _set_pstate("8") -+ -+def enter_pstate_high(): -+ _set_pstate("16") --- a/modules/shared_state.py +++ b/modules/shared_state.py @@ -3,6 +3,7 @@ import sys import time import datetime from modules.errors import log -+from modules.pstates import enter_pstate_high, enter_pstate_low ++from pstates import enter_pstate_high, enter_pstate_low class State: diff --git a/airootfs/root/customize_airootfs/patches/0000-koboldcpp-drop-pstate-in-idle.patch b/airootfs/root/customize_airootfs/patches/0000-koboldcpp-drop-pstate-in-idle.patch index 552737e..b02c181 100644 --- a/airootfs/root/customize_airootfs/patches/0000-koboldcpp-drop-pstate-in-idle.patch +++ b/airootfs/root/customize_airootfs/patches/0000-koboldcpp-drop-pstate-in-idle.patch @@ -8,15 +8,15 @@ sampler_order_max = 7 stop_token_max = 16 -@@ -301,6 +302,7 @@ def load_model(model_filename): +@@ -302,6 +303,7 @@ def load_model(model_filename): return ret - def generate(prompt, memory="", max_length=32, max_context_length=512, temperature=0.7, top_k=100, top_a=0.0, top_p=0.92, min_p=0.0, typical_p=1.0, tfs=1.0, rep_pen=1.1, rep_pen_range=128, mirostat=0, mirostat_tau=5.0, mirostat_eta=0.1, sampler_order=[6,0,1,3,4,2,5], seed=-1, stop_sequence=[], use_default_badwordsids=False, stream_sse=False, grammar='', grammar_retain_state=False, genkey='', trimstop=False, quiet=False): + def generate(prompt, memory="", max_length=32, max_context_length=512, temperature=0.7, top_k=100, top_a=0.0, top_p=0.92, min_p=0.0, typical_p=1.0, tfs=1.0, rep_pen=1.1, rep_pen_range=128, presence_penalty=0.0, mirostat=0, mirostat_tau=5.0, mirostat_eta=0.1, sampler_order=[6,0,1,3,4,2,5], seed=-1, stop_sequence=[], use_default_badwordsids=False, stream_sse=False, grammar='', grammar_retain_state=False, genkey='', trimstop=False, quiet=False): + enter_pstate_high() global maxctx, args, currentusergenkey, totalgens inputs = generation_inputs() outputs = ctypes.create_unicode_buffer(ctypes.sizeof(generation_outputs)) -@@ -364,6 +366,7 @@ def generate(prompt, memory="", max_length=32, max_context_length=512, temperatu +@@ -366,6 +368,7 @@ def generate(prompt, memory="", max_length=32, max_context_length=512, temperatu sindex = outstr.find(trim_str) if sindex != -1 and trim_str!="": outstr = outstr[:sindex] @@ -24,7 +24,7 @@ return outstr def utfprint(str): -@@ -2031,6 +2034,7 @@ def sanitize_string(input_string): +@@ -2176,6 +2179,7 @@ def sanitize_string(input_string): return sanitized_string def main(launch_args,start_server=True): @@ -32,23 +32,3 @@ global args, friendlymodelname args = launch_args embedded_kailite = None ---- /dev/null -+++ b/pstates.py -@@ -0,0 +1,17 @@ -+import os -+import subprocess -+ -+def _set_pstate(pstate): -+ visible_devices = os.getenv("CUDA_VISIBLE_DEVICES") -+ -+ if visible_devices: -+ for device in visible_devices.split(","): -+ subprocess.check_call([ "nvidia-pstate", "-i", device, "-ps", pstate ], stdout=subprocess.DEVNULL) -+ else: -+ subprocess.check_call([ "nvidia-pstate", "-ps", pstate ], stdout=subprocess.DEVNULL) -+ -+def enter_pstate_low(): -+ _set_pstate("8") -+ -+def enter_pstate_high(): -+ _set_pstate("16") diff --git a/airootfs/usr/lib/python3.11/pstates.py b/airootfs/usr/lib/python3.11/pstates.py new file mode 100644 index 0000000..44865a8 --- /dev/null +++ b/airootfs/usr/lib/python3.11/pstates.py @@ -0,0 +1,17 @@ +import os +import subprocess + +def _set_pstate(pstate): + visible_devices = os.getenv("CUDA_VISIBLE_DEVICES") + + if visible_devices: + for device in visible_devices.split(","): + subprocess.check_call([ "nvidia-pstate", "-i", device, "-ps", pstate ], stdout=subprocess.DEVNULL) + else: + subprocess.check_call([ "nvidia-pstate", "-ps", pstate ], stdout=subprocess.DEVNULL) + +def enter_pstate_low(): + _set_pstate("8") + +def enter_pstate_high(): + _set_pstate("16")