Skip to content

[dynamo] Make global state guards and torch function stack guards droppable.#167674

Closed
zhxchen17 wants to merge 1 commit intomainfrom
zhxchen17/dynamo/unsafe_drop_all_guards
Closed

[dynamo] Make global state guards and torch function stack guards droppable.#167674
zhxchen17 wants to merge 1 commit intomainfrom
zhxchen17/dynamo/unsafe_drop_all_guards

Conversation

@zhxchen17
Copy link
Contributor

@zhxchen17 zhxchen17 commented Nov 12, 2025

Summary:
Prior to this PR we will always build global and torch funciton guards in all cases.

In this PR we did 2 changes to dynamo guards:

  1. Created a new guard called "GLOBAL_STATE" which corresponds to the global state guard and can be filtered out using guard_filter_fn
  2. Repurpose the existing "TORCH_FUNCTION_STATE" guard for checking torch function mode stack.

Also added a new helper torch.compiler.skip_all_guards_unsafe which can be useful for use cases like vllm

Test Plan:
CI

Fixes #ISSUE_NUMBER

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames @Lucaskabela @mlazos

@pytorch-bot
Copy link

pytorch-bot bot commented Nov 12, 2025

🔗 Helpful Links

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

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

⏳ 1 Pending, 4 Unrelated Failures

As of commit ec46563 with merge base 4de24bc (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

@zhxchen17 zhxchen17 force-pushed the zhxchen17/dynamo/unsafe_drop_all_guards branch from ee7e48e to b023bb6 Compare November 13, 2025 16:01
…ppable.

Summary:
Prior to this PR we will always build global and torch funciton guards in all cases.

In this PR we did 2 changes to dynamo guards:
1. Created a new guard called "GLOBAL_STATE" which corresponds to the global state guard and can be filtered out using guard_filter_fn
2. Repurpose the existing "TORCH_FUNCTION_STATE" guard for checking torch function mode stack.

Also added a new helper `torch.compiler.skip_all_guards_unsafe` which can be useful for use cases like vllm

Test Plan:
CI
@zhxchen17 zhxchen17 force-pushed the zhxchen17/dynamo/unsafe_drop_all_guards branch from b023bb6 to ec46563 Compare November 13, 2025 17:55
@zhxchen17 zhxchen17 marked this pull request as ready for review November 13, 2025 19:00
@zhxchen17 zhxchen17 requested a review from laithsakka November 13, 2025 19:00
return [not entry.is_global for entry in guard_entries]


def skip_all_guards_unsafe(guard_entries):
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 good.

Is it also possible to add a config option somewhere to skip building the guards itself? If user does not want guards, we can just short-circuit sooner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sounds a good item to do. Not sure about the amount of changed code yet if we skip builder entirely. Can take a look further.

@zhxchen17
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 14, 2025
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

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

jsuarez5341 pushed a commit to PufferAI/pytorch that referenced this pull request Nov 15, 2025
…ppable. (pytorch#167674)

Summary:
Prior to this PR we will always build global and torch funciton guards in all cases.

In this PR we did 2 changes to dynamo guards:
1. Created a new guard called "GLOBAL_STATE" which corresponds to the global state guard and can be filtered out using guard_filter_fn
2. Repurpose the existing "TORCH_FUNCTION_STATE" guard for checking torch function mode stack.

Also added a new helper `torch.compiler.skip_all_guards_unsafe` which can be useful for use cases like vllm

Test Plan:
CI

Fixes #ISSUE_NUMBER

Pull Request resolved: pytorch#167674
Approved by: https://github.com/anijain2305
Silv3S pushed a commit to Silv3S/pytorch that referenced this pull request Nov 18, 2025
…ppable. (pytorch#167674)

Summary:
Prior to this PR we will always build global and torch funciton guards in all cases.

In this PR we did 2 changes to dynamo guards:
1. Created a new guard called "GLOBAL_STATE" which corresponds to the global state guard and can be filtered out using guard_filter_fn
2. Repurpose the existing "TORCH_FUNCTION_STATE" guard for checking torch function mode stack.

Also added a new helper `torch.compiler.skip_all_guards_unsafe` which can be useful for use cases like vllm

Test Plan:
CI

Fixes #ISSUE_NUMBER

Pull Request resolved: pytorch#167674
Approved by: https://github.com/anijain2305
@github-actions github-actions bot deleted the zhxchen17/dynamo/unsafe_drop_all_guards branch December 15, 2025 02:20
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.

3 participants