Hi,
In general, I am afraid that you cannot do that. Only operations within torch will be tracked by autograd which enables you to do the backward and update params.
But there is one exception, which is the fact that you can extend autograd.Function and use C/C++ or python` codes easily in it to enable autograd tracking for computations that pytorch do not support internally. For instance, you cannot use numpy and still track grads, but if you can obtain derivitives manually, then you can simply create a box that does that and let you to do the backward.
Here are the links that help you throughout the process and I think documentation is clear enough for a start:

Learn about autograd:


  
      
      Paperspace Blog – 29 May 19
  
  
    

PyTorch Basics: Understanding Autograd and Computation Graphs 2

In this article, we dive into how PyTorch's Autograd engine performs automatic differentiation.


  
  
    
    
  
  



extending pytorch (autograd, nn.module, etc):


  
      pytorch.org
  
  
    

Extending PyTorch — PyTorch 1.7.0 documentation



  
  
    
    
  
  



Tutorial on a custom layer/network with manual autograd


  
      pytorch.org
  
  
    

PyTorch: Defining New autograd Functions — PyTorch Tutorials 1.7.0 documentation 1



  
  
    
    
  
  



Extending pytorch by C++/cuda and creating binding directly from C++ for pytorch:


  
      pytorch.org
  
  
    

Custom C++ and CUDA Extensions — PyTorch Tutorials 1.7.0 documentation 1



  
  
    
    
  
  



  
      pytorch.org
  
  
    

torch.utils.cpp_extension — PyTorch 1.7.0 documentation 2



  
  
    
    
  
  


Bests