获取 token 当前负载。 Returns: (inflight, remaining) remaining 为 None 表示无限制
(self, token_id: int, for_image_generation: bool, for_video_generation: bool)
| 57 | self._video_pending[token_id] = current - 1 |
| 58 | |
| 59 | async def _get_token_load(self, token_id: int, for_image_generation: bool, for_video_generation: bool) -> tuple[int, Optional[int]]: |
| 60 | """获取 token 当前负载。 |
| 61 | |
| 62 | Returns: |
| 63 | (inflight, remaining) |
| 64 | remaining 为 None 表示无限制 |
| 65 | """ |
| 66 | if not self.concurrency_manager: |
| 67 | return 0, None |
| 68 | |
| 69 | if for_image_generation: |
| 70 | inflight = await self.concurrency_manager.get_image_inflight(token_id) |
| 71 | remaining = await self.concurrency_manager.get_image_remaining(token_id) |
| 72 | pending = await self._get_pending_count(token_id, True, False) |
| 73 | effective_inflight = inflight + pending |
| 74 | if remaining is not None: |
| 75 | remaining = max(0, remaining - pending) |
| 76 | return effective_inflight, remaining |
| 77 | |
| 78 | if for_video_generation: |
| 79 | inflight = await self.concurrency_manager.get_video_inflight(token_id) |
| 80 | remaining = await self.concurrency_manager.get_video_remaining(token_id) |
| 81 | pending = await self._get_pending_count(token_id, False, True) |
| 82 | effective_inflight = inflight + pending |
| 83 | if remaining is not None: |
| 84 | remaining = max(0, remaining - pending) |
| 85 | return effective_inflight, remaining |
| 86 | |
| 87 | return 0, None |
| 88 | |
| 89 | async def _reserve_slot(self, token_id: int, for_image_generation: bool, for_video_generation: bool) -> bool: |
| 90 | """尝试为当前 token 预占一个生成槽位。""" |
no test coverage detected