Voila! It worked. With minors tweaks in my code, I passed through this error but as you can see, I need to average the loss before I can implement backpropagation, but I encounter the following error
        loss = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8
        loss = loss.mean()
        print(loss.dtype)
        loss.backward()

Output:
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
 in 
     32         loss = loss.mean()
     33         print(loss.dtype)
---> 34         loss.backward()   # Backward pass
     35         optimizer.step()
     36 

~\Anaconda3\lib\site-packages\torch\tensor.py in backward(self, gradient, retain_graph, create_graph)
    193                 products. Defaults to ``False``.
    194         """
--> 195         torch.autograd.backward(self, gradient, retain_graph, create_graph)
    196 
    197     def register_hook(self, hook):

~\Anaconda3\lib\site-packages\torch\autograd\__init__.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables)
     97     Variable._execution_engine.run_backward(
     98         tensors, grad_tensors, retain_graph, create_graph,
---> 99         allow_unreachable=True)  # allow_unreachable flag
    100 
    101 

RuntimeError: expected dtype Float but got dtype Long


As you can see, the dtype of loss is float but I am still getting this error