Skip to content

[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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

[tests] feat: add AoT compilation tests #12203

wants to merge 3 commits into from

Conversation

sayakpaul
Copy link
Member

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".

@sayakpaul sayakpaul requested review from DN6 and cbensimon August 21, 2025 04:33

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)

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!

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)

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

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.

@cbensimon
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

@sayakpaul
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.

@sayakpaul sayakpaul requested a review from angelayi August 21, 2025 13:49
@cbensimon
Copy link
Contributor

cbensimon commented Aug 22, 2025

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)

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

Successfully merging this pull request may close these issues.

3 participants