-
Notifications
You must be signed in to change notification settings - Fork 683
Arm backend: Add pass order validation to ArmPassManager #14148
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/14148
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New Failures, 2 Unrelated FailuresAs of commit 243d006 with merge base 5fd66ee ( NEW FAILURES - The following jobs have failed:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
@pytorchbot label ciflow/trunk |
@pytorchbot label "partner: arm" |
This PR needs a
|
132f407
to
b9a0d81
Compare
Returns the list of passes that must be run after this pass, sorted by name. | ||
""" | ||
if hasattr(pass_, "_passes_required_after"): | ||
return sorted([ArmPass.get_name(p) for p in pass_._passes_required_after]) |
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.
One issue I can see with this approach is transitive dependency and running into weird errors.
At a high level, do we see many cases where we run same pass multiple times in certain order for a given backend, or do something different, in terms of pass ordering, based on some flag or a model architecture?
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 not fully understanding the case of transitive dependencies. With this implementation, if we got the following scenario:
PassA:
_passes_required_after = {PassB}
PassB:
_passes_required_after = {PassC}
PassC:
_passes_required_after = set()
Then PassA
will transitively depend on PassC
.
Then if create a pipeline where we remove PassB
like this:
[
PassA,
PassC,
]
Then we will get the following error:
The following constraints for passes are not met:
PassB must run after PassA
Is that not an reasonable way to handle it? I cannot think of a case where a missing transitive dependency will slip through here and not get caught by validate_constraints_mandatory
.
Then regarding your second point: We have a long-term plan to change the passes such that they will always be added in the same order, but let themselves check whether they should run or not. This means that the order will always remain the same no matter which state/hardware profile we are in. Does that answer your question or maybe I'm not fully following?
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.
Is that not an reasonable way to handle it?
Yeah I guess. Thanks. I was also thinking like,
PassA --(needs)--> Pass B
PassB --(needs)--> Pass C
PassC --(needs)--> Pass A
More broadly,
let themselves check whether they should run or not
I am failing to see the gain from this added complexity over a list[Pass]
for a given backend. Mainly because this is not a user facing surface.
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.
If you are saying we don't have to maintain "per backend + config list of passe" perhaps that is a good enough reason to embrace this complexity.. But I doubt if we can get rid of backend "specialized" logic from the PassManager but happy to be proven wrong :)
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 @digantdesai for the thorough review and feedback!
Regarding the cycles, yes, this implementation would not be able to handle that. But we also want to avoid those kind of loops, so having circular dependencies such as that is something we want to avoid. I cannot say it's 100% future proof but it's unlikely that we would ever need cyclic dependencies I'm thinking.
Regarding the added complexity, perhaps it adds a bit yes; the idea is to uphold intended ordering of the passes in cases where a developer wants to change the ordering. It's not obvious what should come before/after what when there's so many of them. One could say that the unit tests should protect against improper reordering, but this feature gives us quicker and clearer feedback in those cases.
I see your argument about special cases might work against this design. In the worst case we would have to revisit this feature and try to extend/change it somehow. But we do hope to eliminate special cases and always list the passes in the same order at least.
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.
_passes_required_after
being empty for almost all existing passes implies that a simple (ordered) list is sufficient :)
I don't want to block you here, and since this is inside Arm dir, I will let you make the call. Thanks for the discussion.
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! I see your point, but the actual dependencies are added in a later patch that is on its way.
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.
stamping to unblock from merging if/when ready. Thanks @martinlsm
Introduce a mechanism to enforce required ordering of passes in ArmPassManager. Each ArmPass must now declare which passes are required to run after it, ensuring ordering constraints are always upheld. This prevents accidental breakage when modifying pass ordering in the manager. Ordering constraints are verified by the new method ArmPass.validate_constraints_mandatory. We considered reusing torch.fx.passes.infra.pass_manager.PassManager.validate_constraints, but that utility only checks pairwise ordering and cannot enforce that a pass is actually run, which did not meet our needs. This patch only implements the mechanism and tests for it. Defining the actual pass orderings are done in a later patch. Change-Id: I6f822ec4192b0c8dd19b70d85905adcd08ca502f Signed-off-by: Adrian Lundell <adrian.lundell@arm.com> Co-authored-by: Martin Lindström <martin.lindstroem@arm.com>
DecomposeLinearVectorNormPass is listed in both the transform_for_annotation_pipeline and _tosa_INT_pipeline stages. The latter is redundant because torch.linalg.vector_norm can only run with floating point inputs, i.e., we should always be in a quantized setting when we enter _tosa_INT_pipeline if the operator is present and _transform_for_annotation_pipeline will always run; therefore, remove DecomposeLinearVectorNormPass from _tosa_INT_pipeline. Signed-off-by: Martin Lindström <Martin.Lindstroem@arm.com> Change-Id: I647687b51298bbb98087914fbbee053436ffb79f
b9a0d81
to
243d006
Compare
Test fails seems unrelated |
Introduce a mechanism to enforce required ordering of passes in ArmPassManager. Each ArmPass must now declare which passes are required to run after it, ensuring ordering constraints are always upheld. This prevents accidental breakage when modifying pass ordering in the manager. Ordering constraints are verified by the new method ArmPass.validate_constraints_mandatory. We considered reusing torch.fx.passes.infra.pass_manager.PassManager.validate_constraints, but that utility only checks pairwise ordering and cannot enforce that a pass is actually run, which did not meet our needs. This patch only implements the mechanism and tests for it. Defining the actual pass orderings are done in a later patch. ### Test plan The change comes with added unit tests in backends/arm/test/misc/test_pass_required_order.py Signed-off-by: Adrian Lundell <adrian.lundell@arm.com> Signed-off-by: Martin Lindström <Martin.Lindstroem@arm.com> Co-authored-by: Adrian Lundell <adrian.lundell@arm.com> Co-authored-by: Martin Lindström <martin.lindstroem@arm.com>
Introduce a mechanism to enforce required ordering of passes in ArmPassManager. Each ArmPass must now declare which passes are required to run after it, ensuring ordering constraints are always upheld.
This prevents accidental breakage when modifying pass ordering in the manager.
Ordering constraints are verified by the new method ArmPass.validate_constraints_mandatory. We considered reusing torch.fx.passes.infra.pass_manager.PassManager.validate_constraints, but that utility only checks pairwise ordering and cannot enforce that a pass is actually run, which did not meet our needs.
This patch only implements the mechanism and tests for it. Defining the actual pass orderings are done in a later patch.
Test plan
The change comes with added unit tests in backends/arm/test/misc/test_pass_required_order.py
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218