Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tvm4j] add GraphRuntime #1472

Merged
merged 2 commits into from
Jul 24, 2018
Merged

[tvm4j] add GraphRuntime #1472

merged 2 commits into from
Jul 24, 2018

Conversation

yzhliu
Copy link
Member

@yzhliu yzhliu commented Jul 22, 2018

GraphRuntime for Java.

@tqchen
Copy link
Member

tqchen commented Jul 23, 2018

please request reviews

*/
public static GraphModule create(String graphJson, Module libmod, TVMContext ctx) {
Module graphModule = null;
if (ctx.deviceType >= RPC.RPC_SESS_MASK) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe combine these into if P and Q instead of two separate if statements?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the current statement is more readable, the ifs inside are more about assert, rather than control flows.

value.copyTo(input);
}
fsetInput.pushArg(key).pushArg(input).invoke();
return this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular use for returning this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a common design in Java world, which enable users to do something like g.setInputs(..).setInputs(...).run()

from tvm.contrib import graph_runtime

def dump_graph_lib(target_dir):
n = 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that this is math inside of a test script but perhaps we want to avoid using single-letter variable names? We could change to dim or something like that.

n = 4
A = tvm.placeholder((n,), name='A')
B = tvm.compute(A.shape, lambda *i: A(*i) + 1.0, name='B')
s = tvm.create_schedule(B.op)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sched or schedule

@@ -57,8 +57,7 @@ public NDArrayBase copyTo(NDArrayBase target) {
/**
* Release the NDArray memory.
* <p>
* We highly recommend you to do this manually since the GC strategy is lazy
* and `finalize()` is not guaranteed to be called when GC happens.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason why this has been deleted? This info might be useful to keep.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually finalize() is guaranteed to be called finally. it just cannot be called immediately.

*/

package ml.dmlc.tvm;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps include a brief explanation as you did with other classes.

* @param value The input value.
* @return self.
*/
public GraphModule setInput(int key, NDArray value) {
Copy link
Contributor

@kevinthesun kevinthesun Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to support batch set inputs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think batched inputs can still be described as NDArray.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But here we only supports a single input key. We may want a map for multiple inputs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do g.setInput(k1, v1).setInput(k2, v2).setInput...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. User can always set input one by one. I'm thinking whether we can make the API simpler. Maybe we can do this later if it requires significant extra work.

Copy link
Member Author

@yzhliu yzhliu Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to provide another two functions� setInput(Map<String, NDArray>) and setInput(Map<Integer, NDArray>) since now users need to construct Map using Map.put(k, v) first - which is actually less convenient.

* @param value The input value
* @return self.
*/
public GraphModule setInput(String key, NDArray value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine these two setInputs using a generic method? It seems the bodies are the same.

Copy link
Member Author

@yzhliu yzhliu Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how... the types are different.

Copy link
Member

@zhiics zhiics Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind. I was thinking sth like, public <T> GraphModule setInput(T key, NDArray value). Not quite familiar with JAVA...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in java, if we do in this way we have to check and cast T to int/String manually before passing to pushArg. Moreover, users will get confused with what type is exactly supported for key since it is not specified in the function signature.

@yzhliu
Copy link
Member Author

yzhliu commented Jul 23, 2018

@markrogersjr @kevinthesun @zhiics Thanks for reviewing. Once you feel it is good to merge, please explicitly approve it: https://docs.tvm.ai/contribute/code_review.html#approve-and-request-changes-explicitly

Copy link
Member

@zhiics zhiics left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tqchen tqchen merged commit 5643846 into apache:master Jul 24, 2018
@tqchen
Copy link
Member

tqchen commented Jul 24, 2018

Thanks @yzhliu @zhiics @kevinthesun @markrogersjr this is now merged.

tqchen pushed a commit to tqchen/tvm that referenced this pull request Aug 4, 2018
sergei-mironov pushed a commit to sergei-mironov/tvm that referenced this pull request Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants