From: Francois Fleuret Date: Sun, 15 Jan 2017 20:09:55 +0000 (+0100) Subject: Make it easier to check with cuda. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=501034fda227664ac04ab5dd2d912f768bcd70e4;p=dagnn.git Make it easier to check with cuda. --- diff --git a/test-dagnn.lua b/test-dagnn.lua index e34ee02..cec37d2 100755 --- a/test-dagnn.lua +++ b/test-dagnn.lua @@ -21,6 +21,9 @@ require 'torch' require 'nn' + +-- require 'cunn' + require 'dagnn' torch.setdefaulttensortype('torch.DoubleTensor') @@ -57,7 +60,7 @@ function checkGrad(model, criterion, input, target, epsilon) local num = (loss1 - loss0) / (2 * epsilon) if num ~= ana then - err = math.max(err, math.abs(num - ana) / math.abs(num)) + err = math.max(err, math.abs(num - ana) / math.max(epsilon, math.abs(num))) end end @@ -111,10 +114,13 @@ model = nn.Sequential() criterion = nn.MSECriterion() --- model:cuda() --- criterion:cuda() --- torch.setdefaulttensortype('torch.CudaTensor') --- epsilon = 1e-4 +if cunn then + print("Using CUDA") + model:cuda() + criterion:cuda() + torch.setdefaulttensortype('torch.CudaTensor') + epsilon = 1e-3 +end local input = torch.Tensor(30, 50):uniform() local output = model:updateOutput(input):clone()