Skip to content

Sample custom guards [Do not land, for answering question] #95586

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

Closed
wants to merge 1 commit into from

Conversation

voznesenskym
Copy link
Collaborator

@voznesenskym voznesenskym commented Feb 27, 2023

Context:
https://dev-discuss.pytorch.org/t/can-backend-compilers-modify-guards-for-torch-dynamo-frame/1074

Invoked with:

def my_backend(gm, args):
    print("Compile!")
    TracingContext.get().guards_context.custom_guards.append(ArbitraryStringGuard("x.tag == 'foo'"))
    return gm
    
x = torch.randn([2, 2])
y = torch.randn([2, 2])

def simple_fn(x, y):
    return x * y    

torch._dynamo.optimize(my_backend)(simple_fn)(x, y)
x.tag = 'bar'
torch._dynamo.optimize(my_backend)(simple_fn)(x, y)
x.tag = 'foo'
torch._dynamo.optimize(my_backend)(simple_fn)(x, y)
torch._dynamo.optimize(my_backend)(simple_fn)(x, y)

Run with TORCHDYNAMO_PRINT_GUARDS=1

To see:

GUARDS ___guarded_code.valid and ___check_tensors(x, y) and x.tag == 'foo' and x.size()[1] == x.size()[0] and x.stride()[0] == x.size()[0] and x.stride()[1] == 1 and x.storage_offset() == 0 and y.size()[0] == x.size()[0] and y.size()[1] == x.size()[0] and y.stride()[0] == x.size()[0] and y.stride()[1] == 1 and y.storage_offset() == 0 and Eq(x.size()[0], 2) and 2 <= x.size()[0]

cc @soumith @yanboliang @penguinwu @anijain2305 @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @desertfire

@pytorch-bot
Copy link

pytorch-bot bot commented Feb 27, 2023

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 7 Failures

As of commit 7689970:

NEW FAILURES - The following jobs have failed:

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

@github-actions
Copy link
Contributor

This PR needs a label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

For more information, see https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@ezyang
Copy link
Contributor

ezyang commented Feb 27, 2023

do you want review

@albanD albanD removed their request for review February 28, 2023 19:37
@github-actions github-actions bot deleted the voz/custom_sample_guards branch August 28, 2024 01:59
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.

2 participants