It’s possible to that using the C++ API, which we can now use from Java with the JavaCPP Presets for PyTorch:
  
      
      github.com
  
  
    

bytedeco/javacpp-presets 4

master/pytorch

  The missing Java distribution of native C++ libraries