Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[tests] feat: add AoT compilation tests #12203

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

Merged
sayakpaul merged 8 commits into main from export-tests
Sep 3, 2025
Merged

[tests] feat: add AoT compilation tests #12203

sayakpaul merged 8 commits into main from export-tests
Sep 3, 2025

Conversation

Copy link
Member

@sayakpaul sayakpaul commented Aug 21, 2025

What does this PR do?

AoT compilation is exciting because it helps cut the framework overhead. It also helps realize similar benefits as JiT compilation for environments where JiT might not be feasible (ZeroGPU Spaces, for example). For example, with AoT-compilation, we were able to obtain 1.7x speedups in latency on a ZeroGPU Space. Wouldn't have been feasible, otherwise.

To run, RUN_SLOW=1 RUN_COMPILE=yes pytest tests/models/ -k "aot".


with tempfile.TemporaryDirectory() as tmpdir:
package_path = os.path.join(tmpdir, f"{self.model_class.__name__}.pt2")
_ = torch._inductor.aoti_compile_and_package(exported_model, package_path=package_path)
Copy link

Choose a reason for hiding this comment

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

Not passing in a path should also automatically give you a path in the tmp dir!

sayakpaul reacted with thumbs up emoji
Copy link

@angelayi angelayi left a comment

Choose a reason for hiding this comment

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

Thanks for adding a test!


with torch.no_grad():
_ = model(**inputs_dict)
_ = model(**inputs_dict)
Copy link

Choose a reason for hiding this comment

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

Is there a particular reason why you're running it twice?

Copy link
Member Author

@sayakpaul sayakpaul Aug 21, 2025

Choose a reason for hiding this comment

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

To emulate the real scenario as the model is typically invoked more than once during the actual generation process.

angelayi reacted with thumbs up emoji
Copy link
Contributor

Very nice! Ideally we should pass multiple inputs to the exported (and/or compiled) model in order to test proper dynamism (for instance in the case of QwenImageTransformer2DModel, export test might pass but we'll miss the fact that it will only work at a given image shape). Of course this probably means quite a (too) big refactor of prepare_init_args_and_inputs_for_common

Copy link
Member Author

Very nice! Ideally we should pass multiple inputs to the exported (and/or compiled) model in order to test proper dynamism (for instance in the case of QwenImageTransformer2DModel, export test might pass but we'll miss the fact that it will only work at a given image shape). Of course this probably means quite a (too) big refactor of prepare_init_args_and_inputs_for_common

We already have this kind of test:

def test_compile_on_different_shapes(self):

I think it's fine for now to just test for static shapes. If dynamic AoT becomes more popular, we can revisit it.

Copy link
Contributor

cbensimon commented Aug 22, 2025
edited
Loading

We already have this kind of test:

Very nice! I think that prepare_dummy_inputs could actually be useful outside of tests too (for torch.export.export input examples)

sayakpaul reacted with heart emoji

@sayakpaul sayakpaul merged commit ffc8c0c into main Sep 3, 2025
27 of 28 checks passed
@sayakpaul sayakpaul deleted the export-tests branch September 3, 2025 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@cbensimon cbensimon cbensimon approved these changes

@DN6 DN6 Awaiting requested review from DN6

+1 more reviewer

@angelayi angelayi angelayi approved these changes

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /