Skip to content

Compile pytorch complexYOLOv3 model to MLIR failed #4451

@bilv12-hub

Description

@bilv12-hub

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions