[AUTO_SCHEDULER] Supported CSE (variable definitions) in feature extraction - #10686
Conversation
…action Add supported for LetStmts in feature extraction. A stack of variable definitions is maintained and added to the arithmetic analyzer at the appropriate points. The buffer access analysis now creates a new arithmetic analysis context per set of loops to avoid redefining variables which is unsafe in the presence of let statements.
b82e065 to
189e1bd
Compare
| return 1; | ||
| } | ||
| // Return the maximum extent of a for loop | ||
| int64_t GetLoopExtent(const ForNode* node, const Analyzer& ana) { |
There was a problem hiding this comment.
NOTE: this is a change of behavior that might worth checking, const_int bound may return INT_MAX for cases that it cannot analyze
There was a problem hiding this comment.
I've added a check that return 1 if const_int_bound returns inf (it way of saying it cannot analyze).
There was a problem hiding this comment.
This LGTM. although I do not expect regression in this case, would be good to run some tests to confirm, not a blocker to merge though.
|
|
||
|
|
||
| def test_primfunc(): | ||
| features = auto_scheduler.feature.named_features_from_primfunc(tir_matmul) |
There was a problem hiding this comment.
Would be good to keep the original test because that is the original intended usage, since the original function was designed for auto-scheduler with limited passes (to enable fast feature extraction). The test should cover the original intended use.
The additional support enables possible explorations for new use cases. Consider add another testcase test_primfunc_lowered_with_let to get the fully lowered version.
It would be helpful to construct a simplified TVM script version of the lowered version to see exactly where let bound may results in a change of values.
There was a problem hiding this comment.
I wrote the original test and its intended usage was for analysis after lowering.
I specifically did not want to construct a test from the explicitly lowered tvmscript so future large changes like CSE would cause the test to fail.
There was a problem hiding this comment.
I see, explicitly constructed script would help to clarify the regression that the change intend to cover.
To rephrase what you are saying (correct if that was not what you meant):
- In the future, if CSE changes its behavior to generate other cases, the feature extractor from an explicit tvm-script may not capture that changes (as new CSE will generate new IRs that may have other properties) -- the test won't fail but I guess you mean it fails to capture the possible problem in CSE changes.
This is indeed a fair pt. Although running things through is a bit like integration tests(that tests the combined effect of CSE, lowering and feature extraction).
The case of tvmscript inputs is closer to unit-test to test the intended behavior of the specific pass. Such unit-tests usually have a clear intend, and easier to debug when it triggers a regression. Although its coverage won't move as the integration tests do.
I still would suggest keep test_primfunc given the original intended behavior of the pass was limited. It does not hurt to have a case to cover the original intended case.
Adding another test_primfunc_lowered_with_let would give quite clear context, and provide some safety net when we start to explore the ability of using the extractor with CSE passes.
As for the unit-test case, it is merely a recommendation(as per above discussion on unit-test and integration tests)
There was a problem hiding this comment.
To rephrase what you are saying (correct if that was not what you meant):
- In the future, if CSE changes its behavior to generate other cases, the feature extractor from an explicit tvm-script may not capture that changes (as new CSE will generate new IRs that may have other properties) -- the test won't fail but I guess you mean it fails to capture the possible problem in CSE changes.
What I mean is that I want a test that ensures that changes to the lowering pipeline do not break feature extraction. CSE is an example of a test that broke it. I agree that it could be viewed as an integration test and I can move the test if you'd like.
There was a problem hiding this comment.
Great, seems our interpretations aligns with each other. I agree that having a test that thread through lowered is useful if we bring in future usecases that applies feature extractor on lowered code.
To summarize the recommendation:
- Keep the original
test_primfunc(perhaps rename totest_prim_func_before_loweringto clairfy the intend)- This was the original intended behavior of the extractor and auto-scheduler only relied on this behavior.
- Add a new test
test_primfunc_lowered_with_let- I understand that there is an exploration effort to try out this and possibly followup features that depends on this. Although auto-scheduler do not yet rely on this behavior, so it would be good to keep it separate.
- Like you said it is more like an integration tests(but i agree in this case it is OK to keep it here)
- (Optional): add a unit-test testcase with explicitly constructed tvmscript that covers the
lowered_let. The main rationale is that the intend of the unit-test case would be clear and it becomes easier to debug in facing regression, but I feel in this case it can be optional.
| } | ||
| // Return the maximum extent of a for loop | ||
| int64_t GetLoopExtent(const ForNode* node, const Analyzer& ana) { | ||
| return ana.const_int_bound(node->extent)->max_value; |
There was a problem hiding this comment.
The reason that we didn't use const-int-bound in feature extraction is that it becomes less helpful when encountering TIR of symbolic shapes.
There was a problem hiding this comment.
auto scheduler doesn't work with symbolic shapes, so why would this be a problem? Seems like this is strictly an improvement over what we currently have.
|
|
||
|
|
||
| def test_primfunc(): | ||
| features = auto_scheduler.feature.named_features_from_primfunc(tir_matmul) |
|
@junrushao1994 Could you review again. |
|
CC @tqchen for a second look |
…ction (apache#10686) Add supported for LetStmts in feature extraction. A stack of variable definitions is maintained and added to the arithmetic analyzer at the appropriate points. The buffer access analysis now creates a new arithmetic analysis context per set of loops to avoid redefining variables which is unsafe in the presence of let statements.
Add supported for LetStmts in feature extraction. A stack of variable definitions is maintained and added to the arithmetic analyzer at the appropriate points. The buffer access analysis now creates a new arithmetic analysis context per set of loops to avoid redefining variables which is unsafe in the presence of let statements.
@tqchen @junrushao1994 @merrymercy