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

[Arith] Inequalities solver #5618

Merged
merged 39 commits into from
Jul 6, 2020
Merged

[Arith] Inequalities solver #5618

merged 39 commits into from
Jul 6, 2020

Conversation

yzhliu
Copy link
Member

@yzhliu yzhliu commented May 18, 2020

This is the LinearInequalitySolver mentioned in https://discuss.tvm.ai/t/rfc-bring-in-tensor-expression-autodiff

src/arith/util.cc Outdated Show resolved Hide resolved
src/arith/util.cc Outdated Show resolved Hide resolved
src/arith/util.cc Outdated Show resolved Hide resolved
@yzhliu yzhliu marked this pull request as ready for review June 7, 2020 07:49
@yzhliu
Copy link
Member Author

yzhliu commented Jun 7, 2020

@yzhliu
Copy link
Member Author

yzhliu commented Jun 12, 2020

Also cc @xqdan @junrushao1994 if you have time review.

include/tvm/arith/int_solver.h Outdated Show resolved Hide resolved
include/tvm/arith/int_solver.h Show resolved Hide resolved
python/tvm/arith/int_solver.py Show resolved Hide resolved
python/tvm/arith/int_solver.py Show resolved Hide resolved
python/tvm/arith/int_solver.py Outdated Show resolved Hide resolved
src/arith/solve_linear_inequality.cc Show resolved Hide resolved
src/arith/solve_linear_inequality.cc Outdated Show resolved Hide resolved
src/arith/solve_linear_inequality.cc Outdated Show resolved Hide resolved
src/arith/solve_linear_inequality.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@MarisaKirisame MarisaKirisame left a comment

Choose a reason for hiding this comment

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

I took a look at the code. However i suck at numeric so I dont know what it is doing. I left some small word smithing.

include/tvm/arith/int_solver.h Outdated Show resolved Hide resolved
src/arith/int_constraints.cc Outdated Show resolved Hide resolved
@tqchen tqchen added the status: need update need update based on feedbacks label Jun 18, 2020

rels = constraints_trans.dst.relations
if len(rels) == 1 and tvm.ir.structural_equal(rels[0], False):
# not solvable, skip
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be checked here that the original constraints are also unsolvable.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes.. but how can I detect the contradiction in the original constraints without running the solver?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can check that the original constraints are false for all values of the variables. I would remove this check completely, I think _check_forward should do what is needed automatically or with some minor changes.

Copy link
Contributor

@ANSHUMAN87 ANSHUMAN87 left a comment

Choose a reason for hiding this comment

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

@yzhliu : Thanks for the PR! Great work 👍

Please find some high level comments and some queries. Thanks!

src/arith/analyzer.cc Outdated Show resolved Hide resolved
include/tvm/arith/analyzer.h Outdated Show resolved Hide resolved
* \param r The range
* \return constructed bounds.
*/
static IntGrpBounds range(const Range& r);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe range --> CreateIntGrpBounds (Or something like that, as we are creating Bounds from Range)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! I see now. I am also okay if it is general convention:)
@tqchen : Do you have any thoughts on the comment ?

include/tvm/arith/int_solver.h Show resolved Hide resolved
include/tvm/arith/int_solver.h Show resolved Hide resolved
python/tvm/testing.py Outdated Show resolved Hide resolved
python/tvm/testing.py Show resolved Hide resolved
@yzhliu
Copy link
Member Author

yzhliu commented Jun 26, 2020

@sergei-grechanik @ANSHUMAN87 @tqchen @MarisaKirisame Please take a look again.

src/arith/solve_linear_inequality.cc Outdated Show resolved Hide resolved
// Note that we use the 0-th expression because they are ordered by complexity,
// so it must be the simplest one.
Range best_range(bnd->equal[0], analyzer.Simplify(bnd->equal[0] + 1, 3));
res_ranges.Set(var, best_range);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: res_ranges.Set & vranges.Set can be taken to common place below if...else... block.

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 the else branch, they are not set unless best_range is defined.

Copy link
Member

@tqchen tqchen left a comment

Choose a reason for hiding this comment

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

some minor comments about naming

* coef * var <= upper
* \sa IntGrpBounds
*/
class IntGrpBoundsNode : public Object {
Copy link
Member

Choose a reason for hiding this comment

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

IntGroupBounds

* \param r The range
* \return constructed bounds.
*/
static IntGrpBounds range(const Range& r);
Copy link
Member

Choose a reason for hiding this comment

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

How about FromRange


@staticmethod
def make_by_range(rng):
"""Construct a IntGroupedBounds by Range.
Copy link
Member

Choose a reason for hiding this comment

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

from_range

@yzhliu
Copy link
Member Author

yzhliu commented Jul 2, 2020

@tqchen @ANSHUMAN87 Please take a look again.

Copy link
Contributor

@ANSHUMAN87 ANSHUMAN87 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @yzhliu 👍

@yzhliu
Copy link
Member Author

yzhliu commented Jul 6, 2020

@tqchen kindly ping

@tqchen tqchen merged commit 151f3f5 into apache:master Jul 6, 2020
@tqchen
Copy link
Member

tqchen commented Jul 6, 2020

@tqchen tqchen added status: accepted and removed status: need review status: need update need update based on feedbacks labels Jul 6, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Jul 14, 2020
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Jul 14, 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.

5 participants