run_server.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import configargparse
  2. from hivemind.proto.runtime_pb2 import CompressionType
  3. from hivemind.utils.limits import increase_file_limit
  4. from hivemind.utils.logging import get_logger, use_hivemind_log_handler
  5. from humanfriendly import parse_size
  6. from src.server.server import Server
  7. use_hivemind_log_handler("in_root_logger")
  8. logger = get_logger(__file__)
  9. def main():
  10. # fmt:off
  11. parser = configargparse.ArgParser(default_config_files=["config.yml"])
  12. parser.add('-c', '--config', required=False, is_config_file=True, help='config file path')
  13. parser.add_argument('--converted_model_name_or_path', type=str, default='bigscience/test-bloomd-6b3',
  14. help="path or name of a pretrained model, converted with cli/convert_model.py (see README.md)")
  15. parser.add_argument('--num_blocks', type=int, default=None, help="The number of blocks to serve")
  16. parser.add_argument('--block_indices', type=str, default=None, help="Specific block indices to serve")
  17. parser.add_argument('--prefix', type=str, default=None, help="Announce all blocks with this prefix. By default,"
  18. "use the same name as in the converted model.")
  19. parser.add_argument('--host_maddrs', nargs='+', default=['/ip4/0.0.0.0/tcp/0'], required=False,
  20. help='Multiaddrs to listen for external connections from other p2p instances; default: all IPv4 and TCP: /ip4/0.0.0.0/tcp/0')
  21. parser.add_argument('--announce_maddrs', nargs='+', default=None, required=False,
  22. help='Visible multiaddrs the host announces for external connections from other p2p instances')
  23. parser.add_argument('--compression', type=str, default='NONE', required=False, help='Tensor compression communication')
  24. parser.add_argument('--num_handlers', type=int, default=8, required=False,
  25. help='server will use this many processes to handle incoming requests')
  26. parser.add_argument('--min_batch_size', type=int, default=1,
  27. help='Minimum required batch size for all expert operations')
  28. parser.add_argument('--max_batch_size', type=int, default=16384,
  29. help='The total number of tokens in the same batch will not exceed this value')
  30. parser.add_argument('--prefetch_batches', type=int, default=1, required=False,
  31. help='Pre-form this many subsequent batches while GPU is processing the current one')
  32. parser.add_argument('--sender_threads', type=int, default=1, required=False,
  33. help='Use this many threads to pass results/exceptions from Runtime to Pools')
  34. parser.add_argument('--inference_max_length', type=int, default=16384,
  35. help='Maximum total sequence length permitted per inference, defaults to 16384 tokens')
  36. parser.add_argument('--cache_dir', type=str, default=None,
  37. help='Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.')
  38. parser.add_argument('--device', type=str, default=None, required=False,
  39. help='all experts will use this device in torch notation; default: cuda if available else cpu')
  40. parser.add_argument("--torch_dtype", type=str, default="auto",
  41. help="Use this dtype to store block weights and do computations. "
  42. "By default, respect the dtypes in the pre-trained state dict.")
  43. parser.add_argument('--attn_cache_size', type=str, default=None,
  44. help='The size of GPU memory allocated for storing past attention keys/values between inference'
  45. ' steps; examples: 500MB or 1.2GB or 1073741824 (bytes); be warned: 1KB != 1KiB')
  46. parser.add_argument('--revision', type=str, default='main',
  47. help="The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models"
  48. "and other artifacts on huggingface.co, so `revision` can be any identifier allowed by git.")
  49. parser.add_argument('--throughput',
  50. type=lambda value: value if value in ['auto', 'eval'] else float(value),
  51. default='auto',
  52. help='Expected server throughput (a float measured in RPS). '
  53. 'If set to "auto" (default), the script evaluates network and compute throughput '
  54. 'on the first run and uses these estimates for future runs. '
  55. 'If set to "eval", the script re-evaluates the throughput and overrides the cache.')
  56. parser.add_argument('--update_period', type=float, required=False, default=30,
  57. help='Server will report experts to DHT once in this many seconds')
  58. parser.add_argument('--expiration', type=float, required=False, default=None,
  59. help='DHT entries will expire after this many seconds')
  60. parser.add_argument('--initial_peers', type=str, nargs='*', required=False, default=[],
  61. help='multiaddrs of one or more active DHT peers (if you want to join an existing DHT)')
  62. parser.add_argument('--increase_file_limit', action='store_true',
  63. help='On *nix, this will increase the max number of processes '
  64. 'a server can spawn before hitting "Too many open files"; Use at your own risk.')
  65. parser.add_argument('--stats_report_interval', type=int, required=False,
  66. help='Interval between two reports of batch processing performance statistics')
  67. parser.add_argument('--custom_module_path', type=str, required=False,
  68. help='Path of a file with custom nn.modules, wrapped into special decorator')
  69. parser.add_argument('--identity_path', type=str, required=False, help='Path to identity file to be used in P2P')
  70. parser.add_argument("--use_auth_token", type=str, default=None, help="auth token for from_pretrained")
  71. parser.add_argument('--load_in_8bit', action='store_true', help='Convert the loaded model into mixed-8bit quantized model.')
  72. # fmt:on
  73. args = vars(parser.parse_args())
  74. args.pop("config", None)
  75. if args.pop("increase_file_limit"):
  76. increase_file_limit()
  77. compression_type = args.pop("compression")
  78. compression = getattr(CompressionType, compression_type)
  79. attn_cache_size = args.pop("attn_cache_size")
  80. if attn_cache_size is not None:
  81. attn_cache_size = parse_size(attn_cache_size)
  82. assert isinstance(
  83. attn_cache_size, (int, type(None))
  84. ), "unrecognized value for attention_cache_bytes, examples: 1.5GB or 1500MB or 1572864000 (bytes)"
  85. use_auth_token = args.pop("use_auth_token")
  86. args["use_auth_token"] = True if use_auth_token in ("True", "true", "") else use_auth_token
  87. server = Server.create(**args, start=True, compression=compression, attn_cache_size=attn_cache_size)
  88. try:
  89. server.join()
  90. except KeyboardInterrupt:
  91. logger.info("Caught KeyboardInterrupt, shutting down")
  92. finally:
  93. server.shutdown()
  94. if __name__ == "__main__":
  95. main()