Skip to content

Instantly share code, notes, and snippets.

@jwickens
jwickens / database.py
Last active April 7, 2025 05:26
Pytorch-like iterable Dataset example backed by async iterator (postgres)
import asyncpg
async def create_pool():
pool = await asyncpg.create_pool(
database="research",
user="jwickens",
setup=setup_connection,
min_size=32,
max_size=32
)
@99991
99991 / gpu_usage.py
Last active September 9, 2022 21:40
Get NVIDIA GPU memory usage and find free GPUs using nvidia-smi
import subprocess, getpass
def get_gpu_usage():
"""
Returns a dict which contains information about memory usage for each GPU.
In the following output, the GPU with id "0" uses 5774 MB of 16280 MB.
253 MB are used by other users, which means that we are using 5774 - 253 MB.
{