MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / DistributedInferenceService

Class DistributedInferenceService

lightx2v/server/services/inference/service.py:8–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class DistributedInferenceService:
9 def __init__(self):
10 self.worker = None
11 self.is_running = False
12 self.args = None
13
14 def start_distributed_inference(self, args) -> bool:
15 self.args = args
16 if self.is_running:
17 logger.warning("Distributed inference service is already running")
18 return True
19
20 try:
21 self.worker = TorchrunInferenceWorker()
22
23 if not self.worker.init(args):
24 raise RuntimeError("Worker initialization failed")
25
26 self.is_running = True
27 logger.info(f"Rank {self.worker.rank} inference service started successfully")
28 return True
29
30 except Exception as e:
31 logger.error(f"Error starting inference service: {str(e)}")
32 self.stop_distributed_inference()
33 return False
34
35 def stop_distributed_inference(self):
36 if not self.is_running:
37 return
38
39 try:
40 if self.worker:
41 self.worker.cleanup()
42 logger.info("Inference service stopped")
43 except Exception as e:
44 logger.error(f"Error stopping inference service: {str(e)}")
45 finally:
46 self.worker = None
47 self.is_running = False
48
49 async def submit_task_async(self, task_data: dict) -> Optional[dict]:
50 if not self.is_running or not self.worker:
51 logger.error("Inference service is not started")
52 return None
53
54 if self.worker.rank != 0:
55 return None
56
57 try:
58 if self.worker.processing:
59 logger.info(f"Waiting for previous task to complete before processing task {task_data.get('task_id')}")
60
61 self.worker.processing = True
62 result = await self.worker.process_request(task_data)
63 self.worker.processing = False
64 return result
65 except Exception as e:

Callers 1

run_serverFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected