-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from michaelfeil/feature-refactor
Improve real-time / sleep strategy, async await for queues and result futures
- Loading branch information
Showing
6 changed files
with
209 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
import asyncio | ||
import time | ||
from dataclasses import dataclass, field | ||
from typing import Optional | ||
from uuid import uuid4 | ||
|
||
import numpy as np | ||
|
||
from infinity_emb.inference.threading_asyncio import EventTS | ||
# from infinity_emb.inference.threading_asyncio import EventTS | ||
|
||
NpEmbeddingType = np.ndarray | ||
|
||
|
||
@dataclass | ||
@dataclass(order=True) | ||
class EmbeddingResult: | ||
sentence: str | ||
event: EventTS | ||
uuid: str = field(default_factory=lambda: str(uuid4())) | ||
created: float = field(default_factory=time.time) | ||
embedding: Optional[NpEmbeddingType] = None | ||
sentence: str = field(compare=False) | ||
uuid: str = field(default_factory=lambda: str(uuid4()), compare=False) | ||
embedding: Optional[NpEmbeddingType] = field(default=None, compare=False) | ||
future: Optional[asyncio.Future] = field(default=None, compare=False) | ||
# event: Optional[EventTS] = field(default=None, compare=False) | ||
|
||
|
||
@dataclass(order=True) | ||
class PrioritizedQueueItem: | ||
priority: int | ||
item: EmbeddingResult = field(compare=False) | ||
timestamp: float = field(default_factory=time.time, compare=False) | ||
|
||
|
||
@dataclass | ||
class OverloadStatus: | ||
queue_fraction: float | ||
queue_absolute: int | ||
results_absolute: int | ||
|
||
|
||
if __name__ == "__main__": | ||
import bisect | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
tp = ThreadPoolExecutor() | ||
r1 = EmbeddingResult(5, "hello") | ||
r2 = EmbeddingResult(6, "hello_") | ||
r3 = EmbeddingResult(6, "hello_") | ||
r1 < r2 | ||
l1 = [] | ||
bisect.insort(l1, r1) | ||
bisect.insort(l1, r2) |
Oops, something went wrong.