pytorch / pytorch/executorch

Debugging to_executorch() call

Open
#1,890 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

module: devtools triaged
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

I was converting ultralytics/yolov5 from torch hub to executorch. Unfortunately one of the layers was unsupported, and the program exited with an error on this line: executorch_program: exir.ExecutorchProgramManager = edge_program.to_executorch(). The traceback was:

image

I've looked into the file being exported and this is what I saw:

class BaseModel(nn.Module):

    def _forward_once(self, x, p, v):
        for m in self.model: # nn.Sequential
            ...
            x = m(x)  # run
            ...
        return x

What is the recommended way to find out which layer in the nn.Sequential failed?

Given that:

  • Logging & printing is disabled
  • Debugging with breakpoints doesn't work

I've ended up monkey-patching the model and unwinding the nn.Sequential by hand:

class DebugModel(nn.Module):

    def forward(self, x):
        x0 = self.model[0](x)
        x1 = self.model[1](x0)
        x2 = self.model[2](x1)
        x3 = self.model[3](x2)
        x4 = self.model[4](x3)
        x5 = self.model[5](x4)
        x6 = self.model[6](x5)
        x7 = self.model[7](x6)
        x8 = self.model[8](x7)
        x9 = self.model[9](x8)
        x10 = self.model[10](x9)
        x11 = self.model[11](x10)
        x12 = self.model[12]([x11, x6])  # [-1, 6],
        x13 = self.model[13](x12)
        x14 = self.model[14](x13)
        x15 = self.model[15](x14)
        x16 = self.model[16]([x15, x4])  # [-1, 4],
        x17 = self.model[17](x16)
        x18 = self.model[18](x17)
        x19 = self.model[19]([x18, x14])  # [-1, 14],
        x20 = self.model[20](x19)
        x21 = self.model[21](x20)
        x22 = self.model[22]([x21, x10])  # [-1, 10],
        x23 = self.model[23](x22)
        x24 = self.model[24]([x17, x20, x23])  # [17, 20, 23]

        return x24

Executing this way I've found out that 11th layer is actually nn.Upsample which is unsupported. But my question is: Is there a better way? Is there a torch.export.log() or something similar?

Contributor guide

Open the contributing guide

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 at the edge_program.to_executorch() call and the BaseModel._forward_once implementation shown in the issue, then inspect the traceback around the failing nn.Sequential layer. Done means providing a supported way to identify the unsupported layer without manually unwinding the model, including coverage for the reported nn.Upsample case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
developer-experience, machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.