Skip to content

Instantly share code, notes, and snippets.

View t-vi's full-sized avatar
🌍
Creating fun and friendly AIs

Thomas Viehmann t-vi

🌍
Creating fun and friendly AIs
View GitHub Profile
@t-vi
t-vi / validation_set_split.py
Last active August 18, 2017 16:08
Torch validation set split (MNIST example)
import torch.utils.data
from torchvision import datasets, transforms
class PartialDataset(torch.utils.data.Dataset):
def __init__(self, parent_ds, offset, length):
self.parent_ds = parent_ds
self.offset = offset
self.length = length
assert len(parent_ds)>=offset+length, Exception("Parent Dataset not long enough")
super(PartialDataset, self).__init__()
@t-vi
t-vi / LSTM-bidir-memory-consumption.py
Created March 21, 2017 21:22
Torch bidirectional LSTM memory consumption
#!/usr/bin/python3
import torch
from torch.autograd import Variable
import torch.nn as nn
import gc
# helper function to get rss size, see stat(5) under statm. This is in pages (4k on my linux)
def memory_usage():
return int(open('/proc/self/statm').read().split()[1])
@t-vi
t-vi / main-gpu.py
Created March 20, 2017 21:31
Memory usage of LSTM
# This is taken from https://github.com/yunjey/pytorch-tutorial with just a few changes.
# Please see there for copyright and license information and use that copy.
import torch
import torch.nn as nn
import torchvision.datasets as dsets
import torchvision.transforms as transforms
from torch.autograd import Variable
import gc