Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Jong Wook Kim
commited on
Commit
•
6d90da5
1
Parent(s):
12459ab
using sys.executable for subprocess calls (fixes #8)
Browse files- detector/server.py +2 -2
- detector/train.py +1 -1
detector/server.py
CHANGED
@@ -68,7 +68,7 @@ def serve_forever(server, model, tokenizer, device):
|
|
68 |
globals()['tokenizer'] = tokenizer
|
69 |
globals()['device'] = device
|
70 |
|
71 |
-
log('Ready to serve')
|
72 |
server.serve_forever()
|
73 |
|
74 |
|
@@ -93,7 +93,7 @@ def main(checkpoint, port=8080, device='cuda' if torch.cuda.is_available() else
|
|
93 |
server = HTTPServer(('0.0.0.0', port), RequestHandler)
|
94 |
|
95 |
# avoid calling CUDA API before forking; doing so in a subprocess is fine.
|
96 |
-
num_workers = int(subprocess.check_output([
|
97 |
|
98 |
if num_workers <= 1:
|
99 |
serve_forever(server, model, tokenizer, device)
|
|
|
68 |
globals()['tokenizer'] = tokenizer
|
69 |
globals()['device'] = device
|
70 |
|
71 |
+
log(f'Ready to serve at http://localhost:{server.server_address[1]}')
|
72 |
server.serve_forever()
|
73 |
|
74 |
|
|
|
93 |
server = HTTPServer(('0.0.0.0', port), RequestHandler)
|
94 |
|
95 |
# avoid calling CUDA API before forking; doing so in a subprocess is fine.
|
96 |
+
num_workers = int(subprocess.check_output([sys.executable, '-c', 'import torch; print(torch.cuda.device_count())']))
|
97 |
|
98 |
if num_workers <= 1:
|
99 |
serve_forever(server, model, tokenizer, device)
|
detector/train.py
CHANGED
@@ -281,7 +281,7 @@ if __name__ == '__main__':
|
|
281 |
parser.add_argument('--weight-decay', type=float, default=0)
|
282 |
args = parser.parse_args()
|
283 |
|
284 |
-
nproc = int(subprocess.check_output([
|
285 |
"print(torch.cuda.device_count() if torch.cuda.is_available() else 1)"]))
|
286 |
if nproc > 1:
|
287 |
print(f'Launching {nproc} processes ...', file=sys.stderr)
|
|
|
281 |
parser.add_argument('--weight-decay', type=float, default=0)
|
282 |
args = parser.parse_args()
|
283 |
|
284 |
+
nproc = int(subprocess.check_output([sys.executable, '-c', "import torch;"
|
285 |
"print(torch.cuda.device_count() if torch.cuda.is_available() else 1)"]))
|
286 |
if nproc > 1:
|
287 |
print(f'Launching {nproc} processes ...', file=sys.stderr)
|