Download src/orchestrator/prompt_queue.py from tahamajs/AsyncTensorRLHF: direct link, hf CLI and curl.
- Browser
- Download file 725 Bytes
-
https://huggingface.co/tahamajs/AsyncTensorRLHF/resolve/main/src/orchestrator/prompt_queue.py
- Command line
-
hf download hf://tahamajs/AsyncTensorRLHF/src/orchestrator/prompt_queue.py
-
curl -L -o prompt_queue.py https://huggingface.co/tahamajs/AsyncTensorRLHF/resolve/main/src/orchestrator/prompt_queue.py
725 Bytes
| """Prompt queue actor for orchestration. | |
| The queue wraps an asyncio.Queue. It provides | |
| `add_prompt` (async) and `get_prompt` methods that can be called | |
| from Ray actors or standalone threads. | |
| """ | |
| import asyncio | |
| try: | |
| import ray | |
| ray_remote = ray.remote | |
| except ImportError: | |
| ray = None | |
| def ray_remote(cls): | |
| return cls | |
| class PromptQueue: | |
| def __init__(self, maxsize: int = 0): | |
| self._queue = asyncio.Queue(maxsize=maxsize) | |
| async def add_prompt(self, prompt: dict): | |
| await self._queue.put(prompt) | |
| return True | |
| async def get_prompt(self): | |
| prompt = await self._queue.get() | |
| return prompt | |
| def size(self): | |
| return self._queue.qsize() | |