Skip to content
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

[AutoSchedule] Sparse dense tuning support with custom sketch rule #7313

Merged
merged 36 commits into from
Mar 6, 2021

Conversation

jcf94
Copy link
Contributor

@jcf94 jcf94 commented Jan 20, 2021

No description provided.

@ANSHUMAN87
Copy link
Contributor

Thanks @jcf94 for the PR!
May be once the PR is ready, it would be really great if you can share the stats of sparse_dense Op with and without Ansor.
Really excited to see those.

tutorials/auto_scheduler/tune_sparse_x86.py Outdated Show resolved Hide resolved
tutorials/auto_scheduler/tune_sparse_x86.py Outdated Show resolved Hide resolved
tutorials/auto_scheduler/tune_sparse_x86.py Outdated Show resolved Hide resolved
tutorials/auto_scheduler/tune_sparse_x86.py Outdated Show resolved Hide resolved
tutorials/auto_scheduler/tune_sparse_x86.py Outdated Show resolved Hide resolved
tutorials/auto_scheduler/tune_sparse_x86.py Outdated Show resolved Hide resolved
tutorials/auto_scheduler/tune_sparse_x86.py Outdated Show resolved Hide resolved
tutorials/auto_scheduler/tune_sparse_x86.py Show resolved Hide resolved
tutorials/auto_scheduler/tune_sparse_x86.py Outdated Show resolved Hide resolved
density *= i
density /= (K * N)
density = density.value
sparse_prefix = "%s_%d_%d_%d_%d_%d_%.2f_" % (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could run into the case that two matrices have the same sparse_prefix, but different non-zero structure. Will this cause issues? What if one of the matrices has one nonzero per row and the other has one dense row (while maintaining the same sparsity)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though in my test a schedule seems to have similar performance with different random sparse data, I think that may still be a potential problem. Unfortunately, I have not figured out any better solution.

Copy link
Contributor

@tkonolige tkonolige Jan 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could hash the indptr and indices arrays as these determine the structure. Alternatively you could hash the number of nonzeros per row.

It would be interesting to study if tuning performs the same independent of structure (but for the same sparsity).

python/tvm/auto_scheduler/measure.py Outdated Show resolved Hide resolved
python/tvm/auto_scheduler/measure.py Outdated Show resolved Hide resolved
python/tvm/auto_scheduler/measure.py Outdated Show resolved Hide resolved
@merrymercy merrymercy self-assigned this Feb 5, 2021
Copy link
Member

@merrymercy merrymercy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor style comments

python/tvm/topi/nn/sparse.py Outdated Show resolved Hide resolved
src/auto_scheduler/feature.cc Outdated Show resolved Hide resolved
tutorials/auto_scheduler/tune_sparse_x86.py Outdated Show resolved Hide resolved
tutorials/auto_scheduler/tune_sparse_x86.py Outdated Show resolved Hide resolved
@merrymercy
Copy link
Member

merrymercy commented Mar 3, 2021

According to our offline discussion,

  1. Update the type of SearchTaskNode::task_inputs. Change it from Map<String, runtime::NDArray> to Array<String>, so we only need to store nd arrays in one place. We can query it from the global table in measure.py
  2. Remove SearchTask.AddTaskInput interface to make SearchTask immutable. We do not have the need to dynamically update task inputs, so we can provide all arguments to the constructors.
  3. Make sure we can use the same interface to support the use case where we want to match the special buffers by name

@jcf94
Copy link
Contributor Author

jcf94 commented Mar 3, 2021

According to our offline discussion,

  1. Update the type of SearchTaskNode::task_inputs. Change it from Map<String, runtime::NDArray> to Array<String>, so we only need to store nd arrays in one place. We can query it from the global table in measure.py
  2. Remove SearchTask.AddTaskInput interface to make SearchTask immutable. We do not have the need to dynamically update task inputs, so we can provide all arguments to the constructors.
  3. Make sure we can use the same interface to support the use case where we want to match the special buffers by name

@comaniac @merrymercy Comments all addressed:
1/2: Removed the add_task_input API, and only provide them in constructor. Now, SearchTask only keeps the name of each special buffer.
3: Add a extra case in measure.py:_prepare_input_map to check the placeholder name, as well as a unit test in test_auto_scheduler_measure.py:test_measure_special_inputs_map_by_name.

Copy link
Contributor

@tkonolige tkonolige left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to echo my earlier concerns about special casing sparse inputs instead of having a generic mechanism for detecting special task inputs.

tensor_input_map[arg] = arg.op.name

# Case 1: Check sparse op
sparse_input_map = topi.nn.sparse.try_get_sparse_input(args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I asked this before, but can we have a more general mechanism than checking only for sparse. There are other use cases that require specific input (sorting, scatter).

Copy link
Contributor Author

@jcf94 jcf94 Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I've also had some discussions in our weekly sync while didn't figure out any better solutions.
There're several reasons:

  1. Different ops have different requirements over specific inputs;
  2. While the problems is in a subgraph generated in Relay Integration, the placeholder are all the same, we can not differentiate them from tag, name or any other way, even the order of inputs are not guaranteed.

Current approach is to merge all specific inputs checking to this function, at least they have a same entry here. For the other ops, you have to add their own check functions below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, my colleague is going to add Ansor support for sparse_conv2d. We'll add extra check to this entry first, and see if there's any better way to merge them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we associate the lookup mechanism with @register_workload? It would at least be extensible then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we associate the lookup mechanism with @register_workload? It would at least be extensible then.

Thanks! This is a pretty good idea, I'll have a try.

tests/python/unittest/test_auto_scheduler_search_task.py Outdated Show resolved Hide resolved
@jcf94 jcf94 requested a review from comaniac March 4, 2021 01:26
include/tvm/auto_scheduler/search_task.h Outdated Show resolved Hide resolved
python/tvm/auto_scheduler/measure.py Outdated Show resolved Hide resolved
python/tvm/auto_scheduler/measure.py Outdated Show resolved Hide resolved
python/tvm/auto_scheduler/measure.py Outdated Show resolved Hide resolved
python/tvm/auto_scheduler/search_task.py Outdated Show resolved Hide resolved
python/tvm/auto_scheduler/search_task.py Outdated Show resolved Hide resolved
python/tvm/auto_scheduler/search_task.py Outdated Show resolved Hide resolved
python/tvm/auto_scheduler/measure.py Outdated Show resolved Hide resolved
python/tvm/auto_scheduler/measure.py Outdated Show resolved Hide resolved
python/tvm/topi/nn/sparse.py Outdated Show resolved Hide resolved
@jcf94
Copy link
Contributor Author

jcf94 commented Mar 5, 2021

@merrymercy @comaniac @tkonolige Thanks! Comments has all been addressed.
Additionally, add a @auto_scheduler.register_task_input_check_func, now we can add extra input check functions more easily.

@merrymercy merrymercy dismissed comaniac’s stale review March 6, 2021 04:53

comments are addressed

@merrymercy merrymercy merged commit 0b4f669 into apache:main Mar 6, 2021
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request May 6, 2021
…pache#7313)

* Add sparse dense tuning tutorial

* Add sparse input fusion

* Update the dag to support output fusion

* Update

* Add task input to search_task

* Update

* Add search_inputs to measure

* Lint fix

* Lint fix

* Update

* Update

* Update

* Update

* Add file save load support

* Update

* Update

* Update

* Remove add_task_inputs API

* Update

* Update

* Update

* Lint fix

* Lint fix

* Lint fix

* Lint fix

* Update

* Add example ci_log

* Update

* retrigger ci

* Update

* Update

* Update

* Lint fix

* Lint fix

* Lint fix
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request May 11, 2021
…pache#7313)

* Add sparse dense tuning tutorial

* Add sparse input fusion

* Update the dag to support output fusion

* Update

* Add task input to search_task

* Update

* Add search_inputs to measure

* Lint fix

* Lint fix

* Update

* Update

* Update

* Update

* Add file save load support

* Update

* Update

* Update

* Remove add_task_inputs API

* Update

* Update

* Update

* Lint fix

* Lint fix

* Lint fix

* Lint fix

* Update

* Add example ci_log

* Update

* retrigger ci

* Update

* Update

* Update

* Lint fix

* Lint fix

* Lint fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants