Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable used in lines 13,105 and 147 in util.py is deprecated. Comme… #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/pytorch/data/MNIST/raw/t10k-images-idx3-ubyte
Binary file not shown.
Binary file not shown.
Binary file added src/pytorch/data/MNIST/raw/t10k-labels-idx1-ubyte
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions src/pytorch/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, k):
'''
super(linearUnified, self).__init__()
self.k = k

@staticmethod
def forward(self, x, w, b):
'''
forward propagation
Expand All @@ -36,7 +36,7 @@ def forward(self, x, w, b):
self.add_buffer = x.new(x.size(0)).fill_(1)
y.addr_(self.add_buffer, b)
return y

@staticmethod
def backward(self, dy):
'''
backprop with meprop
Expand Down
4 changes: 2 additions & 2 deletions src/pytorch/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def reset_parameters(self):

def forward(self, x):
if self.unified:
return linearUnified(self.k)(x, self.w, self.b)
return linearUnified.apply(x, self.w, self.b)#add apply
else:
return linear(self.k)(x, self.w, self.b)
return linear.apply(x, self.w, self.b)#add apply

def __repr__(self):
return '{} ({} -> {} <- {}{})'.format(self.__class__.__name__,
Expand Down
12 changes: 5 additions & 7 deletions src/pytorch/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import torch.nn.functional as F
import torch.optim as optim
import torch.utils.data
from torch.autograd import Variable
from torch.autograd import Variable#deprecated- no longer supported

from model import NetLayer

Expand Down Expand Up @@ -102,8 +102,7 @@ def _train(self, model, opt):
utime = 0
tloss = 0
for bid, (data, target) in enumerate(self.trainloader):
data, target = Variable(data).cuda(), Variable(
target.view(-1)).cuda()
data, target = Variable(data).cuda(), Variable(target.view(-1)).cuda()#Deprecated- need to replace
start = torch.cuda.Event(True)
end = torch.cuda.Event(True)

Expand Down Expand Up @@ -145,8 +144,7 @@ def _evaluate(self, model, loader, name='test'):
test_loss = 0
correct = 0
for data, target in loader:
data, target = Variable(
data, volatile=True).cuda(), Variable(target).cuda()
data, target = Variable(data, volatile=True).cuda(), Variable(target).cuda()# Deprecated- need to update
output = model(data)
test_loss += F.nll_loss(output, target).data[0]
pred = output.data.max(1)[
Expand Down Expand Up @@ -204,7 +202,7 @@ def run(self, k=None, epoch=None):
start = torch.cuda.Event(True)
end = torch.cuda.Event(True)
start.record()
loss, ft, bt, ut = self._train(model, opt)
loss, ft, bt, ut = self._train(model, opt)#model is trained here
end.record()
end.synchronize()
ttime = start.elapsed_time(end)
Expand All @@ -215,7 +213,7 @@ def run(self, k=None, epoch=None):
btime.append(bt)
utime.append(ut)
# predict
curacc = self._evaluate(model, self.devloader, 'dev')
curacc = self._evaluate(model, self.devloader, 'dev')#evaluation here
if curacc > acc:
e = t
acc = curacc
Expand Down