KEMBAR78
Aoti minifier flatten by yushangdi · Pull Request #141156 · pytorch/pytorch · GitHub
Skip to content

Conversation

@yushangdi
Copy link
Contributor

@yushangdi yushangdi commented Nov 20, 2024

Flatten the inputs to minifier so AOTI Minifier can handle unflattened inputs and kwargs.

  • flatten the inputs in minifier
  • changed the "load_and_run" part of the minifier verification to run on the flattened inputs.
  • refactored code to keep torch._inductor.__init__.py clean
  • update doc

python test/inductor/test_minifier.py

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang @aakhundov

@pytorch-bot
Copy link

pytorch-bot bot commented Nov 20, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/141156

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 1751740 with merge base 16ea0dd (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@yushangdi yushangdi force-pushed the aoti_minifier_flatten_2 branch 2 times, most recently from d2a7339 to aaebc35 Compare November 25, 2024 19:16
@yushangdi yushangdi added the topic: not user facing topic category label Nov 25, 2024
@yushangdi yushangdi force-pushed the aoti_minifier_flatten_2 branch 2 times, most recently from 137b8c1 to 6a4d3be Compare November 25, 2024 22:06
@yushangdi yushangdi changed the title Aoti minifier flatten 2 Aoti minifier flatten Nov 25, 2024
@yushangdi yushangdi marked this pull request as ready for review November 25, 2024 22:29
@yushangdi yushangdi requested a review from desertfire November 25, 2024 22:29
warn_and_skip(node.get_device())


def _flatten_inputs(
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand this is moved from _inductor/init.py, but I feel flattening inputs should be a functionality provided by Export. @angelayi , does this already exist in Export?

Copy link
Contributor Author

@yushangdi yushangdi Dec 3, 2024

Choose a reason for hiding this comment

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

@desertfire (Angela pls correct me if I'm wrong) My understanding is that export does flatten the inputs, but that's the inputs for the "flattened graph" (exported_program.graph), but this graph might be different from the input graph module to AOTI (exported_program.module()) .

The main difference is that, exported_program.module() may contain submodules, but exported_program.graph is fully flatten.

So the two flattening are a little different. Here in _flatten_inputs, we are only flattening the inputs, but not other parts of the graph (e.g. the submodules).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah this code is pretty similar to what we have here, but I'm not sure if it's easy to refactor things to reuse this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@desertfire The _flatten_inputs function here does 3 things:

  1. update the gm's codegen to take in the flattened inputs
  2. get the flattened inputs (this is similar to the code that Angela linked above, but that's basically 2 lines)
  3. update the inductor_config's serialized_in_spec and serialized_out_spec fields

Maybe I could rename this function to e.g. _update_gm_input_spec_and_flatten to be more clear that this function does more than just getting the flattened inputs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or you rename to something more generic but with aoti in it.

Copy link
Contributor Author

@yushangdi yushangdi Dec 5, 2024

Choose a reason for hiding this comment

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

Or you rename to something more generic but with aoti in it.

sure, renamed to _aoti_flatten_inputs now.

@yushangdi yushangdi requested a review from desertfire December 4, 2024 21:55

options = (
{
"aot_inductor.serialized_in_spec": serialized_in_spec,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a legacy issue, but we really shouldn't use inductor config for passing these. It will be nice to have some refactoring someday.

warn_and_skip(node.get_device())


def _flatten_inputs(
Copy link
Contributor

Choose a reason for hiding this comment

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

Or you rename to something more generic but with aoti in it.

@yushangdi yushangdi force-pushed the aoti_minifier_flatten_2 branch 4 times, most recently from 2d9c61a to b2f1579 Compare December 5, 2024 23:14
@yushangdi yushangdi force-pushed the aoti_minifier_flatten_2 branch from b2f1579 to 1751740 Compare December 5, 2024 23:16
@yushangdi
Copy link
Contributor Author

@pytorchbot merge -i

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Dec 6, 2024
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: pull / linux-focal-py3_9-clang9-xla / test (xla, 1, 1, lf.linux.12xlarge)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

AmdSampsa pushed a commit to AmdSampsa/pytorch that referenced this pull request Dec 9, 2024
Flatten the inputs to minifier so AOTI Minifier can handle unflattened inputs and kwargs.

- flatten the inputs in minifier
- changed the "load_and_run" part of the minifier verification to run on the flattened inputs.
- refactored code to keep `torch._inductor.__init__.py` clean
- update doc

`python test/inductor/test_minifier.py`

Pull Request resolved: pytorch#141156
Approved by: https://github.com/desertfire
@github-actions github-actions bot deleted the aoti_minifier_flatten_2 branch January 6, 2025 02:08
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.

4 participants