A key for the layer cache engine
| 562 | |
| 563 | @dataclass(slots=True) |
| 564 | class LayerCacheEngineKey(CacheEngineKey): |
| 565 | """A key for the layer cache engine""" |
| 566 | |
| 567 | layer_id: int = 0 |
| 568 | |
| 569 | def __hash__(self): |
| 570 | return hash( |
| 571 | ( |
| 572 | self.model_name, |
| 573 | self.world_size, |
| 574 | self.worker_id, |
| 575 | self.chunk_hash, |
| 576 | self._dtype_str, |
| 577 | self.tags, |
| 578 | self.layer_id, |
| 579 | ) |
| 580 | ) |
| 581 | |
| 582 | def __eq__(self, other): |
| 583 | if super(LayerCacheEngineKey, self).__eq__(other): |
| 584 | return self.layer_id == other.layer_id |
| 585 | |
| 586 | return False |
| 587 | |
| 588 | def to_string(self): |
| 589 | s = ( |
| 590 | f"{self.model_name}@{self.world_size}" |
| 591 | f"@{self.worker_id}@{self.chunk_hash_hex}@{self._dtype_str}@{self.layer_id}" |
| 592 | ) |
| 593 | if self.tags is not None and len(self.tags) != 0: |
| 594 | tags = [f"{k}%{v}" for k, v in self.tags] |
| 595 | s += "@" + "@".join(tags) |
| 596 | return s |
| 597 | |
| 598 | def split_layers(self, num_layers: int) -> List["LayerCacheEngineKey"]: |
| 599 | """Split the key into multiple keys for each layer""" |
| 600 | keys = [] |
| 601 | for layer_id in range(num_layers): |
| 602 | keys.append( |
| 603 | LayerCacheEngineKey( |
| 604 | model_name=self.model_name, |
| 605 | world_size=self.world_size, |
| 606 | worker_id=self.worker_id, |
| 607 | chunk_hash=self.chunk_hash, |
| 608 | dtype=self.dtype, |
| 609 | request_configs=self.request_configs, |
| 610 | layer_id=layer_id, |
| 611 | ) |
| 612 | ) |
| 613 | return keys |
| 614 | |
| 615 | @staticmethod |
| 616 | def from_string(s): |
| 617 | parts = s.split("@") |
| 618 | if len(parts) < 6: |
| 619 | raise ValueError(f"Invalid key string: {s}") |
| 620 | request_configs = None |
| 621 | if len(parts) >= 7: |
no outgoing calls