shared.py 5.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import argparse
  2. model = None
  3. tokenizer = None
  4. model_name = ""
  5. soft_prompt_tensor = None
  6. soft_prompt = False
  7. is_RWKV = False
  8. is_LLaMA = False
  9. # Chat variables
  10. history = {'internal': [], 'visible': []}
  11. character = 'None'
  12. stop_everything = False
  13. still_streaming = False
  14. # UI elements (buttons, sliders, HTML, etc)
  15. gradio = {}
  16. # Generation input parameters
  17. input_params = []
  18. settings = {
  19. 'max_new_tokens': 200,
  20. 'max_new_tokens_min': 1,
  21. 'max_new_tokens_max': 2000,
  22. 'name1': 'Person 1',
  23. 'name2': 'Person 2',
  24. 'context': 'This is a conversation between two people.',
  25. 'stop_at_newline': True,
  26. 'chat_prompt_size': 2048,
  27. 'chat_prompt_size_min': 0,
  28. 'chat_prompt_size_max': 2048,
  29. 'chat_generation_attempts': 1,
  30. 'chat_generation_attempts_min': 1,
  31. 'chat_generation_attempts_max': 5,
  32. 'name1_pygmalion': 'You',
  33. 'name2_pygmalion': 'Kawaii',
  34. 'context_pygmalion': "Kawaii's persona: Kawaii is a cheerful person who loves to make others smile. She is an optimist who loves to spread happiness and positivity wherever she goes.\n<START>",
  35. 'stop_at_newline_pygmalion': False,
  36. 'default_extensions': [],
  37. 'chat_default_extensions': ["gallery"],
  38. 'presets': {
  39. 'default': 'NovelAI-Sphinx Moth',
  40. 'pygmalion-*': 'Pygmalion',
  41. 'RWKV-*': 'Naive',
  42. 'llama-*': 'Naive',
  43. '(rosey|chip|joi)_.*_instruct.*': 'Instruct Joi (Contrastive Search)'
  44. },
  45. 'prompts': {
  46. 'default': 'Common sense questions and answers\n\nQuestion: \nFactual answer:',
  47. '^(gpt4chan|gpt-4chan|4chan)': '-----\n--- 865467536\nInput text\n--- 865467537\n',
  48. '(rosey|chip|joi)_.*_instruct.*': 'User: \n'
  49. }
  50. }
  51. def str2bool(v):
  52. if isinstance(v, bool):
  53. return v
  54. if v.lower() in ('yes', 'true', 't', 'y', '1'):
  55. return True
  56. elif v.lower() in ('no', 'false', 'f', 'n', '0'):
  57. return False
  58. else:
  59. raise argparse.ArgumentTypeError('Boolean value expected.')
  60. parser = argparse.ArgumentParser(formatter_class=lambda prog: argparse.HelpFormatter(prog,max_help_position=54))
  61. parser.add_argument('--model', type=str, help='Name of the model to load by default.')
  62. parser.add_argument('--notebook', action='store_true', help='Launch the web UI in notebook mode, where the output is written to the same text box as the input.')
  63. parser.add_argument('--chat', action='store_true', help='Launch the web UI in chat mode.')
  64. parser.add_argument('--cai-chat', action='store_true', help='Launch the web UI in chat mode with a style similar to Character.AI\'s. If the file img_bot.png or img_bot.jpg exists in the same folder as server.py, this image will be used as the bot\'s profile picture. Similarly, img_me.png or img_me.jpg will be used as your profile picture.')
  65. parser.add_argument('--cpu', action='store_true', help='Use the CPU to generate text.')
  66. parser.add_argument('--load-in-8bit', action='store_true', help='Load the model with 8-bit precision.')
  67. parser.add_argument('--bf16', action='store_true', help='Load the model with bfloat16 precision. Requires NVIDIA Ampere GPU.')
  68. parser.add_argument('--auto-devices', action='store_true', help='Automatically split the model across the available GPU(s) and CPU.')
  69. parser.add_argument('--disk', action='store_true', help='If the model is too large for your GPU(s) and CPU combined, send the remaining layers to the disk.')
  70. parser.add_argument('--disk-cache-dir', type=str, default="cache", help='Directory to save the disk cache to. Defaults to "cache".')
  71. parser.add_argument('--gpu-memory', type=int, nargs="+", help='Maxmimum GPU memory in GiB to be allocated per GPU. Example: --gpu-memory 10 for a single GPU, --gpu-memory 10 5 for two GPUs.')
  72. parser.add_argument('--cpu-memory', type=int, help='Maximum CPU memory in GiB to allocate for offloaded weights. Must be an integer number. Defaults to 99.')
  73. parser.add_argument('--flexgen', action='store_true', help='Enable the use of FlexGen offloading.')
  74. parser.add_argument('--percent', type=int, nargs="+", default=[0, 100, 100, 0, 100, 0], help='FlexGen: allocation percentages. Must be 6 numbers separated by spaces (default: 0, 100, 100, 0, 100, 0).')
  75. parser.add_argument("--compress-weight", action="store_true", help="FlexGen: activate weight compression.")
  76. parser.add_argument("--pin-weight", type=str2bool, nargs="?", const=True, default=True, help="FlexGen: whether to pin weights (setting this to False reduces CPU memory by 20%%).")
  77. parser.add_argument('--deepspeed', action='store_true', help='Enable the use of DeepSpeed ZeRO-3 for inference via the Transformers integration.')
  78. parser.add_argument('--nvme-offload-dir', type=str, help='DeepSpeed: Directory to use for ZeRO-3 NVME offloading.')
  79. parser.add_argument('--local_rank', type=int, default=0, help='DeepSpeed: Optional argument for distributed setups.')
  80. parser.add_argument('--rwkv-strategy', type=str, default=None, help='The strategy to use while loading RWKV models. Examples: "cpu fp32", "cuda fp16", "cuda fp16 *30 -> cpu fp32".')
  81. parser.add_argument('--no-stream', action='store_true', help='Don\'t stream the text output in real time. This improves the text generation performance.')
  82. parser.add_argument('--settings', type=str, help='Load the default interface settings from this json file. See settings-template.json for an example.')
  83. parser.add_argument('--extensions', type=str, nargs="+", help='The list of extensions to load. If you want to load more than one extension, write the names separated by spaces.')
  84. parser.add_argument('--listen', action='store_true', help='Make the web UI reachable from your local network.')
  85. parser.add_argument('--listen-port', type=int, help='The listening port that the server will use.')
  86. parser.add_argument('--share', action='store_true', help='Create a public URL. This is useful for running the web UI on Google Colab or similar.')
  87. parser.add_argument('--verbose', action='store_true', help='Print the prompts to the terminal.')
  88. args = parser.parse_args()