llvm / llvm/torch-mlir

Does `torch_mlir.compile` exist now?

Open
#4,097 7 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I was trying to build and run a pytorch based project code. But I'm facing some errors.
I'm attaching the code:
`
import torch
import torch_mlir

 # Define a simple PyTorch model
 class SimpleModel(torch.nn.Module):
     def __init__(self):
         super(SimpleModel, self).__init__()
         self.linear = torch.nn.Linear(3, 2)

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

 # Create an instance of the model
 model = SimpleModel()
 model.eval()  # Set model to evaluation mode

 # Create example input tensor
 example_input = torch.randn(1, 3)

 # Compile the model using Torch-MLIR
 mlir_module = torch_mlir.compile(model, (example_input,), output_type="torch")

 # Print the MLIR output
 print(mlir_module)

`

I'm also attaching the error that i'm facing:
Traceback (most recent call last): File "/home/tos/COMPILER_PROJECT_DEC_2024/torch-mlir/sample.py", line 21, in <module> mlir_module = torch_mlir.compile(model, (example_input,), output_type="torch") ^^^^^^^^^^^^^^^^^^ AttributeError: module 'torch_mlir' has no attribute 'compile'

Can someone suggest me a solution to fix this issue ?

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.

Research direction

Start with the reproducer in sample.py and inspect the installed torch_mlir package API to verify whether compile is an available entry point. Compare the example's call and output_type with the project's supported usage, then confirm that the corrected minimal model example runs without the AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
compilers, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.