text-generation-inference/server/bloom_inference/cache.py
Olivier Dehaene 4c693e6524 Refactored gRPC interface
Added validation logic
2022-10-11 16:50:54 +02:00

24 lines
548 B
Python

from bloom_inference.model import Batch
from typing import Dict, Optional
class Cache:
def __init__(self):
self.cache: Dict[int, Batch] = {}
def pop(self, batch_id: int) -> Optional[Batch]:
return self.cache.pop(batch_id, None)
def set(self, entry: Batch):
if entry is not None:
self.cache[entry.batch_id] = entry
def delete(self, batch_id: int):
del self.cache[batch_id]
def clear(self):
self.cache.clear()
def __len__(self):
return len(self.cache.keys())