PyTorch - CosineSimilarity in Sequential
I have a model which consists of 3 parts:

A submodule computing some vector x.

A similar submodule computing some vector y.

Final layer, which computes the similarity between these vectors and linearly scales it. Namely:
self.final = nn.Sequential(
    nn.CosineSimilarity(),
    nn.Linear(1, 1),
)



Now, I have problems with calling self.final. The following doesn't work:

self.final(x, y): forward() takes 2 positional arguments but 3 were given.
self.final([x, y]): forward() missing 1 required positional argument: 'x2'.

How should I use self.final? Of course, I can apply nn.CosineSimilarity and nn.Linear separately, but I wonder how to make this module work.
Edit: after using the modules separately, it turns out that I also need to reshape the output of CosineSimilarity, with .reshape(-1, 1), so the module as it is won't work. This also raises the question: how to fix the module (without defining a custom Reshape module like this one).

It is not possible to pass multiple objects through a torch.nn.Sequential module. If you really want to understand what's going on under the hood consider looking at the source:. The forward() method of Sequential is implemented as
 def forward(self, input):
    for module in self:
        input = module(input)
    return input

(Also consider this thread.)
So there is no way to do what you're asking with this module. But you can easily write your own, for instance following can accept multiple inputs to the first entry:
class MySeq(nn.Sequential):
    def __init__(self, *args):
        super().__init__(*args)

    def forward(self, *input):
        flag = True
        for module in self:
            if flag:
                input = module(*input)
                flag = False
            else:
                input = module(input)
        return input

To your second question: I don't think there are currently any modules in torch.nn for just reshaping. You need to do that manually, so I'd suggest writing your own module like:
class Final(nn.Module):
    def __init__(self):
        super().__init__()
        self.cs = nn.CosineSimilarity()
        self.lin = nn.Linear(1, 1)

    def forward(self, x, y):
        t = self.cs(x, y)
        return self.lin(t.reshape(-1, 1))

