args.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import argparse
  2. import os
  3. # Additional argparse types
  4. def path(string):
  5. if not string:
  6. return ''
  7. s = os.path.expanduser(string)
  8. if not os.path.exists(s):
  9. raise argparse.ArgumentTypeError(f'No such file or directory: "{string}"')
  10. return s
  11. def file_path(string):
  12. if not string:
  13. return ''
  14. s = os.path.expanduser(string)
  15. if not os.path.isfile(s):
  16. raise argparse.ArgumentTypeError(f'No such file: "{string}"')
  17. return s
  18. def dir_path(string):
  19. if not string:
  20. return ''
  21. s = os.path.expanduser(string)
  22. if not os.path.isdir(s):
  23. raise argparse.ArgumentTypeError(f'No such directory: "{string}"')
  24. return s
  25. parser = argparse.ArgumentParser(prog='langchina-ChatGLM',
  26. description='基于langchain和chatGML的LLM文档阅读器')
  27. parser.add_argument('--no-remote-model', action='store_true', default=False, help='remote in the model on loader checkpoint, if your load local model to add the ` --no-remote-model`')
  28. parser.add_argument('--model', type=str, default='chatglm-6b', help='Name of the model to load by default.')
  29. parser.add_argument('--lora', type=str, help='Name of the LoRA to apply to the model by default.')
  30. parser.add_argument("--model-dir", type=str, default='model/', help="Path to directory with all the models")
  31. parser.add_argument("--lora-dir", type=str, default='loras/', help="Path to directory with all the loras")
  32. # Accelerate/transformers
  33. parser.add_argument('--cpu', action='store_true', help='Use the CPU to generate text. Warning: Training on CPU is extremely slow.')
  34. parser.add_argument('--auto-devices', action='store_true', help='Automatically split the model across the available GPU(s) and CPU.')
  35. parser.add_argument('--gpu-memory', type=str, 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. You can also set values in MiB like --gpu-memory 3500MiB.')
  36. parser.add_argument('--cpu-memory', type=str, help='Maximum CPU memory in GiB to allocate for offloaded weights. Same as above.')
  37. parser.add_argument('--load-in-8bit', action='store_true', help='Load the model with 8-bit precision.')
  38. parser.add_argument('--bf16', action='store_true', help='Load the model with bfloat16 precision. Requires NVIDIA Ampere GPU.')
  39. args = parser.parse_args([])
  40. # Generares dict with a default value for each argument
  41. DEFAULT_ARGS = vars(args)