refactor canonical ordering to also be able to do isAfter checks (#42140)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/42140
Test Plan: Imported from OSS
Reviewed By: SplitInfinity
Differential Revision: D22798378
Pulled By: eellison
fbshipit-source-id: d1a549f43b28fe927729597818a46674c58fe81d