|
@@ -6,17 +6,19 @@ import resource
|
|
import torch
|
|
import torch
|
|
|
|
|
|
from hivemind.server import Server
|
|
from hivemind.server import Server
|
|
|
|
+from hivemind.utils.threading import increase_file_limit
|
|
|
|
|
|
-if __name__ == '__main__':
|
|
|
|
|
|
+
|
|
|
|
+def main():
|
|
# fmt:off
|
|
# fmt:off
|
|
parser = configargparse.ArgParser(default_config_files=["config.yml"])
|
|
parser = configargparse.ArgParser(default_config_files=["config.yml"])
|
|
parser.add('-c', '--config', required=False, is_config_file=True, help='config file path')
|
|
parser.add('-c', '--config', required=False, is_config_file=True, help='config file path')
|
|
parser.add_argument('--listen_on', type=str, default='0.0.0.0:*', required=False,
|
|
parser.add_argument('--listen_on', type=str, default='0.0.0.0:*', required=False,
|
|
help="'localhost' for local connections only, '0.0.0.0' for ipv4 '::' for ipv6")
|
|
help="'localhost' for local connections only, '0.0.0.0' for ipv4 '::' for ipv6")
|
|
- parser.add_argument('--num_experts', type=int, default=None, required=False, help="run this many experts")
|
|
|
|
- parser.add_argument('--expert_pattern', type=str, default=None, required=False, help='all expert uids will follow'
|
|
|
|
- ' this pattern, e.g. "myexpert.[0:256].[0:1024]" will sample random expert uids'
|
|
|
|
- ' between myexpert.0.0 and myexpert.255.1023 . Use either num_experts and this or expert_uids')
|
|
|
|
|
|
+ parser.add_argument('--num_experts', type=int, default=None, required=False, help="The number of experts to serve")
|
|
|
|
+ parser.add_argument('--expert_pattern', type=str, default=None, required=False,
|
|
|
|
+ help='all expert uids will follow this pattern, e.g. "myexpert.[0:256].[0:1024]" will sample random expert uids'
|
|
|
|
+ ' between myexpert.0.0 and myexpert.255.1023 . Use either num_experts and this or expert_uids')
|
|
parser.add_argument('--expert_uids', type=str, nargs="*", default=None, required=False,
|
|
parser.add_argument('--expert_uids', type=str, nargs="*", default=None, required=False,
|
|
help="specify the exact list of expert uids to create. Use either this or num_experts"
|
|
help="specify the exact list of expert uids to create. Use either this or num_experts"
|
|
" and expert_pattern, not both")
|
|
" and expert_pattern, not both")
|
|
@@ -26,39 +28,39 @@ if __name__ == '__main__':
|
|
parser.add_argument('--num_handlers', type=int, default=None, required=False,
|
|
parser.add_argument('--num_handlers', type=int, default=None, required=False,
|
|
help='server will use this many processes to handle incoming requests')
|
|
help='server will use this many processes to handle incoming requests')
|
|
parser.add_argument('--max_batch_size', type=int, default=16384, required=False,
|
|
parser.add_argument('--max_batch_size', type=int, default=16384, required=False,
|
|
- help='total num examples in the same batch will not exceed this value')
|
|
|
|
|
|
+ help='The total number of examples in the same batch will not exceed this value')
|
|
parser.add_argument('--device', type=str, default=None, required=False,
|
|
parser.add_argument('--device', type=str, default=None, required=False,
|
|
help='all experts will use this device in torch notation; default: cuda if available else cpu')
|
|
help='all experts will use this device in torch notation; default: cuda if available else cpu')
|
|
parser.add_argument('--optimizer', type=str, default='adam', required=False, help='adam, sgd or none')
|
|
parser.add_argument('--optimizer', type=str, default='adam', required=False, help='adam, sgd or none')
|
|
parser.add_argument('--no_dht', action='store_true', help='if specified, the server will not be attached to a dht')
|
|
parser.add_argument('--no_dht', action='store_true', help='if specified, the server will not be attached to a dht')
|
|
- parser.add_argument('--initial_peers', type=str, nargs='*', required=False, default=[], help='one or more peers'
|
|
|
|
- ' that can welcome you to the dht, e.g. 1.2.3.4:1337 192.132.231.4:4321')
|
|
|
|
|
|
+ parser.add_argument('--initial_peers', type=str, nargs='*', required=False, default=[],
|
|
|
|
+ help='one or more peers that can welcome you to the dht, e.g. 1.2.3.4:1337 192.132.231.4:4321')
|
|
parser.add_argument('--dht_port', type=int, default=None, required=False, help='DHT node will listen on this port')
|
|
parser.add_argument('--dht_port', type=int, default=None, required=False, help='DHT node will listen on this port')
|
|
- parser.add_argument('--increase_file_limit', action='store_true', help='On *nix, this will increase the max number'
|
|
|
|
- ' of processes a server can spawn before hitting "Too many open files"; Use at your own risk.')
|
|
|
|
|
|
+ parser.add_argument('--increase_file_limit', action='store_true',
|
|
|
|
+ help='On *nix, this will increase the max number of processes '
|
|
|
|
+ 'a server can spawn before hitting "Too many open files"; Use at your own risk.')
|
|
# fmt:on
|
|
# fmt:on
|
|
args = vars(parser.parse_args())
|
|
args = vars(parser.parse_args())
|
|
args.pop('config', None)
|
|
args.pop('config', None)
|
|
optimizer = args.pop('optimizer')
|
|
optimizer = args.pop('optimizer')
|
|
if optimizer == 'adam':
|
|
if optimizer == 'adam':
|
|
- Optimizer = torch.optim.Adam
|
|
|
|
|
|
+ optim_cls = torch.optim.Adam
|
|
elif optimizer == 'sgd':
|
|
elif optimizer == 'sgd':
|
|
- Optimizer = partial(torch.optim.SGD, lr=0.01)
|
|
|
|
|
|
+ optim_cls = partial(torch.optim.SGD, lr=0.01)
|
|
elif optimizer == 'none':
|
|
elif optimizer == 'none':
|
|
- Optimizer = None
|
|
|
|
|
|
+ optim_cls = None
|
|
else:
|
|
else:
|
|
- raise ValueError("Optimizer must be adam, sgd or none")
|
|
|
|
|
|
+ raise ValueError("optim_cls must be adam, sgd or none")
|
|
|
|
|
|
if args.pop('increase_file_limit'):
|
|
if args.pop('increase_file_limit'):
|
|
- soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
|
|
|
|
- try:
|
|
|
|
- print("Setting open file limit to soft={}, hard={}".format(max(soft, 2 ** 15), max(hard, 2 ** 15)))
|
|
|
|
- resource.setrlimit(resource.RLIMIT_NOFILE, (max(soft, 2 ** 15), max(hard, 2 ** 15)))
|
|
|
|
- except:
|
|
|
|
- print("Could not increase open file limit, currently at soft={}, hard={}".format(soft, hard))
|
|
|
|
|
|
+ increase_file_limit()
|
|
|
|
|
|
try:
|
|
try:
|
|
- server = Server.create(**args, Optimizer=Optimizer, start=True, verbose=True)
|
|
|
|
|
|
+ server = Server.create(**args, optim_cls=optim_cls, start=True, verbose=True)
|
|
server.join()
|
|
server.join()
|
|
finally:
|
|
finally:
|
|
server.shutdown()
|
|
server.shutdown()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
+ main()
|