mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2025-09-10 09:04:36 +00:00
better way of checking for avx2 support
This commit is contained in:
parent
52dcfe42d6
commit
abc1d8ac25
14 changed files with 106 additions and 40 deletions
55
koboldcpp.py
55
koboldcpp.py
|
@ -678,23 +678,34 @@ def strip_base64_prefix(encoded_data):
|
|||
encoded_data = encoded_data.split(',', 1)[-1]
|
||||
return encoded_data
|
||||
|
||||
def old_cpu_check(): #return 0 if has avx2, 1 if has avx, 2 if has nothing
|
||||
def old_cpu_check(): #return -1 for pass, 0 if has avx2, 1 if has avx, 2 if has nothing
|
||||
shouldcheck = ((sys.platform == "linux" and platform.machine().lower() in ("x86_64", "amd64")) or
|
||||
(os.name == 'nt' and platform.machine().lower() in ("amd64", "x86_64")))
|
||||
if not shouldcheck:
|
||||
return 0 #doesnt deal with avx at all.
|
||||
return -1 #doesnt deal with avx at all.
|
||||
try:
|
||||
import cpuinfo
|
||||
info = cpuinfo.get_cpu_info()
|
||||
flags = info.get('flags', [])
|
||||
if 'avx2' in flags:
|
||||
return 0
|
||||
elif 'avx' in flags:
|
||||
return 1
|
||||
else:
|
||||
return 2
|
||||
retflags = 0
|
||||
if sys.platform == "linux":
|
||||
with open('/proc/cpuinfo', 'r') as f:
|
||||
cpuinfo = f.read()
|
||||
cpuinfo = cpuinfo.lower()
|
||||
if 'avx' not in cpuinfo and 'avx2' not in cpuinfo:
|
||||
retflags = 2
|
||||
elif 'avx2' not in cpuinfo:
|
||||
retflags = 1
|
||||
elif os.name == 'nt':
|
||||
basepath = os.path.abspath(os.path.dirname(__file__))
|
||||
output = ""
|
||||
data = None
|
||||
output = subprocess.run([os.path.join(basepath, "simplecpuinfo.exe")], capture_output=True, text=True, check=True, creationflags=subprocess.CREATE_NO_WINDOW | subprocess.DETACHED_PROCESS, encoding='utf-8', timeout=6).stdout
|
||||
data = json.loads(output)
|
||||
if data["avx2"]==0 and data["avx"]==0:
|
||||
retflags = 2
|
||||
elif data["avx2"]==0:
|
||||
retflags = 1
|
||||
return retflags
|
||||
except Exception:
|
||||
return 0 #cannot determine
|
||||
return -1 #cannot determine
|
||||
|
||||
|
||||
def unpack_to_dir(destpath = ""):
|
||||
|
@ -1286,7 +1297,7 @@ def auto_set_backend_cli():
|
|||
# check for avx2 and avx support
|
||||
is_oldpc_ver = "Use CPU" not in runopts #on oldcpu ver, default lib does not exist
|
||||
cpusupport = old_cpu_check() # 0 if has avx2, 1 if has avx, 2 if has nothing
|
||||
eligible_cuda = (cpusupport==0 and not is_oldpc_ver) or (cpusupport==1 and is_oldpc_ver)
|
||||
eligible_cuda = (cpusupport<1 and not is_oldpc_ver) or (cpusupport<2 and is_oldpc_ver)
|
||||
if not eligible_cuda:
|
||||
if cpusupport==1:
|
||||
args.noavx2 = True
|
||||
|
@ -1297,17 +1308,17 @@ def auto_set_backend_cli():
|
|||
if eligible_cuda and exitcounter < 100 and MaxMemory[0]>3500000000 and (("Use CuBLAS" in runopts and CUDevicesNames[0]!="") or "Use hipBLAS (ROCm)" in runopts) and any(CUDevicesNames):
|
||||
if "Use CuBLAS" in runopts or "Use hipBLAS (ROCm)" in runopts:
|
||||
args.usecublas = ["normal","mmq"]
|
||||
print("Auto Selected CUDA Backend...\n")
|
||||
print(f"Auto Selected CUDA Backend (flag={cpusupport})\n")
|
||||
found_new_backend = True
|
||||
elif exitcounter < 100 and (1 in VKIsDGPU) and ("Use Vulkan" in runopts or "Use Vulkan (Old CPU)" in runopts):
|
||||
for i in range(0,len(VKIsDGPU)):
|
||||
if VKIsDGPU[i]==1:
|
||||
args.usevulkan = []
|
||||
print("Auto Selected Vulkan Backend...\n")
|
||||
print(f"Auto Selected Vulkan Backend (flag={cpusupport})\n")
|
||||
found_new_backend = True
|
||||
break
|
||||
if not found_new_backend:
|
||||
print("No GPU Backend found...\n")
|
||||
print(f"Auto Selected Default Backend (flag={cpusupport})\n")
|
||||
|
||||
def load_model(model_filename):
|
||||
global args
|
||||
|
@ -4668,7 +4679,7 @@ def show_gui():
|
|||
# check for avx2 and avx support
|
||||
is_oldpc_ver = "Use CPU" not in runopts #on oldcpu ver, default lib does not exist
|
||||
cpusupport = old_cpu_check() # 0 if has avx2, 1 if has avx, 2 if has nothing
|
||||
eligible_cuda = (cpusupport==0 and not is_oldpc_ver) or (cpusupport==1 and is_oldpc_ver)
|
||||
eligible_cuda = (cpusupport<1 and not is_oldpc_ver) or (cpusupport<2 and is_oldpc_ver)
|
||||
|
||||
#autopick cublas if suitable, requires at least 3.5GB VRAM to auto pick
|
||||
#we do not want to autoselect hip/cublas if the user has already changed their desired backend!
|
||||
|
@ -4676,22 +4687,22 @@ def show_gui():
|
|||
if "Use CuBLAS" in runopts:
|
||||
runopts_var.set("Use CuBLAS")
|
||||
gpu_choice_var.set("1")
|
||||
print("Auto Selected CUDA Backend...\n")
|
||||
print(f"Auto Selected CUDA Backend (flag={cpusupport})\n")
|
||||
found_new_backend = True
|
||||
elif "Use hipBLAS (ROCm)" in runopts:
|
||||
runopts_var.set("Use hipBLAS (ROCm)")
|
||||
gpu_choice_var.set("1")
|
||||
print("Auto Selected HIP Backend...\n")
|
||||
print(f"Auto Selected HIP Backend (flag={cpusupport})\n")
|
||||
found_new_backend = True
|
||||
elif exitcounter < 100 and (1 in VKIsDGPU) and runmode_untouched and ("Use Vulkan" in runopts or "Use Vulkan (Old CPU)" in runopts):
|
||||
for i in range(0,len(VKIsDGPU)):
|
||||
if VKIsDGPU[i]==1:
|
||||
if cpusupport==0 and "Use Vulkan" in runopts:
|
||||
if cpusupport<1 and "Use Vulkan" in runopts:
|
||||
runopts_var.set("Use Vulkan")
|
||||
else:
|
||||
runopts_var.set("Use Vulkan (Old CPU)")
|
||||
gpu_choice_var.set(str(i+1))
|
||||
print("Auto Selected Vulkan Backend...\n")
|
||||
print(f"Auto Selected Vulkan Backend (flag={cpusupport})\n")
|
||||
found_new_backend = True
|
||||
break
|
||||
else:
|
||||
|
@ -4700,7 +4711,7 @@ def show_gui():
|
|||
elif runopts_var.get()=="Use CPU" and cpusupport==2 and "Failsafe Mode (Older CPU)" in runopts:
|
||||
runopts_var.set("Failsafe Mode (Older CPU)")
|
||||
if not found_new_backend:
|
||||
print("Auto Selected Default Backend...\n")
|
||||
print(f"Auto Selected Default Backend (flag={cpusupport})\n")
|
||||
changed_gpu_choice_var()
|
||||
|
||||
def on_picked_model_file(filepath):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue