Compile pytorch complexYOLOv3 model to MLIR failed
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 736
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 15
Description
Hi, I am trying to use torch-mlir to compile my model (ComplexYOLOv3) -> https://github.com/ghimiredhikura/Complex-YOLOv3
I can get right result if i use default code test_detection.py in github
Here is my compile code
`
import numpy as np
import math
import os
import argparse
import cv2
import time
import torch
import utils.utils as utils
from models import *
import torch.utils.data as torch_data
import utils.kitti_utils as kitti_utils
import utils.kitti_aug_utils as aug_utils
import utils.kitti_bev_utils as bev_utils
from utils.kitti_yolo_dataset import KittiYOLODataset
import utils.config as cnf
import utils.mayavi_viewer as mview
from torch_mlir import fx
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--model_def", type=str, default="config/complex_tiny_yolov3.cfg", help="path to model definition file")
parser.add_argument("--weights_path", type=str, default="checkpoints/tiny-yolov3_ckpt_epoch-220.pth", help="path to weights file")
parser.add_argument("--class_path", type=str, default="data/classes.names", help="path to class label file")
parser.add_argument("--conf_thres", type=float, default=0.5, help="object confidence threshold")
parser.add_argument("--nms_thres", type=float, default=0.5, help="iou thresshold for non-maximum suppression")
parser.add_argument("--img_size", type=int, default=cnf.BEV_WIDTH, help="size of each image dimension")
parser.add_argument("--split", type=str, default="valid", help="text file having image lists in dataset")
parser.add_argument("--folder", type=str, default="training", help="directory name that you downloaded all dataset")
opt = parser.parse_args()
print(opt)
classes = utils.load_classes(opt.class_path)
# device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = "cpu"
print("Device: ", device)
# Set up model
model = Darknet(opt.model_def, img_size=opt.img_size).to(device)
# Load checkpoint weights
model.load_state_dict(torch.load(opt.weights_path))
# Eval mode
with torch.no_grad():
model.eval()
dummy_input = torch.randn(1, 3, 1024, 1024)
print("Exporting to torch-MLIR...")
m = fx.export_and_import(model, dummy_input, output_type="torch")
print("✓ Successfully exported to TOSA!")
# Save MLIR to file
output_file = "yolov3_tosa.mlir"
print(f"\nSaving MLIR to {output_file}...")
with open(output_file, "w") as f:
f.write(str(m))
print(f"✓ Successfully saved to {output_file}!")
`
Follow is Error Log
`(base) root@16db5de91610:/workspace# python test_detection.py --split=sample --folder=sampledata
/opt/conda/lib/python3.11/site-packages/traits/etsconfig/etsconfig.py:425: UserWarning: Environment variable "HOME" not set, setting home directory to /tmp
warn(
Namespace(model_def='config/complex_tiny_yolov3.cfg', weights_path='checkpoints/tiny-yolov3_ckpt_epoch-220.pth', class_path='data/classes.names', conf_thres=0.5, nms_thres=0.5, img_size=608, split='sample', folder='sampledata')
Device: cpu
Exporting to torch-MLIR...
Segmentation fault (core dumped)`
if the error log is more detail, i will try debugging but just say to me "segmentation fault"
Environment:
python 3.11.14
torch 2.9.1+cu126
torch-mlir 20260127.705
torchaudio 2.9.1+cu126
torchelastic 0.2.2
torchvision 0.24.1+cu126
Thank you
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the command in test_detection.py with the reported Python, PyTorch, and torch-mlir versions, then narrow the crash to the model setup or the fx.export_and_import(model, dummy_input, output_type="torch") call. Use the reported ComplexYOLOv3 configuration, checkpoint, and 1024x1024 dummy input; done means identifying a reproducible failing operation or obtaining a non-crashing export with actionable diagnostics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- compilers, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100