Skip to content

Commit

Permalink
Fix patches
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha0552 authored Dec 23, 2023
1 parent f680542 commit 1144c0d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', "")
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,27 @@

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]
+ enter_pstate_low()
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):
+ enter_pstate_low()
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")
17 changes: 17 additions & 0 deletions airootfs/usr/lib/python3.11/pstates.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 1144c0d

Please sign in to comment.