Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha0552 committed Dec 20, 2023
0 parents commit 013e6bd
Show file tree
Hide file tree
Showing 46 changed files with 853 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build ISO

on:
push:
branches: main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Cleanup
uses: rokibhasansagar/slimhub_actions@main
with:
retain: "docker_imgcache,docker_buildkit,docker_imgcache"

- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Build image
uses: addnab/docker-run-action@v3
with:
image: archlinux:latest
options: --privileged
run: |
# Refresh package databases
pacman --sync --noconfirm --refresh
# Upgrade system
pacman --sync --noconfirm --sysupgrade
# Install required packages
pacman --sync --noconfirm --needed archiso
# Build image
mkarchiso -v .
19 changes: 19 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[submodule "airootfs/home/tori/automatic"]
path = airootfs/home/tori/automatic
url = https://github.com/vladmandic/automatic.git

[submodule "airootfs/home/tori/koboldcpp"]
path = airootfs/home/tori/koboldcpp
url = https://github.com/LostRuins/koboldcpp.git

[submodule "airootfs/home/tori/llama.cpp"]
path = airootfs/home/tori/llama.cpp
url = https://github.com/ggerganov/llama.cpp.git

[submodule "airootfs/home/tori/SillyTavern-Extras"]
path = airootfs/home/tori/SillyTavern-Extras
url = https://github.com/SillyTavern/SillyTavern-Extras.git

[submodule "airootfs/home/tori/text-generation-webui"]
path = airootfs/home/tori/text-generation-webui
url = https://github.com/oobabooga/text-generation-webui.git
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 sasha0552

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ToriLinux
3 changes: 3 additions & 0 deletions airootfs/etc/group
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
root:x:0:root
wheel:x:10:tori
tori:x:1000:
2 changes: 2 additions & 0 deletions airootfs/etc/gshadow
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
root:!*::root
tori:!*::
1 change: 1 addition & 0 deletions airootfs/etc/hostname
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
torilinux
2 changes: 2 additions & 0 deletions airootfs/etc/issue
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tori Linux \r (\l)

1 change: 1 addition & 0 deletions airootfs/etc/locale.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LANG=en_US.UTF-8
1 change: 1 addition & 0 deletions airootfs/etc/localtime
3 changes: 3 additions & 0 deletions airootfs/etc/lsb-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DISTRIB_ID="Tori"
DISTRIB_RELEASE="rolling"
DISTRIB_DESCRIPTION="Tori Linux"
1 change: 1 addition & 0 deletions airootfs/etc/mkinitcpio.conf.d/archiso.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HOOKS=(base udev modconf kms memdisk archiso archiso_loop_mnt archiso_pxe_common archiso_pxe_nbd archiso_pxe_http archiso_pxe_nfs block filesystems keyboard)
8 changes: 8 additions & 0 deletions airootfs/etc/mkinitcpio.d/linux.preset
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# mkinitcpio preset file for the 'linux' package on archiso

PRESETS=('archiso')

ALL_kver='/boot/vmlinuz-linux'
archiso_config='/etc/mkinitcpio.conf.d/archiso.conf'

archiso_image="/boot/initramfs-linux.img"
2 changes: 2 additions & 0 deletions airootfs/etc/passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
root:x:0:0:root:/root:/usr/bin/zsh
tori:x:1000:1000::/home/tori:/usr/bin/zsh
2 changes: 2 additions & 0 deletions airootfs/etc/shadow
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
root:!*:::::::
tori:!*:::::::
3 changes: 3 additions & 0 deletions airootfs/etc/sudoers
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Defaults lecture="never"

%wheel ALL=(ALL:ALL) ALL
2 changes: 2 additions & 0 deletions airootfs/etc/systemd/journald.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Journal]
Storage=none
10 changes: 10 additions & 0 deletions airootfs/etc/systemd/network/20-ethernet.network
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Match]
# Matching with "Type=ether" causes issues with containers because it also matches virtual Ethernet interfaces (veth*).
# See https://bugs.archlinux.org/task/70892
# Instead match by globbing the network interface name.
Name=en*
Name=eth*

[Network]
DHCP=yes
MulticastDNS=yes
1 change: 1 addition & 0 deletions airootfs/home/tori/SillyTavern-Extras
Submodule SillyTavern-Extras added at 47a548
1 change: 1 addition & 0 deletions airootfs/home/tori/automatic
Submodule automatic added at 00281e
1 change: 1 addition & 0 deletions airootfs/home/tori/koboldcpp
Submodule koboldcpp added at ec0523
1 change: 1 addition & 0 deletions airootfs/home/tori/llama.cpp
Submodule llama.cpp added at 799fc2
1 change: 1 addition & 0 deletions airootfs/home/tori/text-generation-webui
Submodule text-generation-webui added at 489f4a
32 changes: 32 additions & 0 deletions airootfs/root/customize_airootfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -eu

# move new os-release to its place
mv /usr/lib/os-release.new /usr/lib/os-release

# set user password
echo "tori:tori" | chpasswd

# disable alternate screen capability
echo "termcapinfo * ti=:te=" >> /etc/skel/.screenrc

# enter user directory
cd "/home/tori"

# customize_airootfs temporary directory
export CUSTOMIZE_AIROOTFS=/root/customize_airootfs

# execute scripts
for script in $CUSTOMIZE_AIROOTFS/scripts/*.sh; do
# print current script
echo "===> Executing script $script"

# add execution permission
chmod +x "$script"

# launch script as user
su tori -c "$script"
done

# remove customize_airootfs temporary directory
rm -r "$CUSTOMIZE_AIROOTFS"
10 changes: 10 additions & 0 deletions airootfs/root/customize_airootfs/files/automatic-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"precision": "Full",
"cuda_dtype": "FP32",
"no_half": true,
"no_half_vae": true,

"cross_attention_options": [
"SDP disable memory attention"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
--- a/launch.py
+++ b/launch.py
@@ -7,6 +7,7 @@ import shlex
import subprocess
from functools import lru_cache
import installer
+from modules.pstates import enter_pstate_low


commandline_args = os.environ.get('COMMANDLINE_ARGS', "")
@@ -165,6 +166,7 @@ def start_server(immediate=True, server=None):


if __name__ == "__main__":
+ enter_pstate_low()
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


class State:
@@ -77,6 +78,8 @@ class State:
self.time_start = time.time()
if self.debug_output:
log.debug(f'State begin: {self.job}')
+ if self.job != "load":
+ enter_pstate_high()
modules.devices.torch_gc()

def end(self):
@@ -86,6 +89,8 @@ class State:
self.time_start = time.time()
if self.debug_output:
log.debug(f'State end: {self.job} time={time.time() - self.time_start:.2f}')
+ if self.job != "load":
+ enter_pstate_low()
self.job = ""
self.job_count = 0
self.job_no = 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--- a/koboldcpp.py
+++ b/koboldcpp.py
@@ -13,6 +13,7 @@ import os
import argparse
import json, sys, http.server, time, asyncio, socket, threading
from concurrent.futures import ThreadPoolExecutor
+from pstates import enter_pstate_high, enter_pstate_low

sampler_order_max = 7
stop_token_max = 16
@@ -301,6 +302,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):
+ 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
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):
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")
Loading

0 comments on commit 013e6bd

Please sign in to comment.