Skip to content

Instantly share code, notes, and snippets.

@dylandjian
dylandjian / example.py
Created May 31, 2018 20:38
Re-initialization of CUDA for every process
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.multiprocessing as multiprocessing
import time
DEVICE = torch.device("cuda")
class Model1(nn.Module):
def __init__(self):
@dylandjian
dylandjian / mdn.py
Last active May 30, 2018 04:47
MDN RNN
def gaussian_distribution(y, mu, sigma):
## Prepare the input to be transformed into a gaussian distribution
y = y.unsqueeze(1)
y = y.expand(-1, GAUSSIANS, LATENT_VEC)
res = torch.exp((-0.5 * ((y - mu) / sigma) ** 2) / TEMPERATURE)
result = MDN_CONST * res / sigma
return result
import numpy as np
from torch.autograd import Variable
import torch
import torch.nn as nn
import torch.nn.functional as F
# length of board
L = 10
@dylandjian
dylandjian / test.py
Last active April 9, 2018 09:23
PyTorch cuda device pointer error ?
import multiprocessing
import multiprocessing.pool
import torch
class NoDaemonProcess(multiprocessing.Process):
# make 'daemon' attribute always return False
def _get_daemon(self):
return False
def _set_daemon(self, value):