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

[RELAY][Fix] i64 indices #5235

Merged
merged 2 commits into from
Jul 23, 2020
Merged

[RELAY][Fix] i64 indices #5235

merged 2 commits into from
Jul 23, 2020

Conversation

hzfan
Copy link
Contributor

@hzfan hzfan commented Apr 4, 2020

Fix i64 indices issues. Tests are taken from #5219.

@tqchen
Copy link
Member

tqchen commented May 15, 2020

@hzfan can you followup?

@hzfan
Copy link
Contributor Author

hzfan commented May 18, 2020

@tqchen ok, I will follow up.

@hzfan hzfan force-pushed the relay-large-tensor_pr branch 3 times, most recently from 0b16f80 to e941d98 Compare July 11, 2020 12:16
@hzfan hzfan marked this pull request as ready for review July 11, 2020 12:32
@hzfan hzfan changed the title [Relay][Fix] i64 support [Fix] i64 indices Jul 11, 2020
@hzfan
Copy link
Contributor Author

hzfan commented Jul 11, 2020

CI's green. @tqchen @kazum

tests/python/relay/test_pass_fuse_ops.py Show resolved Hide resolved
return relay.Function([x], y)

orig = before()
fuse0(tvm.IRModule.from_expr(orig))
Copy link
Member

Choose a reason for hiding this comment

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

no used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I just remove this? @kazum

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe yes, I just copied the lines from other tests in the same file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed. Thanks @kazum .

return relay.Function([x], y)

orig = before()
fuse0(tvm.IRModule.from_expr(orig))
Copy link
Member

Choose a reason for hiding this comment

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

not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@tqchen tqchen changed the title [Fix] i64 indices [RELAY][Fix] i64 indices Jul 14, 2020
@tqchen
Copy link
Member

tqchen commented Jul 14, 2020

@@ -63,7 +63,9 @@ class OperationInliner final : public StmtExprMutator {
} else {
Map<Var, PrimExpr> vmap;
for (size_t i = 0; i < args_.size(); ++i) {
vmap.Set(args_[i], op->indices[i]);
// indices into `operation_` must be in the range of its output shape,
// so we can safely cast the indices without worrying about overflow
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont understand this comment, can you try to clarify it?

Copy link
Contributor Author

@hzfan hzfan Jul 16, 2020

Choose a reason for hiding this comment

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

Sure. An example is

a_i32 = tvm.tir.const(2, “int32”)
b_i64 = tvm.tir.const(2 ** 32, “int64”)
a0 = te.placeholder((a_i32,), “a0”)
a = te.compute((a_i32,), lambda i: a0[i])
b = te.compute((b_i64,), lambda i: a[i % 2])

When we fuse a (denoted by operation_ in the comment) into b, the variable i (which is i32) in the computation of a is replaced by i % 2 (which is i64) in b. Since the original indexing variable i in a is i32, we need to cast i % 2 from i64 to i32.

By the comment, I mean i % 2 must fit in i32, because the tensor it indexes into (a) has a shape of i32.

Copy link
Contributor

Choose a reason for hiding this comment

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

i see, it makes sense that we need to cast to the original indexing type of the operator being fused into. Why though can we "safely cast the indices without worrying about overflow"? Isn't it still possible to overflow given a sufficiently large index?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. The comment is a bit misleading. I think I can change it to 'cast indices to the type of the original indexing variable'

tests/python/relay/test_pass_fuse_ops.py Show resolved Hide resolved
@zhiics
Copy link
Member

zhiics commented Jul 22, 2020

@jwfromm please take another look and approve explicitly if everything looks good to you.

@jwfromm
Copy link
Contributor

jwfromm commented Jul 23, 2020

LGTM

@zhiics zhiics merged commit 6dbc344 into apache:master Jul 23, 2020
@zhiics
Copy link
Member

zhiics commented Jul 23, 2020

Thanks @hzfan @jwfromm @tqchen @kazum

trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Aug 26, 2020
* fix

* resolve comments
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Aug 26, 2020
* fix

* resolve comments
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Sep 2, 2020
* fix

* resolve comments
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Sep 3, 2020
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.

6 participants