yes, you are right… i checked them and they work fine(for one step only)
This is the error after i removed the condition:
RuntimeError                              Traceback (most recent call last)
<ipython-input-5-d5ac286e099d> in <module>()
     38             print 'loss',loss
     39             loss_ += loss.data[0]
---> 40             loss.backward()
     41             optimizer.step()
     42             #torch.cuda.empty_cache()

/home/eslam/anaconda2/lib/python2.7/site-packages/torch/tensor.pyc in backward(self, gradient, retain_graph, create_graph)
     91                 products. Defaults to ``False``.
     92         """
---> 93         torch.autograd.backward(self, gradient, retain_graph, create_graph)
     94 
     95     def register_hook(self, hook):

/home/eslam/anaconda2/lib/python2.7/site-packages/torch/autograd/__init__.pyc in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables)
     87     Variable._execution_engine.run_backward(
     88         tensors, grad_tensors, retain_graph, create_graph,
---> 89         allow_unreachable=True)  # allow_unreachable flag
     90 
     91 

RuntimeError: cuda runtime error (2) : out of memory at /opt/conda/conda-bld/pytorch_1524577177097/work/aten/src/THC/generic/THCStorage.cu:58

and if put the break statement for only one step it raises this error:
RuntimeError                              Traceback (most recent call last)
<ipython-input-6-421d8405ce76> in <module>()
     13                          num_workers=4,
     14                          pin_memory=True)
---> 15 model = ConvNet().cuda()
     16 optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate, weight_decay=0.0)
     17 #scheduler_model = torch.optim.lr_scheduler.StepLR(optimizer, step_size=1, gamma=1.0)

/home/eslam/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.pyc in cuda(self, device)
    247             Module: self
    248         """
--> 249         return self._apply(lambda t: t.cuda(device))
    250 
    251     def cpu(self):

/home/eslam/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.pyc in _apply(self, fn)
    174     def _apply(self, fn):
    175         for module in self.children():
--> 176             module._apply(fn)
    177 
    178         for param in self._parameters.values():

/home/eslam/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.pyc in _apply(self, fn)
    180                 # Tensors stored in modules are graph leaves, and we don't
    181                 # want to create copy nodes, so we have to unpack the data.
--> 182                 param.data = fn(param.data)
    183                 if param._grad is not None:
    184                     param._grad.data = fn(param._grad.data)

/home/eslam/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.pyc in <lambda>(t)
    247             Module: self
    248         """
--> 249         return self._apply(lambda t: t.cuda(device))
    250 
    251     def cpu(self):

RuntimeError: cuda runtime error (2) : out of memory at /opt/conda/conda-bld/pytorch_1524577177097/work/aten/src/THC/generic/THCStorage.cu:58