Skip to content

Instantly share code, notes, and snippets.

View jayelm's full-sized avatar

Jesse Mu jayelm

View GitHub Profile
@jayelm
jayelm / auto_gpu_example.py
Last active April 10, 2022 01:41
Hydra parallel sweep with joblib that waits and auto-selects free GPUs
"""
Auto GPU example with Hydra. To run, first
pip install hydra hydra-joblib-launcher --upgrade
Then run as follows
```
python auto_gpu_example.py -m n=1,2,3
```
{"data": [{"hovertemplate": "template=<NULL><br>num_frames=%{x}<br>n_all=%{y}<extra></extra>", "legendgroup": "<NULL>", "line": {"color": "#636efa", "dash": "solid"}, "marker": {"symbol": "circle"}, "mode": "lines", "name": "<NULL>", "showlegend": true, "x": [176000, 1065600, 2028800, 2544000], "xaxis": "x", "y": [0.15686274509800505, 0.0013495276653169568, 0.0005299417064122666, 0.004360465116278436], "yaxis": "y", "type": "scattergl"}, {"hovertemplate": "template=open the door<br>num_frames=%{x}<br>n_all=%{y}<extra></extra>", "legendgroup": "open the door", "line": {"color": "#EF553B", "dash": "solid"}, "marker": {"symbol": "circle"}, "mode": "lines", "name": "open the door", "showlegend": true, "x": [176000, 352000, 531200, 707200, 883200, 1065600, 1235200, 1395200, 1555200, 1718400, 1875200, 2028800, 2195200, 2371200, 2544000, 2720000, 2892800, 3065600, 3241600, 3414400, 3590400, 3763200, 3939200, 4115200, 4291200, 4467200, 4643200, 4816000, 4992000, 5168000, 5347200, 5523200, 5699200, 5875200, 6051200, 6
@jayelm
jayelm / test_shared_memory_read_write.py
Created October 22, 2021 20:27
Testing multi-process read/writes to shared memory tensor
import torch
from torch import multiprocessing as mp
import numpy as np
import time
ctx = mp.get_context("fork")
shared_arr = torch.zeros(10, dtype=torch.float32).share_memory_()
procs = []
@jayelm
jayelm / spatial_jda.py
Created June 9, 2021 20:11
L3's ShapeWorld dataset
from shapeworld.dataset import CaptionAgreementDataset
from shapeworld.generators import GenericGenerator
from shapeworld.captioners import AttributesTypeCaptioner, SpatialRelationCaptioner, ExistentialCaptioner
class SpatialJdaDataset(CaptionAgreementDataset):
dataset_name = 'spatial_jda'
def __init__(self, validation_combinations, test_combinations, caption_size, words, language=None):
@jayelm
jayelm / generate.py
Created June 9, 2021 20:10
L3 ShapeWorld generation code
#!/usr/bin/env python3
from collections import defaultdict
import numpy as np
import os
from shapeworld import dataset
import json
import itertools
#N_CAPTIONS = 5000
@jayelm
jayelm / eps_greedy_gumbel_softmax.py
Created April 26, 2021 03:53
eps_greedy_gumbel_softmax.py
import numpy as np
import torch
import torch.nn.functional as F
from torch.distributions import Gumbel
B = 1000
logits = torch.tensor([np.log(.1), np.log(.2), np.log(.7)]).unsqueeze(0).expand(B, -1)
#!/usr/bin/env python3
# Use this commit:
# 82b3c3a106a5d5f6d8afe98c34b301e3ed696865
# https://github.com/AlexKuhnle/ShapeWorld/tree/82b3c3a106a5d5f6d8afe98c34b301e3ed696865
from collections import defaultdict
import numpy as np
import os
from shapeworld import dataset
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1.145180 -0.729419 0.294109 -0.137857 0.983908 -1.214803 -0.509172 -0.340711 1.276555 1.049647 -0.082486 -1.835534 -0.182150 0.623531 -1.032927 -1.291505 -0.412877 -0.947889 0.335135 -0.536616 -1.594202 -0.179977 1.408303 -0.631926 -0.292394 0.246462 -2.305299 -0.073608 -0.758349 0.735160 -1.413949 0.303192 -0.223297 0.062672 0.835991 -0.938621 -0.871679 0.061283 -1.423315 -2.430456 -0.902132 0.926610 0.241719 -0.599141 0.926239 -0.002843 1.785787 -1.570865 -1.545609 0.734268 0.237709 1.053545 0.443135 0.702816 1.423069 0.464142 1.442585 0.436081 -0.979451 -1.533974 1.561329 1.423159 -0.378904 -1.166427 -1.169915 -0.073474 0.285773 1.082592 1.434991 -0.001535 -0.886316 -1.374243 -0.444396 -1.055432 -1.123337 -1.253592 0.988258 -1.879589 0.612668 -1.211673 0.719780 0.299395 1.371702 1.249071 1.330787 0.658092 0.740096 -0.218481 0.226011 1.495918 0.396524 0.009114 -0.210701 -0.610920 0.077490 1.630272 -0.149504 -0.591978 0.174959 1.066213 0.375805 0.859718 -1.150404 -0.541962 -0.411150 0.114656 0.634735 -0.2836