-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Arith] DeduceBound produces relaxed bounds because of rounding up #3974
Comments
@tqchen Please let me know your thoughts, this can be fixed with a check for the sign. |
it is hard to force deduce bound to produce exact bound for every case, so ideally we should fix loop partition to respect this assumption. |
In the previous logic of loop partition, we always keep the same body of the loop, but transforms the loop to two segments.
In the loop above, imagine if deduce bound returns [0, 2], which is a relaxed set, then the loop will be transformed to
Regardless of what value deduce bound returns, such transformation was hold to be always valid. A tight bound will help us to eliminate the conditions. It could be possible that recent changes to LoopPartition no longer tries to hold that assumption, it would be great if we can look into it and fix the problem. Independently, we could work to make sure DeduceBound produce tighter bound, but we don't want to make the assumption that it is a strict one. Perhaps we should also change the API name to remind users of that |
@tqchen Hence, it is implicitly making the assumption that bounds are strict. E.g in the example you posted above:
Based on the bounds for the
so, it directly replaces that condition with either output from first iteration would look like:
I think it is better to tighten the bounds from the However, it doesn't do so for the So far from my experience and From the LoopPartition perspective (the one and only user of the deduce_bound I guess), I haven't seen an example where deduce bound succeeded and produced relaxed bounds except for the particular case of the rounding up for the I think it is more or less safe to assume that bounds are always tight except the case mentioned in this issue. @xqdan also share your thoughts. |
I see, I think we should avoid directly eliminating the conditions but rather keep them. Then the follow-up simplify pass would decide if it is safe to eliminate the conditions. In the meanwhile, we could improve deduce bound to produce tighter bound, but it is good to not making the assumption when using it. So we won't put pressure on deduce bound. Especially in the cases where we might relax the some of the bounds. |
ping @umangyadav would be great if you can followup on this and help to update the loop partition logic. |
To summerize, Problem: Currently for the We discussed two possible solutions through the discussion.
Instead of updating the loop partition, I am more leaning towards tightening deduce_bound for the One main reason, I can think of is that, in some cases, Also, the current loop partition logic is recursive. Hence, if the conditions are still floating around then, it is possible that loop partition keeps partitioning based on those conditions and go into an infinite loop. With the introduction of So far, I don't see any case where I can prepare a PR for the deduce_bound for the LE op. But it can take some time. |
In this particular case, I still recommend to keep the original bounds, and relies on the simplifier(which provide an additional verification). This will allows us to safe-guard the bound deduce, especially for cases that it may produce in-exact bound, not due to the deduction, but due to some iter variables being relaxed that already covers more than what it expects. Note that the integer set analysis system we have right now can produce relaxed bounds, which enlarges its capability for covering set of operations, but also means that additional utils need to work together with the relaxed result. If there is a case when the simplifier cannot simplify the additional condition, we should look into it and fix the simplifier. |
@umangyadav @tqchen @ZihengJiang For this case, fixing the deduce_bound is better IMO, but we can take all actions, since they don't conflict with each other in TVM complier system. deduce_bound should do its best as much as possible, other passes should tolerate bad cases at the same time. |
Hey @umangyadav and @xqdan , actually @tqchen and me believe that these two things are both necessary to do instead of just choosing one of them to fix the problem. |
@ZihengJiang @tqchen I agree with not removing conditions directly in the loop partition now. I've sent a PR for the I'll try to come up with something for the loop partition. |
@umangyadav please also comment on whether we have addressed the issue of adding the guard conditions back(besides improving the bound deducer). |
Hi @umangyadav , are you interested in relaxing the loop partition assumption task ? |
@tqchen We haven't addressed the issue of adding the guard conditions back yet. There is one more thing with the loop partition that can be improved. That is right now If the HalideIR has more than one conditions and if the intersection of their deduced bounds are empty then, loop partition will skip the partition altogether. e.g. something like the following:
The issue is stemming from the following line: I was thinking about the solution to the task of the removing assumption and it reminded me of this issue as well. The solution to task1 (removing assumption) could simply be using simplifier instead of directly eliminating the conditions. The solution to the empty intersection issue (task2) could be that we can consider only one condition at a time for the partition instead of a collection of the conditions. Now Let's say we follow this solution to task2. In that case, we need to somehow tag condition that has already been considered for the partition to avoid considering the same condition repeatedly when simplifier is not able to simplify that. I wanted to address both the issues at the same time, since solving one without another would potentially require design change each time. I am busy with some other work at the time moment. So, @ZihengJiang if you want to take up the task, please go ahead. |
Seems that using floordiv already solve one of the problem, so i will close this thread, let us follow up with new threads for new problems. |
Consider the following example for the
DeduceBound
where we want to find bounds for expression
b < 1 - 2*a
given variables' range,a : [0, 1]
andb: [0, 1]
.Result from running above exmpale is
IntervalSet: [neg_inf, 0]
These bounds from
DeduceBound
are not correct. E.g. considera = 0
then expression becomesb < 1
and that is not always true givenb: [0, 1]
.The error comes from following rounding up stated in the
bound_deducer.cc
:https://github.com/dmlc/tvm/blob/b0ddcff6748bddc69881a2ff4216a830407421c9/src/arithmetic/bound_deducer.cc#L175
Is there a good reason behind keeping this rounding up as it is ?
It is mentioned that, user should respect the relaxed bounds.
As far as I know, only place deduce bound is used is in the
LoopPartition
and relaxed bound gives wrong results.Take the following example for the
LoopPartition
:Output from LoopPartition after the
Simplify
andRemoveNoOp
is as follows:Above output is not correct. With the correct deduce bound the result should be following:
The text was updated successfully, but these errors were encountered: