Download tcod/trinity/buffer/writer/sql_writer.py from SeanWang0027/ftb-sciworld-repro: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/SeanWang0027/ftb-sciworld-repro/resolve/main/tcod/trinity/buffer/writer/sql_writer.py
- Command line
-
hf download hf://SeanWang0027/ftb-sciworld-repro/tcod/trinity/buffer/writer/sql_writer.py
-
curl -L -o sql_writer.py https://huggingface.co/SeanWang0027/ftb-sciworld-repro/resolve/main/tcod/trinity/buffer/writer/sql_writer.py
1.31 kB
| """Writer of the SQL buffer.""" | |
| import ray | |
| from trinity.buffer.buffer_writer import BufferWriter | |
| from trinity.buffer.storage.sql import SQLStorage | |
| from trinity.common.config import StorageConfig | |
| from trinity.common.constants import StorageType | |
| class SQLWriter(BufferWriter): | |
| """Writer of the SQL buffer.""" | |
| def __init__(self, config: StorageConfig) -> None: | |
| assert config.storage_type == StorageType.SQL.value | |
| # we only support write RFT algorithm buffer for now | |
| self.wrap_in_ray = config.wrap_in_ray | |
| self.db_wrapper = SQLStorage.get_wrapper(config) | |
| def write(self, data: list) -> None: | |
| if self.wrap_in_ray: | |
| ray.get(self.db_wrapper.write.remote(data)) | |
| else: | |
| self.db_wrapper.write(data) | |
| async def write_async(self, data): | |
| if self.wrap_in_ray: | |
| await self.db_wrapper.write.remote(data) | |
| else: | |
| self.db_wrapper.write(data) | |
| async def acquire(self) -> int: | |
| if self.wrap_in_ray: | |
| return await self.db_wrapper.acquire.remote() | |
| else: | |
| return 0 | |
| async def release(self) -> int: | |
| if self.wrap_in_ray: | |
| return await self.db_wrapper.release.remote() | |
| else: | |
| self.db_wrapper.release() | |
| return 0 | |