| import os | |
| import subprocess | |
| import torch | |
| def launch_servers(base_port=8111): | |
| num_gpus = torch.cuda.device_count() | |
| processes = [] | |
| for gpu_id in range(num_gpus): | |
| port = base_port + gpu_id | |
| env = os.environ.copy() | |
| env["CUDA_VISIBLE_DEVICES"] = str(gpu_id) | |
| cmd = [ | |
| "python", "vlac_service.py", # 你写的 FastAPI 代码文件 | |
| "--port", str(port) | |
| ] | |
| print(f"Launching GPU {gpu_id} on port {port}") | |
| p = subprocess.Popen(cmd, env=env) | |
| processes.append(p) | |
| for p in processes: | |
| p.wait() | |
| if __name__ == "__main__": | |
| launch_servers() | |