Class Symbol

java.lang.Object
ai.djl.util.NativeResource<com.sun.jna.Pointer>
ai.djl.mxnet.engine.Symbol
All Implemented Interfaces:
AutoCloseable

public class Symbol extends ai.djl.util.NativeResource<com.sun.jna.Pointer>
Symbol is an internal helper for symbolic model graphs used by the SymbolBlock.
See Also:
  • Method Details

    • load

      public static Symbol load(MxNDManager manager, String path)
      Loads a symbol from a path.
      Parameters:
      manager - the manager to load the symbol to
      path - the path to the symbol file
      Returns:
      the new symbol
    • loadJson

      public static Symbol loadJson(MxNDManager manager, String json)
      Loads a symbol from a json string.
      Parameters:
      manager - the manager to load the symbol to
      json - the json string of the symbol.
      Returns:
      the new symbol
    • getArgNames

      public String[] getArgNames()
      Returns the symbol argument names.
      Returns:
      the symbol argument names
    • getAuxNames

      public String[] getAuxNames()
      Returns the MXNet auxiliary states for the symbol.
      Returns:
      the MXNet auxiliary states for the symbol
    • getAllNames

      public String[] getAllNames()
      Returns the symbol names.
      Returns:
      the symbol names
    • getOutputNames

      public String[] getOutputNames()
      Returns the symbol outputs.
      Returns:
      the symbol outputs
    • copy

      public Symbol copy()
      Copies the symbol.
      Returns:
      a new copy of the symbol
    • get

      public Symbol get(int index)
      Returns the output symbol by index.
      Parameters:
      index - the index of the output
      Returns:
      the symbol output as a new symbol
    • get

      public Symbol get(String name)
      Returns the output symbol with the given name.
      Parameters:
      name - the name of the symbol to return
      Returns:
      the output symbol
      Throws:
      IllegalArgumentException - Thrown if no output matches the name
    • getInternals

      public Symbol getInternals()
      Returns the symbol internals.
      Returns:
      the symbol internals symbol
    • getLayerNames

      public List<String> getLayerNames()
      Returns the list of names for all internal outputs.
      Returns:
      a list of names
    • inferShape

      public Map<String,ai.djl.ndarray.types.Shape> inferShape(ai.djl.util.PairList<String,ai.djl.ndarray.types.Shape> pairs)
      Infers the shapes for all parameters inside a symbol from the given input shapes.
      Parameters:
      pairs - the given input name and shape
      Returns:
      a map of arguments with names and shapes
    • optimizeFor

      public Symbol optimizeFor(String backend, ai.djl.Device device)
      [Experimental] Add customized optimization on the Symbol.

      This method can be used with EIA or TensorRT for model acceleration

      Parameters:
      backend - backend name
      device - the device assigned
      Returns:
      optimized Symbol
    • toJsonString

      public String toJsonString()
      Converts Symbol to json string for saving purpose.
      Returns:
      the json string
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class ai.djl.util.NativeResource<com.sun.jna.Pointer>