| 12961 | |
| 12962 | |
| 12963 | class CompletionScheduler: |
| 12964 | @dataclass |
| 12965 | class BatchItem: |
| 12966 | @dataclass |
| 12967 | class Prefill: |
| 12968 | embeddings: Optional[np.ndarray] = None |
| 12969 | positions: Optional[np.ndarray] = None |
| 12970 | non_causal: bool = False |
| 12971 | prompt_advance_to: Optional[int] = None |
| 12972 | |
| 12973 | @dataclass |
| 12974 | class Decode: |
| 12975 | completion_index: int |
| 12976 | pending_count: int |
| 12977 | accepted_draft_count: int = 0 |
| 12978 | sampled_pending_token: Optional[int] = None |
| 12979 | rollback_keep_len: Optional[int] = None |
| 12980 | rollback_accepted_draft_count: int = 0 |
| 12981 | rollback_draft_processed: bool = False |
| 12982 | deferred_accept_draft_count: Optional[int] = None |
| 12983 | deferred_truncate_draft_len: Optional[int] = None |
| 12984 | |
| 12985 | kind: Literal["prefill", "decode"] |
| 12986 | request_id: str |
| 12987 | seq_id: int |
| 12988 | start_pos: int |
| 12989 | llama_start_pos: int |
| 12990 | tokens: List[int] |
| 12991 | identity_tokens: List[int] |
| 12992 | output_indices: List[Optional[int]] |
| 12993 | output_positions: List[int] |
| 12994 | position_increments: List[int] |
| 12995 | prefill_state: Optional["CompletionScheduler.BatchItem.Prefill"] = None |
| 12996 | decode_state: Optional["CompletionScheduler.BatchItem.Decode"] = None |
| 12997 | |
| 12998 | def require_prefill(self) -> "CompletionScheduler.BatchItem.Prefill": |
| 12999 | if self.prefill_state is None: |
| 13000 | raise RuntimeError("batch item is not a prefill item") |
| 13001 | return self.prefill_state |
| 13002 | |
| 13003 | def require_decode(self) -> "CompletionScheduler.BatchItem.Decode": |
| 13004 | if self.decode_state is None: |
| 13005 | raise RuntimeError("batch item is not a decode item") |
| 13006 | return self.decode_state |
| 13007 | |
| 13008 | @property |
| 13009 | def batch_token_count(self) -> int: |
| 13010 | if ( |
| 13011 | self.prefill_state is not None |
| 13012 | and self.prefill_state.embeddings is not None |
| 13013 | ): |
| 13014 | return int(self.prefill_state.embeddings.shape[0]) |
| 13015 | return len(self.tokens) |
| 13016 | |
| 13017 | @classmethod |
| 13018 | def prefill( |
| 13019 | cls, |
| 13020 | *, |
no outgoing calls
no test coverage detected
searching dependent graphs…