run_server.py 6.1 KB

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