openvino icon indicating copy to clipboard operation
openvino copied to clipboard

[Bug]: PyTorch to OpenVINO IR Conversion Fails Due to GRU all_weights Size Mismatch

Open Piotr45 opened this issue 10 months ago • 0 comments

OpenVINO Version

2025.1.0

Operating System

Ubuntu 20.04 (LTS)

Device used for inference

CPU

Framework

PyTorch

Model used

No response

Issue description

Model conversion from PyTorch to OpenVINO Intermediate Representation (IR) fails when using a torch.nn.GRU layer with bias=False. The error is caused by a mismatch in the expected number of weight tensors in the GRU's all_weights attribute.

Step-by-step reproduction

import torch
import torch.nn as nn
import openvino

class MyModel(nn.Module):
    def __init__(self, C):
        super(MyModel, self).__init__()
        self.C = C
        self.rnn = nn.GRU(
            input_size=self.C,
            hidden_size=self.C,
            num_layers=1,
            dropout=0.0,
            batch_first=True,
            bidirectional=False,
            bias=False
        )

    def forward(self, x):
        return self.rnn(x)[0]


def main() -> None:
    model = MyModel(32)

    export_input = torch.randn((1, 32), requires_grad=False)

    ov_model = openvino.convert_model(model, example_input=(export_input,), share_weights=False, verbose=True)


if __name__ == '__main__':
    main()

Relevant log output

Summary:
-- Conversion is failed for: aten::gru

openvino._pyopenvino.OpConversionFailure: Check 'is_conversion_successful' failed at src/frontends/pytorch/src/frontend.cpp:174:
FrontEnd API failed with OpConversionFailure:
Model wasn't fully converted. Failed operations detailed log:
-- aten::gru with a message:
Exception happened during conversion of operation __module.rnn/aten::gru with schema aten::gru.input(Tensor input, Tensor hx, Tensor[] params, bool has_biases, int num_layers, float dropout, bool train, bool bidirectional, bool batch_first) -> (Tensor, Tensor)
Check '(static_cast<int64_t>(all_weights.size()) == num_layers * weights_per_layer * mult)' failed at src/frontends/pytorch/src/op/lstm.cpp:98:
FrontEnd API failed with OpConversionFailure:
[PyTorch Frontend] Unexpected length of list with weights for rnn operation.

Summary:
-- Conversion is failed for: aten::gru

Issue submission checklist

  • [x] I'm reporting an issue. It's not a question.
  • [x] I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.
  • [x] There is reproducer code and related data files such as images, videos, models, etc.

Piotr45 avatar Jun 13 '25 10:06 Piotr45