Skip to content

Instantly share code, notes, and snippets.

View cgarciae's full-sized avatar

Cristian Garcia cgarciae

View GitHub Profile
@cgarciae
cgarciae / erasure.nim
Last active December 16, 2022 21:38
Type Erasure in Nim
#-------------------------------------------------------------
# types
#-------------------------------------------------------------
type C = concept type C
proc name(x: C, msg: string): string
type AnyC = object
name: proc(msg: string): string # doesn't contain C
type A = object
@cgarciae
cgarciae / client-task-pool.py
Last active May 14, 2022 23:00
client-task-pool.py
# client-task-pool.py
from aiohttp import ClientSession, TCPConnector
import asyncio
import sys
from pypeln.task import TaskPool
limit = 1000
@cgarciae
cgarciae / client-async-sem.py
Last active May 9, 2022 00:28
client-async-sem.py
# client-async-sem.py
from aiohttp import ClientSession, TCPConnector
import asyncio
import sys
limit = 1000
async def fetch(url, session):
async with session.get(url) as response:
@cgarciae
cgarciae / timed.sh
Last active May 9, 2022 00:27
timed.sh
# timed.sh
ulimit -n 3000 # increase to avoid "out of file descriptors" error
python server.py &
sleep 1 # Wait for server to start
/usr/bin/time --format "Memory usage: %MKB\tTime: %e seconds\tCPU usage: %P" "$@"
from aiohttp import ClientSession, TCPConnector
import asyncio
import sys
import pypeln as pl
limit = 1000
urls = ("http://localhost:8080/{}".format(i) for i in range(int(sys.argv[1])))
@cgarciae
cgarciae / print.txt
Last active August 25, 2021 20:01
Module print
MyModule:
b: list
- Initializer
- Parameter((5, 13), float32)
a: dict
mlps: list
- MLP:
linear1: Linear
w: Parameter((2, 3), float32)
b: Parameter((3,), float32)
from aiohttp import ClientSession
from pypeln import io
import asyncio
import sys
async def fetch(url, session):
async with session.get(url) as response:
return await response.read()
async def main():
@cgarciae
cgarciae / rsync-watch.sh
Created August 30, 2018 04:48
rsync project to server
rsync --exclude-from=.gitignore -avz -e ssh . $1
while inotifywait -r -e modify,create,delete . ; do
rsync --exclude-from=.gitignore -avz --delete -e ssh . $1
done
@cgarciae
cgarciae / resnet_random.py
Created November 16, 2020 03:26
memory leak
# PARAMETERS
MODEL = "ResNet50"
OUTPUT_DIRECTORY = "models/resnet50"
EPOCHS = 90
BATCH_SIZE = 6
IMAGE_SIZE = 224 # image size in pixels
DATASET = "imagenet2012:5.1.*" # TFDS dataset name and version
DTYPE = "float16" # float16 for mixed_precision or float32 for normal mode
LEARNING_RATE = 0.1 * BATCH_SIZE / 256.0
MOMENTUM = 0.9
model = elegy.Model(
module=MixtureModel(k=k),
loss=MixtureNLL(),
optimizer=optax.adam(3e-4),
)
model.summary(X_train[:batch_size], depth=1)
model.fit(
x=X_train,