-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Node][Metaschedule] Allow ignoring NDArray raw data in StructuralEqual / Hash #12706
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
|
thanks @masahi . I thin this belongs to a more general topic of canonicalizing the workload keys. While adding such option would indeed resolve this particular case, it would be good to think about if we can have a more generalized approach(for future cases that needs canonicalization, e.g. those that have followup elem-wise patterns which allows some form of reuse) One possible approach is to have a CanonicalizeWorkloadKey which takes a TIR and Canonicalizes that into a different one(e.g. change alloc_const to a the function parameter which contains a buffer). Depends on how fast we can do this, we can choose to introduce the flag. This also helps us to prevent possible future cases that can choose to schedule transform depending on the const value content |
|
@tqchen Thanks, I like the idea of the canonicalized key. Last week I discussed with @zxybazh on the possibility of identifying two subgraphs with the identical anchor op workload (conv2d -> add and conv2d -> add -> add etc) as being equal, to reduce the tuning time like you suggested. I can imagine that, moving away from using the raw Relay / TIR mod as a workload key is a good direction toward that goal. |
df0639e to
8c5ef42
Compare
…13001) When we use `StructuralEqual/Hash`, the actual equality testing / hashing work are deferred to `RemapVarSEqualHandler` and `VarCountingSHashHandler` class respectively, defined in `.cc` files. To customize equality / hash behavior, I want to be able to derive from these classes outside of `structural_equal.cc` or `structural_hash.cc`. This is the first step toward replacing my previous attempt #12706 to allow ignoring NDArray raw data in `StructuralEqual/Hash`. So I propose to expose them as the "default" handler, while still hiding their implementation details. This lets me define a custom hasher that ignores NDArray content simply by: ``` class SHashHandlerIgnoreNDArray : public SHashHandlerDefault { protected: void DispatchSHash(const ObjectRef& object, bool map_free_vars) override { ICHECK(object.defined()); if (auto ndarray = object.as<runtime::NDArray::Container>()) { SHashReducer hash_reduce(this, map_free_vars); NDArrayHash(ndarray, &hash_reduce, false); } else { SHashHandlerDefault::DispatchSHash(object, map_free_vars); } } }; ```
Currently, MS uses `StructuralEqual/Hash` in task extraction / evo search / database. Sometimes, we want to use different hashing and equality testing methods, for example (1) to ignore NDArray (#12706) or (2) to enable anchor-op only tuning (identify `conv2d` and `conv2d -> add` subgraphs as equal). To enable such flexibility, this PR consolidate raw calls to `StructuralEqual/Hash` into one place, which for now is named `ModuleEquality`. Since hashing is also done for equality testing, I think it is appropriate to call the component responsible for hashing / equality test that way. But other suggestions are welcome. Importantly, task extraction and database are now using the same hashing / equal method based on TIR mod, while previously task extraction was using a cache key-ed on relay mod.
|
Superceded by #13091 |
…ng NDArray raw data (#13091) A follow up to #13050, also builds on #13001. This PR enables the functionality in #12706 without changing the existing `StructuralEqual/Hash`. A question for discussion: Should this be the default ModuleEquality used by MS? It has no effect for the `link-params = False` case, and it simplifies the MS tuning API usage for the `link-params = True` case (Hexagon etc).
…e#13050) Currently, MS uses `StructuralEqual/Hash` in task extraction / evo search / database. Sometimes, we want to use different hashing and equality testing methods, for example (1) to ignore NDArray (apache#12706) or (2) to enable anchor-op only tuning (identify `conv2d` and `conv2d -> add` subgraphs as equal). To enable such flexibility, this PR consolidate raw calls to `StructuralEqual/Hash` into one place, which for now is named `ModuleEquality`. Since hashing is also done for equality testing, I think it is appropriate to call the component responsible for hashing / equality test that way. But other suggestions are welcome. Importantly, task extraction and database are now using the same hashing / equal method based on TIR mod, while previously task extraction was using a cache key-ed on relay mod.
…ng NDArray raw data (apache#13091) A follow up to apache#13050, also builds on apache#13001. This PR enables the functionality in apache#12706 without changing the existing `StructuralEqual/Hash`. A question for discussion: Should this be the default ModuleEquality used by MS? It has no effect for the `link-params = False` case, and it simplifies the MS tuning API usage for the `link-params = True` case (Hexagon etc).
…pache#13001) When we use `StructuralEqual/Hash`, the actual equality testing / hashing work are deferred to `RemapVarSEqualHandler` and `VarCountingSHashHandler` class respectively, defined in `.cc` files. To customize equality / hash behavior, I want to be able to derive from these classes outside of `structural_equal.cc` or `structural_hash.cc`. This is the first step toward replacing my previous attempt apache#12706 to allow ignoring NDArray raw data in `StructuralEqual/Hash`. So I propose to expose them as the "default" handler, while still hiding their implementation details. This lets me define a custom hasher that ignores NDArray content simply by: ``` class SHashHandlerIgnoreNDArray : public SHashHandlerDefault { protected: void DispatchSHash(const ObjectRef& object, bool map_free_vars) override { ICHECK(object.defined()); if (auto ndarray = object.as<runtime::NDArray::Container>()) { SHashReducer hash_reduce(this, map_free_vars); NDArrayHash(ndarray, &hash_reduce, false); } else { SHashHandlerDefault::DispatchSHash(object, map_free_vars); } } }; ```
…e#13050) Currently, MS uses `StructuralEqual/Hash` in task extraction / evo search / database. Sometimes, we want to use different hashing and equality testing methods, for example (1) to ignore NDArray (apache#12706) or (2) to enable anchor-op only tuning (identify `conv2d` and `conv2d -> add` subgraphs as equal). To enable such flexibility, this PR consolidate raw calls to `StructuralEqual/Hash` into one place, which for now is named `ModuleEquality`. Since hashing is also done for equality testing, I think it is appropriate to call the component responsible for hashing / equality test that way. But other suggestions are welcome. Importantly, task extraction and database are now using the same hashing / equal method based on TIR mod, while previously task extraction was using a cache key-ed on relay mod.
…ng NDArray raw data (apache#13091) A follow up to apache#13050, also builds on apache#13001. This PR enables the functionality in apache#12706 without changing the existing `StructuralEqual/Hash`. A question for discussion: Should this be the default ModuleEquality used by MS? It has no effect for the `link-params = False` case, and it simplifies the MS tuning API usage for the `link-params = True` case (Hexagon etc).
Motivation: Currently,
StructuralEqual/Hashtake into account NDArray raw data to determine equality / compute hash. This is problematic forlink-params = Truecase, because meta schedule task extraction and database look up will treat the following subgraphs as distinct, even though the only difference is the content of NDArray constants.This PR adds options to
StructuralEqual/Hashto allow ignoring NDArray raw data when comparing / hashing. MS task extraction and database look up are now using these options, since NDArray raw data doesn't matter to them.cc @Hzfengsy @junrushao1994