OleehyO opened a new pull request, #17464:
URL: https://github.com/apache/tvm/pull/17464

   Java API is still using the outdated initialization method for 
`GraphModule`, which has led to issues where the old API no longer works as 
expected.
   
   This PR updates the Java API for `GraphModule` initialization to match the 
simplified method used in the Python API.
   
   # Background
   
   In the Python API, `GraphModule` can be initialized in a more concise way:
   
   ```python
   gm = graph_executor.GraphModule(lib["default"](dev))
   ```
   
   However, the Java API still uses the older approach:
   ```python
   gm = graph_executor.create(graph_json, lib, dev);
   gm.load_params(params);
   ```
   
   The old API is not only more verbose (two additional files need to be saved 
and loaded), but also appears to no longer be functional as expected.
   
   ---
   Here is an example of deploying 
[DepthAnything](https://github.com/DepthAnything/Depth-Anything-V2) where the 
ONNX frontend of Relay is used to create the IRModule before compiling and 
exporting. During deployment, the old initialization method seems no longer 
works (top: new method, bottom: old method): 
   
   <img width="1185" alt="截屏2024-10-14 16 38 57" 
src="https://github.com/user-attachments/assets/7197f73b-5e67-49fb-bc64-6446843c4ab6";>
   
   <img width="1190" alt="截屏2024-10-14 16 40 46" 
src="https://github.com/user-attachments/assets/92c088df-66c7-45ec-9042-aa686c1c4841";>
   
   ---
   
   To address these, this PR introduces a new initialization method for 
GraphModule in the Java API, aligning it with the simplified Python API.
   
   # Usage Example
   
   Java: 
   ```java
   Device dev = Device.cpu();
   Module lib = Module.load(libPath);
   Module mod = lib.getFunction("default").call(dev).asModule();  // The 
current Java API does not support calling Device types in Functions
   ```
   
   equivalent Python:
   ```python
   dev = tvm.device('cpu')
   lib = tvm.runtime.load_module(libPath)
   gm = graph_executor.GraphModule(lib["default"](dev))
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to