diff --git a/aiserver.py b/aiserver.py index 3eccb632..7f7be610 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1614,7 +1614,8 @@ def get_model_info(model, directory=""): 'gpu':gpu, 'layer_count':layer_count, 'breakmodel':breakmodel, 'multi_online_models': multi_online_models, 'default_url': default_url, 'disk_break_value': disk_blocks, 'disk_break': utils.HAS_ACCELERATE, 'break_values': break_values, 'gpu_count': gpu_count, - 'url': url, 'gpu_names': gpu_names, 'models_on_url': models_on_url, 'show_online_model_select': show_online_model_select}) + 'url': url, 'gpu_names': gpu_names, 'models_on_url': models_on_url, 'show_online_model_select': show_online_model_select, + 'bit_8_available': koboldai_vars.bit_8_available if koboldai_vars.experimental_features else False}) if send_horde_models: get_cluster_models({'key': key_value, 'url': default_url}) elif key_value != "" and model in [x[1] for x in model_menu['apilist']] and model != 'CLUSTER': @@ -2452,7 +2453,7 @@ def reset_model_settings(): koboldai_vars.revision = None koboldai_vars.lazy_load = True -def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=False, online_model="", use_breakmodel_args=False, breakmodel_args_default_to_cpu=False, url=None): +def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=False, online_model="", use_breakmodel_args=False, breakmodel_args_default_to_cpu=False, url=None, use_8_bit=False): global model global generator global torch @@ -5106,7 +5107,7 @@ def calcsubmit(txt): logger.debug("Submit: get_text time {}s".format(time.time()-start_time)) start_time = time.time() - if koboldai_vars.experimental_features: + if koboldai_vars.experimental_features and any([c.get("attention_multiplier", 1) != 1 for c in koboldai_vars.context]): offset = 0 applied_biases = [] for c in koboldai_vars.context: @@ -8507,7 +8508,7 @@ def UI_2_load_model(data): koboldai_vars.model = data['model'] koboldai_vars.custmodpth = data['path'] print("loading Model") - load_model(use_gpu=data['use_gpu'], gpu_layers=data['gpu_layers'], disk_layers=data['disk_layers'], online_model=data['online_model'], url=koboldai_vars.colaburl) + load_model(use_gpu=data['use_gpu'], gpu_layers=data['gpu_layers'], disk_layers=data['disk_layers'], online_model=data['online_model'], url=koboldai_vars.colaburl, use_8_bit=data['use_8_bit']) #==================================================================# # Event triggered when load story is clicked diff --git a/docker-standalone/Dockerfile.base b/docker-standalone/Dockerfile.base index 41209c2a..515dede4 100644 --- a/docker-standalone/Dockerfile.base +++ b/docker-standalone/Dockerfile.base @@ -5,6 +5,7 @@ COPY ./install_requirements.sh /opt/koboldai USER root RUN apt update && apt install wget aria2 git bzip2 python3 python3-venv -y RUN ./install_requirements.sh cuda;rm -rf ~/.cache/pip +RUN git clone https://github.com/db0/KoboldAI-Horde-Bridge /opt/koboldai/KoboldAI-Horde RUN python3 -m venv /opt/koboldai/KoboldAI-Horde/venv RUN /opt/koboldai/KoboldAI-Horde/venv/bin/pip install -r /opt/koboldai/KoboldAI-Horde/requirements.txt ENV PATH=/opt/conda/bin/:$PATH diff --git a/environments/huggingface.yml b/environments/huggingface.yml index f7b146cd..e87652b5 100644 --- a/environments/huggingface.yml +++ b/environments/huggingface.yml @@ -35,4 +35,5 @@ dependencies: - python-socketio[client] - ansi2html - flask_compress - - ijson \ No newline at end of file + - ijson + - bitsandbytes \ No newline at end of file diff --git a/koboldai_settings.py b/koboldai_settings.py index 8ab6be20..b2be36a6 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1,5 +1,6 @@ from __future__ import annotations from dataclasses import dataclass +import importlib import os, re, time, threading, json, pickle, base64, copy, tqdm, datetime, sys import shutil from typing import Union @@ -1114,7 +1115,7 @@ class system_settings(settings): 'lua_koboldcore', 'sp', 'sp_length', '_horde_pid', 'horde_share', 'aibusy', 'serverstarted', 'inference_config', 'image_pipeline', 'summarizer', 'summary_tokenizer', 'use_colab_tpu', 'noai', 'disable_set_aibusy', 'cloudflare_link', 'tts_model', - 'generating_image'] + 'generating_image', 'bit_8_available'] settings_name = "system" def __init__(self, socketio, koboldai_var): self.socketio = socketio @@ -1198,6 +1199,18 @@ class system_settings(settings): self.keep_img_gen_in_memory = False self.cookies = {} #cookies for colab since colab's URL changes, cookies are lost self.experimental_features = False + #check if bitsandbytes is installed + self.bit_8_available = False + if importlib.util.find_spec("bitsandbytes") is not None and sys.platform.startswith('linux'): #We can install bitsandbytes, but it doesn't work on windows, so limit it here + if torch.cuda.is_available(): + for device in range(torch.cuda.device_count()): + if torch.cuda.get_device_properties(device).major > 7: + self.bit_8_available = True + break + elif torch.cuda.get_device_properties(device).major == 7 and torch.cuda.get_device_properties(device).minor >= 2: + self.bit_8_available = True + break + @dataclass class _inference_config: diff --git a/requirements.txt b/requirements.txt index 0650e1e1..59fa49da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,4 +23,5 @@ diffusers psutil ansi2html flask_compress -ijson \ No newline at end of file +ijson +bitsandbytes \ No newline at end of file diff --git a/static/koboldai.js b/static/koboldai.js index 5b285160..da5e6676 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -1442,6 +1442,7 @@ function show_model_menu(data) { document.getElementById("modelkey").value = ""; document.getElementById("modelurl").classList.add("hidden"); document.getElementById("use_gpu_div").classList.add("hidden"); + document.getElementById("use_8_bit_div").classList.add("hidden"); document.getElementById("modellayers").classList.add("hidden"); document.getElementById("oaimodel").classList.add("hidden"); var model_layer_bars = document.getElementById('model_layer_bars'); @@ -1591,6 +1592,14 @@ function selected_model_info(data) { document.getElementById("modelurl").classList.add("hidden"); } + //hide or unhide 8 bit mode + if (data.bit_8_available) { + document.getElementById("use_8_bit_div").classList.remove("hidden"); + } else { + document.getElementById("use_8_bit_div").classList.add("hidden"); + document.getElementById("use_8_bit").checked = false; + } + //default URL loading if (data.default_url != null) { document.getElementById("modelurl").value = data.default_url; @@ -1820,7 +1829,8 @@ function load_model() { message = {'model': model, 'path': path, 'use_gpu': document.getElementById("use_gpu").checked, 'key': document.getElementById('modelkey').value, 'gpu_layers': gpu_layers.join(), 'disk_layers': disk_layers, 'url': document.getElementById("modelurl").value, - 'online_model': selected_models}; + 'online_model': selected_models, + 'use_8_bit': document.getElementById('use_8_bit').checked}; socket.emit("load_model", message); closePopups(); } diff --git a/templates/popups.html b/templates/popups.html index 47564f07..3e66753a 100644 --- a/templates/popups.html +++ b/templates/popups.html @@ -63,6 +63,10 @@
Use GPU
+