Package 

Class Module


  • 
    public class Module
    
                        

    Java wrapper for ExecuTorch Module.

    Warning: These APIs are experimental and subject to change without notice

    • Method Summary

      Modifier and Type Method Description
      static Module load(String modelPath, int loadMode) Loads a serialized ExecuTorch module from the specified path on the disk.
      static Module load(String modelPath) Loads a serialized ExecuTorch module from the specified path on the disk to run on CPU.
      Array<EValue> forward(Array<EValue> inputs) Runs the 'forward' method of this module with the specified arguments.
      Array<EValue> execute(String methodName, Array<EValue> inputs) Runs the specified method of this module with the specified arguments.
      int loadMethod(String methodName) Load a method on this module.
      Array<String> readLogBuffer() Retrieve the in-memory log buffer, containing the most recent ExecuTorch log entries.
      void destroy() Explicitly destroys the native torch::jit::Module.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • load

         static Module load(String modelPath, int loadMode)

        Loads a serialized ExecuTorch module from the specified path on the disk.

        Parameters:
        modelPath - path to file that contains the serialized ExecuTorch module.
        loadMode - load mode for the module.
      • load

         static Module load(String modelPath)

        Loads a serialized ExecuTorch module from the specified path on the disk to run on CPU.

        Parameters:
        modelPath - path to file that contains the serialized ExecuTorch module.
      • forward

         Array<EValue> forward(Array<EValue> inputs)

        Runs the 'forward' method of this module with the specified arguments.

        Parameters:
        inputs - arguments for the ExecuTorch module's 'forward' method.
      • execute

         Array<EValue> execute(String methodName, Array<EValue> inputs)

        Runs the specified method of this module with the specified arguments.

        Parameters:
        methodName - name of the ExecuTorch method to run.
        inputs - arguments that will be passed to ExecuTorch method.
      • loadMethod

         int loadMethod(String methodName)

        Load a method on this module. This might help with the first time inference performance,because otherwise the method is loaded lazily when it's execute. Note: this function issynchronous, and will block until the method is loaded. Therefore, it is recommended to callthis on a background thread. However, users need to make sure that they don't execute beforethis function returns.

      • readLogBuffer

         Array<String> readLogBuffer()

        Retrieve the in-memory log buffer, containing the most recent ExecuTorch log entries.

      • destroy

         void destroy()

        Explicitly destroys the native torch::jit::Module. Calling this method is not required, as thenative object will be destroyed when this object is garbage-collected. However, the timing ofgarbage collection is not guaranteed, so proactively calling {@code destroy} can free memorymore quickly. See resetNative.