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

Mutate free variables in CommReducer in cache_write #2354

Merged
merged 2 commits into from
Dec 30, 2018

Conversation

vinx13
Copy link
Member

@vinx13 vinx13 commented Dec 29, 2018

VarReplacer in cache_write should mutate combiner of Reduce expression because CommReducer may contain free variables from outer loop.
see https://discuss.tvm.ai/t/cache-write-does-not-replace-vars-in-reducer-identity/1402

cc @tqchen

@vinx13 vinx13 changed the title [IRMutator] Mutate CommReducer Mutate free variables in CommReducer in cache_write Dec 29, 2018
@tqchen
Copy link
Member

tqchen commented Dec 29, 2018

Thanks, @vinx13 can you please add a regression test case, as per https://docs.tvm.ai/contribute/code_review.html#ensure-test-coverage

@tqchen tqchen added the status: need update need update based on feedbacks label Dec 29, 2018
@tqchen tqchen merged commit 1e78d41 into apache:master Dec 30, 2018
@tqchen tqchen added status: accepted and removed status: need update need update based on feedbacks labels Dec 30, 2018
@sgrechanik-h
Copy link
Contributor

@tqchen If variables from the outer loop are allowed in CommReducer, shouldn't we make it a proper Expr and treat combiners of Reduce expressions as proper subexpressions?

@tqchen
Copy link
Member

tqchen commented Jan 3, 2019

I agree with @sgrechanik-h this is something that needs discussion. The question is whether we should always restrict CommReducer to be pure function or allow it to be a closure, I do agree that maybe having a pure function restriction makese sense. Thanks for pointing this out.

As a followup to this, maybe a proper change would be have checks that restricts CommReducer to be pure and report error properly.

@sgrechanik-h
Copy link
Contributor

I'm not sure, I guess there must be a practical example where a combiner using an outer loop variable is necessary, since @vinx13 started to fix it. On the other hand, in some cases such dependencies may be expressed with tuple inputs if CommReducer's purity is important.

@vinx13
Copy link
Member Author

vinx13 commented Jan 4, 2019

@sgrechanik-h
My use case is roi pooling. Each output element is maximum of a roi. If roi is empty, the output is 0, instead of the -MAX_FLOAT. In this case, identity value of combiner depends on outer loop index.
Note that I cannot nest the reduction in a if-else statement since reductions can only be in the top level https://github.com/dmlc/tvm/blob/151f550b2ee5050c74f632679a1c1d86fcea2482/src/op/compute_op.cc#L536

FrozenGene pushed a commit to FrozenGene/tvm that referenced this pull request Jan 10, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
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.

3 participants