refactor: 页状态移入 PagedCache,Task 纯化为域对象

- PagedCache 增 task_alloc/task_free/task_extend/task_cached/task_record_hashes/make_table_tensor
- Task 移除 page_table/n_pages/_prefix_cached_tokens/_pages_freed
- Executor 移除 _PageState,页操作全部委托 PagedCache
- CacheView.gather 截断逻辑下沉到 PagedCache.gather
- 各类补充单行职责 docstring
This commit is contained in:
2026-05-11 14:42:39 +08:00
parent 73d6cc0f26
commit 4753958f92
4 changed files with 98 additions and 90 deletions
+6 -4
View File
@@ -13,6 +13,8 @@ STOP = object()
class TaskStatus(Enum):
"""Task lifecycle states."""
PENDING = "pending"
RUNNING = "running"
FINISHED = "finished"
@@ -20,6 +22,8 @@ class TaskStatus(Enum):
class Task:
"""Single generation request: prompt, sampling params, output state."""
def __init__(
self,
task_id: str,
@@ -41,13 +45,9 @@ class Task:
self.output_ids: List[int] = []
self.input_tokens: int = 0
self.output_tokens: int = 0
self.page_table: List[int] = []
self.n_pages: int = 0
self._prefix_cached_tokens: int = 0
self.arrival_time = time.time()
self.finish_time: Optional[float] = None
self.stream_callback = stream_callback
self._pages_freed: bool = False
@property
def next_pos(self) -> int:
@@ -62,6 +62,8 @@ class Task:
class TaskManager:
"""Thread-safe task queues and lifecycle transitions (no page ops)."""
def __init__(
self,
tokenizer: AutoTokenizer,