Files
SillyTavern/colab/GPU.ipynb
T
2023-02-15 16:49:46 +04:00

8.1 KiB

https://colab.research.google.com/github/TavernAI/TavernAI/blob/main/colab/GPU.ipynb

Works with:
KoboldAI https://github.com/KoboldAI/KoboldAI-Client
Pygmalion https://huggingface.co/PygmalionAI/

Links
TavernAI Github https://github.com/TavernAI/TavernAI
TavernAI Discord https://discord.gg/zmK2gmr45t
TavernAI Boosty https://boosty.to/tavernai

 Tavern.AI/ \ /  ^   ^ ^ ^    ~~~~ ^ \     /  ^ ^   ^ ^/ ^  ^ \/^  ^    \
         /^ ^\ ^  ^ ^   ^ ^  ~~   ^   \   /  ^  ^ ^   / ^ ^  ^/   ^ ^    \
        /^ ^ ^\^   ^ ^ ^   _||____   ^ \ /  ^  ^ ^   /       /  ^  ^  ^   \
 /\ /\ /\   ^  \  /\ /\   /\\\\\\\\   ^ \  ^ /\ /\ /\   /\ /\ /\  ^ ^  ^/\
//\\/\\/\\   ^  \//\\/\\ /__\\\\\\\\  _, \  //\\/\\/\\ //\\/\\/\\  ^ ^ //\\
//\\/\\/\\       //\\/\\ |__|_|_|__|   \__, //\\/\\/\\ //\\/\\/\\     ///\\\
 || || (@^◡^)(≖ ‸ ≖*) ( ←_← )\| /|   /\ \ヽ(°ㅂ°╬) |( Ψ▼ー▼)∈ (O_O; )  |||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~  ~~~~~ ~~ 

Launch Instructions

  1. Click the launch button.
  2. Wait for the environment and model to load
  3. After initialization, a TavernAI link will appear

Faq

  • Q: I do not get a TavernAI link
  • A: It seems the localtunnel service is currently down, so the TavernAI link is unavailable. Need to wait for it to start working again.
In [ ]:
#@title <-- Tap this if you play on Mobile { display-mode: "form" }
#Taken from KoboldAI colab
%%html
<b>Press play on the music player to keep the tab alive, then start TavernAI below (Uses only 13MB of data)</b><br/>
<audio src="https://henk.tech/colabkobold/silence.m4a" controls>
In [ ]:
#@title <b>TavernAI</b>
#@markdown <- Click For Start (≖ ‸ ≖ ✿)

Model = "Pygmalion 6B" #@param [ "Pygmalion 6B", "Pygmalion 6B Dev"] {allow-input: true}
Version = "Official" 
KoboldAI_Provider = "Localtunnel" #@param ["Localtunnel", "Cloudflare"]
use_google_drive = True #@param {type:"boolean"}
Provider = KoboldAI_Provider
!nvidia-smi
import subprocess
import time
import sys
import os
import threading
import shutil
from google.colab import drive

    
if use_google_drive:
  drive.mount('/content/drive/')
  if not os.path.exists("/content/drive/MyDrive/TavernAI/"):
    os.mkdir("/content/drive/MyDrive/TavernAI/")
  if not os.path.exists("/content/drive/MyDrive/TavernAI/characters/"):
    os.mkdir("/content/drive/MyDrive/TavernAI/characters/")
  if not os.path.exists("/content/drive/MyDrive/TavernAI/chats/"):
    os.mkdir("/content/drive/MyDrive/TavernAI/chats/")
else:
  if not os.path.exists("/content/drive"):
    os.mkdir("/content/drive")
  if not os.path.exists("/content/drive/MyDrive/"):
    os.mkdir("/content/drive/MyDrive/")

def copy_characters(use_google_drive=False):
  if not use_google_drive:
    return
  
  src_folder = "/TavernAIColab/public/characters"
  dst_folder = "/content/drive/MyDrive/TavernAI/characters"

  for filename in os.listdir(src_folder):
    src_file = os.path.join(src_folder, filename)
    dst_file = os.path.join(dst_folder, filename)

    if os.path.exists(dst_file):
      print(f"{dst_file} already exists. Skipping...")
      continue

    shutil.copy(src_file, dst_folder)
    print(f"{src_file} copied to {dst_folder}")
Revision = ""

if Model == "Pygmalion 6B":
  Model = "PygmalionAI/pygmalion-6b"
  path = ""
  download = ""
  Version = "United"
elif Model == "Pygmalion 6B Dev":
  Model = "PygmalionAI/pygmalion-6b"
  Revision = "--revision dev"
  path = ""
  Version = "United"
  download = ""

if Provider == "Localtunnel":
  tunnel = "--localtunnel yes"
else:
  tunnel = ""



#Henk's KoboldAI script
!wget https://koboldai.org/ckds && chmod +x ckds
!./ckds --init only
if Provider == "Localtunnel":
  p = subprocess.Popen(['/content/ckds', '--model', Model, '--localtunnel', 'yes'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
  p = subprocess.Popen(['/content/ckds', '--model', Model], stdout=subprocess.PIPE, stderr=subprocess.PIPE)


#Do not repeat! Tricks performed by a professional!
url = ''
while True:
    line = p.stdout.readline().decode().strip()
    if "KoboldAI has finished loading and is available at the following link: " in line:
        print(line)
        url = line.split("KoboldAI has finished loading and is available at the following link: ")[1]
        print(url)
        break
    if "KoboldAI has finished loading and is available at the following link for UI 1: " in line:
        print(line)
        url = line.split("KoboldAI has finished loading and is available at the following link for UI 1: ")[1]
        print(url)
        break
    if not line:
        break
    print(line)
    if "INIT" in line and "Transformers" in line:
      print("Model loading... (It will take 2 - 5 minutes)")


#TavernAI
%cd /
!curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
!nvm install 19.1.0
!nvm use 19.1.0
!node -v
!git clone https://github.com/TavernAI/TavernAIColab
copy_characters(use_google_drive)
%cd TavernAIColab
!npm install
time.sleep(1)
%env colab=2
%env colaburl=$url
if use_google_drive:
  %env googledrive=2
!nohup node server.js &
time.sleep(3)
print('KoboldAI LINK:')
print(url)
print('')
print('###TavernAI LINK###')
!lt --port 8000