Your code works fine and I don’t know where the error is raised, as you are not calling the forward method in the posted code snippet:
modelA = nn.Linear(1, 1)
modelB = nn.Linear(1, 1)
model = MyEnsemble(modelA, modelB)

x = torch.randn(1, 1)
out = model(x)