Skip to content

[tmva][sofie] PyTorch parser registers 6 operators while SOFIE implements 55 #23108

Closed as not planned

Description

@Pranav-error

Explain what you would like to see improved and how.

SOFIE implements 55 ROperator_* classes in tmva/sofie/inc/TMVA/, and the Keras parser reaches a good fraction of them through 20 layer modules under _parser/_keras/layers/. The PyTorch parser, translated to Python in 7dd0d1d ([tmva][sofie] Translate PyTorch parser to Python, July), currently registers six operators:

https://github.com/root-project/root/blob/master/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tmva/_sofie/_parser/_pytorch/parser.py#L236-L241

mapPyTorchNode = {
    "onnx::Gemm": MakePyTorchGemm,
    "onnx::Conv": MakePyTorchConv,
    "onnx::Relu": MakePyTorchRelu,
    "onnx::Selu": MakePyTorchSelu,
    "onnx::Sigmoid": MakePyTorchSigmoid,
    "onnx::Transpose": MakePyTorchTranspose,
}

Anything outside that set stops at parser.py:275:

if node_type not in mapPyTorchNode:
    raise RuntimeError("TMVA::SOFIE - Parsing PyTorch node " + node_type + " is not yet supported")

The practical consequence is that common models cannot be converted from PyTorch even though SOFIE can already execute the operators they need:

PyTorch layer emitted node SOFIE operator that exists
nn.MaxPool2d / nn.AvgPool2d onnx::MaxPool / onnx::AveragePool ROperator_Pool
nn.BatchNorm2d onnx::BatchNormalization ROperator_BatchNormalization
residual x + f(x) onnx::Add ROperator_BasicBinary
nn.Flatten / .reshape() onnx::Reshape ROperator_Reshape
nn.Softmax onnx::Softmax ROperator_Softmax
nn.Tanh, nn.LeakyReLU onnx::Tanh, onnx::LeakyRelu ROperator_Tanh, ROperator_LeakyRelu
torch.cat onnx::Concat ROperator_Concat

So any CNN with pooling, and any ResNet-style model with skip connections, fails to parse.

This looks like the same shape as #22552 (Register the existing Swish operator in the ONNX parser): the operator is implemented, it is just not reachable from this parser. The fix per operator would be a MakePyTorchX mirroring the existing MakePyTorchConv / MakePyTorchRelu and one entry in mapPyTorchNode, with the Keras layer modules as a reference for attribute handling.

I would be happy to work through these, starting with MaxPool/AveragePool and BatchNormalization, if that ordering is useful and nobody is already on it.

A caveat on this report: the analysis is static, read from master. I have not reproduced the failures on a build — ROOT 6.40.02 does not ship the Python _pytorch parser at all (only _keras), so a master build is needed to exercise it. Happy to confirm each case against a build before sending anything.

Activity

  1. guitargeek commented on Aug 19, 2026

    @guitargeek
    Contributor

    Hi, thanks for the report! The PyTorch parser is indeed orphaned, because PyTorch supports ONNX export very well by now, so going over ONNX is the preferred path.

    In fact, we're about the remove the PyTorch parser:

    So no work is needed here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions