-
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
[Ansor][AutoTVM v2.0] Phase 1: Add annotation/compute_at/compute_root/compute_inline steps #6073
Conversation
Just noticed that #6077 is also titled as "part 1", shall we make one of them part 2 instead? |
src/auto_scheduler/measure_record.cc
Outdated
@@ -169,6 +206,18 @@ struct Handler<::tvm::Array<::tvm::auto_scheduler::Step>> { | |||
fused_ids.push_back(i); | |||
} | |||
data->push_back(::tvm::auto_scheduler::FuseStep(stage_id, fused_ids)); | |||
} else if (name == "AN") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel the current approach of (de)serializing records is not scalable and hard to be maintained. Specifically, we put all deserialization rules to Read
and all serialization rules to Write
. The key to connect the serialization logic to the corresponding deserialization logic is a two character short name (e.g., AN). It seems to me that it would be better to define a short name and (de)serialization logic in each step. In this case, we can use ps->serialize(writer)
for serialization, and build a step factory to deserialize them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
@merrymercy Currently to add a new transform steps, we have to modify 7 files ... Maybe it would better to move all specific implementation to transform_step.h/cc, and left the other file to just add some interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your points.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm working on this.
Part 1 will have several PRs. "Phase 1" might be a better word to describe this process, but anyways. |
@junrushao1994 My bad, yes I was intended to express a meaning of stage/phase... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jcf94! Overall it looks good. Just some nitpicks.
src/auto_scheduler/measure_record.cc
Outdated
@@ -169,6 +206,18 @@ struct Handler<::tvm::Array<::tvm::auto_scheduler::Step>> { | |||
fused_ids.push_back(i); | |||
} | |||
data->push_back(::tvm::auto_scheduler::FuseStep(stage_id, fused_ids)); | |||
} else if (name == "AN") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your points.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. What's the plan of fixing the step serialization issue? Will that be done in this PR?
A minor typo we didn't catch before (github doesn't allow me to comment on that line because it is not related to this change): in file "loop_state.h", document for class StageNode, "Similar to te::Stage in `include/schedule.h`", the path is incorrect. |
Moved all the implementation to transform_step.h/cc, and updated the order of steps. |
} else { | ||
LOG(FATAL) << "Invalid step: " << step; | ||
} | ||
StepApplyToState(step, this, dag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Looks like we can remove
StepApplyToState
and simply usestep->ApplyToState(this)
? dag
seems unused in both this function andStepApplyToState
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We can remove
StepApplyToState
dag
will be used in other steps such as cache_write and rfactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The step->ApplyToState()
is actually not a virtual function(the return value of different steps may be different), so I add the StepApplyToState
to pack all those step type check to transform_steps.cc
.
if (i != after_ids.size() - 1) { | ||
ss << ", "; | ||
} | ||
void StepApplyToSchedule(const Step& step, Array<te::Stage>* stages, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For 3 functions in this file (StepApplyToState,
StepApplyToSchedule, and
StepApplyToPythonAPI), it should be fine and clearer to directly call
step->XXX(...);in
compute_dag.cc` so that we can avoid unnecessary step node dispatching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emm, step->ApplyToState
, step->ApplyToSchedule
& step->PrintAsPythonAPI
all have problems to be written to virtual functions, we can later try to see if there's any better way to deal with this.
node->stage_id = stage_id; | ||
for (const auto& x : after_ids) { | ||
CHECK(x->IsInstance<IntImmNode>()); | ||
Step StepReadFromRecord(dmlc::JSONReader* reader) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to have a step registration mechanism to establish a step lookup table from record prefix to the step node class, so that we can totally hide step node dispatching from developers. The potential issues in the current implementation is that 1) people may forget to update this function when adding a new step, and 2) there's no mechanism to check duplicated record prefix of two steps.
In addition, I feel this issue is important but I'm not sure if it's proper to address it in this PR. We may need versioning for records.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Yes, we can add a registration mechanism. But I think it can be done in future PRs.
- The current records do have a version field
https://github.com/apache/incubator-tvm/blob/7ac78d96611ab3a069fae9eb5210e433eb240cc5/src/auto_scheduler/measure_record.cc#L314
} else { | ||
LOG(FATAL) << "Invalid step: " << step; | ||
} | ||
StepApplyToState(step, this, dag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We can remove
StepApplyToState
dag
will be used in other steps such as cache_write and rfactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the re-organization looks good to me. We can merge it after fixing the several remaining comments from Cody and me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the contribution!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the issue of 3 dispatching functions will be addressed later, this PR LGTM. Thanks for the efforts!.
Thanks, updated our merge plan to track this issue: https://github.com/merrymercy/Ansor/issues/65 |
…/compute_inline steps (apache#6073) * Add annotation step * Add compute_at/compute_root/compute_inline * Doc update * Update * Update * Update measure record UT * Update * Update * Update * Move state implementation to step * Move measure_record implementation to step * Order update & API update * Update the order of state api * Update
…/compute_inline steps (apache#6073) * Add annotation step * Add compute_at/compute_root/compute_inline * Doc update * Update * Update * Update measure record UT * Update * Update * Update * Move state implementation to step * Move measure_record implementation to step * Order update & API update * Update the order of state api * Update
…/compute_inline steps (apache#6073) * Add annotation step * Add compute_at/compute_root/compute_inline * Doc update * Update * Update * Update measure record UT * Update * Update * Update * Move state implementation to step * Move measure_record implementation to step * Order update & API update * Update the order of state api * Update
…/compute_inline steps (apache#6073) * Add annotation step * Add compute_at/compute_root/compute_inline * Doc update * Update * Update * Update measure record UT * Update * Update * Update * Move state implementation to step * Move measure_record implementation to step * Order update & API update * Update the order of state api * Update
For full upstream plan, see Ansor RFC.
In this PR, we bring annotation/compute_at/compute_root/compute_inline steps for Ansor auto_scheduler.
To record the stage/iterator attach relations, we introduced a new structure AttachMap in State.
cc @tqchen @merrymercy @FrozenGene @minminsun @comaniac