Skip to content

Can magpy support graph break? #48

@hanwen-sun

Description

@hanwen-sun

Hello,I was wondering if MagPy supports graph breaking. After reviewing the code, I noticed that each frame can have multiple cached_graphs. Additionally, in the dynamic control flow section of the paper, it is mentioned that "MAGPY will cut the user program before the dynamic jump and run this jump eagerly."
However, when I tested MagPy with a simple example involving a print statement and a tensor condition, Dynamo breaks the graph and compiles multiple graphs, but MagPy raises an error. Here is the test case:

import torch
from frontend.compile import compile

def builtin_function(x):
    if x.sum() > 10:
        x = x * 2
    else:
        x = x / 2
    
    return x

x = torch.randn(1024)
compiled = compile(builtin_function)
y = compiled(x)

And another example:

class Example(torch.nn.Module):
    def __init__(self):
        super(Example, self).__init__()
        self.conv = torch.nn.Conv2d(3, 3, 3)
        self.relu = torch.nn.ReLU()

    def forward(self, x):
        x = self.conv(x)
        print(x)
        x = self.relu(x)
        return x

Are there any examples where MagPy performs graph breaking and compiles multiple graphs, caching them? Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions