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

Optimize dynamo dynamic shape caching #7726

Merged
merged 2 commits into from
Jul 24, 2024

Conversation

JackCaoG
Copy link
Collaborator

@JackCaoG JackCaoG commented Jul 23, 2024

When we do

compiled_fn = torch.compile(fn, backend="openxla", dynamic=True)
# input1 and input2 are of different types
compiled_fn(input1)
compiled_fn(input2)

Dynamo will only trace the python bytecode once, but will pass input with different shapes to the same optimized_mod . The way we support the dynamic shape is to maintain a mapping between different input shapes to different xla graphs.

Currently there is an ineffiency that when we do

# when `torch.compile`d function being called
extract_internal -> extract_graph_helper -> optimized_mod

we return the optimized_mod to pytorch to replace the existing function. However in this process we did not populate the map that maps input shapes to the graph hash. We do that when we

optimized_mod (found that map is empty) -> extract_graph_helper

This is unnecessary, we should populate the mapping when we first time calling extract_graph_helper

@JackCaoG JackCaoG marked this pull request as ready for review July 24, 2024 03:00
@JackCaoG JackCaoG requested review from alanwaketan and lsy323 July 24, 2024 03:06
Copy link
Collaborator

@alanwaketan alanwaketan left a comment

Choose a reason for hiding this comment

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

LGTM.

@JackCaoG JackCaoG merged commit 33f69ad into master Jul 24, 2024
23 checks passed
yitongh pushed a commit to AlibabaPAI/xla that referenced this pull request Oct 11, 2024
yitongh pushed a commit to AlibabaPAI/xla that referenced this pull request Dec 11, 2024
yitongh pushed a commit to AlibabaPAI/xla that referenced this pull request Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants