Advertisement
Guest User

Kobold Notebook

a guest
Apr 29th, 2023
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {
  6. "id": "y_Khe2ahSRqw"
  7. },
  8. "source": [
  9. "This notebook is loosely based on the original 4bit Kobold notebook by Peepy, OshieteKudasai, and Otis and subsequently modified by Anon. This should work with both Colab and Runpod.\n",
  10. "\n",
  11. "First, we'll install Kobold (may take a few minutes, particularly the last\n",
  12. "command)."
  13. ]
  14. },
  15. {
  16. "cell_type": "code",
  17. "execution_count": null,
  18. "metadata": {
  19. "id": "oSoUZXZ4QO2H"
  20. },
  21. "outputs": [],
  22. "source": [
  23. "import os\n",
  24. "\n",
  25. "# Package / Python updates.\n",
  26. "\n",
  27. "!apt-get -y update\n",
  28. "!apt-get -y install git-lfs\n",
  29. "!python -m pip install --upgrade pip\n",
  30. "\n",
  31. "!git-lfs install\n",
  32. "!git clone https://github.com/0cc4m/KoboldAI -b latestgptq --recurse-submodules\n",
  33. "\n",
  34. "# Install KoboldAI.\n",
  35. "\n",
  36. "!cd KoboldAI && ./install_requirements.sh cuda > /dev/null"
  37. ]
  38. },
  39. {
  40. "cell_type": "markdown",
  41. "metadata": {
  42. "id": "ey9AO8UrTb9S"
  43. },
  44. "source": [
  45. "Next, provide the URL for a 4bit model from Huggingface, along with the group size. Your URL should look something like https://huggingface.co/groupname/modelname/ . The linked repo should contain exactly one safetensors or pt, otherwise weird shit will happen.\n",
  46. "\n",
  47. "If \"version\" is specified, you can load a particular commit of the Huggingface repository."
  48. ]
  49. },
  50. {
  51. "cell_type": "code",
  52. "execution_count": null,
  53. "metadata": {
  54. "id": "eS_7mSYuTccr"
  55. },
  56. "outputs": [],
  57. "source": [
  58. "num_params = \"13b\" #@param [\"7b\", \"13b\", \"30b\", \"65b\"]\n",
  59. "\n",
  60. "group_size = \"128\" #@param [\"None\", \"32\", \"128\"]\n",
  61. "\n",
  62. "huggingface_url = '' #@param {type:\"string\"}\n",
  63. "\n",
  64. "version = '' #@param {type:\"string\"}\n",
  65. "\n",
  66. "group_and_model = huggingface_url[len('https://huggingface.co/'):].split('/')[:2]\n",
  67. "group = group_and_model[0]\n",
  68. "model = group_and_model[1]\n",
  69. "\n",
  70. "if not version:\n",
  71. " !cd KoboldAI/models && git clone https://huggingface.co/{group}/{model}/\n",
  72. "else:\n",
  73. " !cd KoboldAI/models && git clone https://huggingface.co/{group}/{model}/ && cd {model} && git checkout {version}\n",
  74. "\n",
  75. "if group_size == 'None':\n",
  76. " !cd KoboldAI/models/{model} ; mv *.pt 4bit.pt ; mv *.safetensors 4bit.safetensors\n",
  77. "else:\n",
  78. " !cd KoboldAI/models/{model} ; mv *.pt 4bit-{group_size}g.pt ; mv *.safetensors 4bit-{group_size}g.safetensors"
  79. ]
  80. },
  81. {
  82. "cell_type": "markdown",
  83. "metadata": {
  84. "id": "JWFvZKfJa0c2"
  85. },
  86. "source": [
  87. "Next, perform a quick hotfix to fix bug with the Flask Session package (make sure to only ever run this cell once). Fixed now, no longer necessary."
  88. ]
  89. },
  90. {
  91. "cell_type": "code",
  92. "execution_count": null,
  93. "metadata": {
  94. "id": "Ib-L2kajbkFp"
  95. },
  96. "outputs": [],
  97. "source": [
  98. "'''\n",
  99. "def insert_lines(fpath, positions, lines):\n",
  100. " with open(fpath, 'r') as f:\n",
  101. " contents = f.readlines()\n",
  102. "\n",
  103. " for pos, line in zip(positions, lines):\n",
  104. " contents.insert(pos, line)\n",
  105. "\n",
  106. " with open(fpath, 'w') as f:\n",
  107. " contents = ''.join(contents)\n",
  108. " f.write(contents)\n",
  109. "\n",
  110. "positions = [328, 329]\n",
  111. "lines = [' if not hasattr(app, \\'session_cookie_name\\'):\\n',\n",
  112. " ' app.session_cookie_name = \\'session\\'\\n']\n",
  113. "\n",
  114. "if os.path.exists('KoboldAI/runtime/envs/koboldai/lib/python3.8/site-packages/flask_session/sessions.py'):\n",
  115. " insert_lines('KoboldAI/runtime/envs/koboldai/lib/python3.8/site-packages/flask_session/sessions.py', positions, lines)\n",
  116. "'''"
  117. ]
  118. },
  119. {
  120. "cell_type": "markdown",
  121. "metadata": {
  122. "id": "6uipr3t5en52"
  123. },
  124. "source": [
  125. "Run Kobold (use UI2, then when you select the model it should give you the option to load it in 4bit)."
  126. ]
  127. },
  128. {
  129. "cell_type": "code",
  130. "execution_count": null,
  131. "metadata": {
  132. "id": "UidO9J3xe9PM"
  133. },
  134. "outputs": [],
  135. "source": [
  136. "!cd KoboldAI && ./play.sh --remote --quiet"
  137. ]
  138. }
  139. ],
  140. "metadata": {
  141. "accelerator": "GPU",
  142. "colab": {
  143. "provenance": []
  144. },
  145. "gpuClass": "standard",
  146. "kernelspec": {
  147. "display_name": "Python 3",
  148. "name": "python3"
  149. },
  150. "language_info": {
  151. "name": "python"
  152. }
  153. },
  154. "nbformat": 4,
  155. "nbformat_minor": 0
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement