Skip to content

Direct conversion of Ultralytics YOLO11n model to Executorch #14644

@LASTsue

Description

@LASTsue

When attempting to convert a standard Ultralytics YOLO model (yolo11n.pt) directly to the Executorch .pte format using the torch.export and to_edge flow, the process fails with the error 'float' object has no attribute 'node'. This error occurs even when the model and inputs are explicitly placed on the CPU, ruling out device mismatches with the XNNPACK partitioner.

Versions of the libraries:

  • PyTorch version: 2.8.0
  • Executorch version: 0.7.0
  • Ultralytics YOLO version: 8.3.203
  • Python version: 3.10
  • OS: Ubuntu 22.04

Code:

import torch
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
from executorch.exir import to_edge_transform_and_lower
from ultralytics import YOLO

yolo_model = YOLO("yolo11n.pt")
yolo_model=yolo_model.model
yolo_model.eval()

device = 'cpu'
yolo_model = yolo_model.to(device)

sample_inputs = (torch.randn(1, 3, 640, 640).to(device),)

exported=torch.export.export(yolo_model,args=sample_inputs)

et_program = to_edge_transform_and_lower(
    exported,
    partitioner=[XnnpackPartitioner()],
).to_executorch()

with open("yolo11n.pte", "wb") as file:
    et_program.write_to_file(file)

ERROR TRACEBACK:

'float' object has no attribute 'node'

While executing %item : [num_users=1] = call_function[target=torch.ops.aten.item.default](args = (%getitem_21,), kwargs = {})
GraphModule: class GraphModule(torch.nn.Module):
    ...

Original traceback:
File "/home/zll/miniconda3/envs/yolo/lib/python3.10/site-packages/ultralytics/nn/tasks.py", line 139, in forward
    return self.predict(x, *args, **kwargs)
  File "/home/zll/miniconda3/envs/yolo/lib/python3.10/site-packages/ultralytics/nn/modules/head.py", line 125, in forward
    y = self._inference(x)

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