Skip to content

Instantly share code, notes, and snippets.

View jayelm's full-sized avatar

Jesse Mu jayelm

View GitHub Profile
#!/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
@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)
@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 / 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 / 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 = []
{"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 / 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
```