Run a single layer of an existing model

What would be my options if I wanted to run a specific layer of a model?
I know that I can get the output of any layer and that I can manually schedule a model to run a layer at a time. But I think there is no way to tell which layer you’re currently at when doing manual schedule (please correct me if I’m wrong). The point being that I don’t want to run the entire model, just one layer.

The alternative may be to extract that layer (in this case a ‘Conv’ layer) and its weights and create a new model through code?

  • Would this second approach work?
  • or is there an easier way that I might be missing?

I think there are number of ways I can think if.
(1) Just run through all the layers one at a time until you get to the layer you are interested in.
(2) You can add inputs and outputs then set the layer inputs names to the names of those inputs and the output name to the name of that layer. Then delete all other inputs and outputs. So you essentially created a model with just one layer.
(3) Use python onnx library to edit the model layers to do the same as in (2).

Probably (2) is easiest. It’s not particularly a straightforward thing to do as you can examine the inputs and outputs.

It’s not a particularly straightforward thing to do as it’s not a typical use case.

We may have better debugging tools in the future such as the graph tool.

Can you give an example of the kind of API that you would like to see for this case and it’s uses?

Thanks, that’s helpful. I’ll try creating the layer as a new model then.
Agree that it’s probably a very niche usecase. I don’t think I expect an API for this unless it’s more common than I realize.

(I’m running into this while implementing the marigold depth estimation model. Not 100% sure yet why this is needed myself)