llvm / llvm/torch-mlir

`fx.export_and_import` hangs

Open
#4,157 8 comments 0 reactions 1 assignee View on GitHub

@vivekkhandelwal1 is already working on this.

Since May 6, 2025.

Dominant language
C++
Stars
1.9k
Forks
736
Avg merge
5d 22h
Merged PRs (30d)
15

Description

I have a simple program:

class Conv2D(torch.nn.Module):

    def __init__(
        self,
        kernel_size=3,
        in_channels=8,
        out_channels=16,
        stride=1,
        padding=0,
        dilation=1,
        bias=True,
    ):
        super().__init__()
        self.conv = torch.nn.Conv2d(
            in_channels=in_channels,
            out_channels=out_channels,
            kernel_size=kernel_size,
            stride=stride,
            padding=padding,
            dilation=dilation,
            bias=bias,
        )

    def forward(self, x):
        return self.conv(x)

if __name__ == "__main__":
    model = Conv2D(
        kernel_size=(3, 3),
        in_channels=3,
        out_channels=8,
        stride=(1, 2),
        padding=(1, 1),
        dilation=(1, 1),
        bias=False,
    )
    model.eval()  # Set to evaluation mode
    example_input = torch.randn(2, 3, 5, 32, requires_grad=True, device="cpu")
    prog = torch.export.export(model, (example_input,))
    torch_module = fx.export_and_import(
        prog,
        func_name="temp",
        enable_graph_printing=False,
        import_symbolic_shape_expressions=True,
    )
    print(torch_module)

When I run it, it can generate the Torch-MLIR module like I want. However, when the program finished, it didn't exit cleanly but rather just hung there. I had to Ctrl+C to exit. I found the same thing happens to one of the examples - projects/pt1/examples/fximporter_resnet18.py (I've not checked other examples).
I've tried running my program with a debugger, and it looks like at the end, some Python internal cleaning processes got stuck in a loop or something like that. I'm not entirely sure what causes that.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.