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

[BUG] Customize get Python AST starting_line_no is a null ptr when isinstance(fn, str) #273

Open
jiahanxie353 opened this issue Dec 4, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jiahanxie353
Copy link

Describe the bug
If we take the if branch when getting the Python AST in customize, then starting_line_no is a null pointer in this line, causing:

UnboundLocalError: cannot access local variable 'starting_line_no' where it is not associated with a value

To Reproduce

import torch
import torch.nn as nn
import torch.nn.functional as F

import allo

torch.set_printoptions(precision=2)

input_size = 6
hidden_size = 5
output_size = 2

mean = 0
std = 5

lower_bound = -5
upper_bound = 5

torch.manual_seed(42)

random_tensor = torch.randn(hidden_size, input_size) * std + mean

clipped_tensor = torch.clamp(random_tensor, min=lower_bound, max=upper_bound)


class Model(nn.Module):
    def __init__(self, input_size, hidden_size, output_size):
        super(Model, self).__init__()
        self.l1 = nn.Linear(input_size, hidden_size)
        self.activation = F.relu
        self.l2 = nn.Linear(hidden_size, output_size)

    def forward(self, x):
        output = self.l1(x)
        output = self.activation(output)
        output = self.l2(output)
        return output

model = Model(input_size, hidden_size, output_size)
model.eval()
example_inputs = [clipped_tensor]
mlir_mod = allo.frontend.from_pytorch(
    model, example_inputs=example_inputs, verbose=False
)
print(mlir_mod)

Buggy output

UnboundLocalError: cannot access local variable 'starting_line_no' where it is not associated with a value

Expected behavior
Expect to run successfully.

@jiahanxie353 jiahanxie353 added the bug Something isn't working label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant