I’m sorry for asking so many times.
I’ve changed the code as follows, but I’m facing another problem again.
class CNNForecast(nn.Module):
    def __init__(self, w, p_w):
        super(CNNForecast, self).__init__()
        self.first_conv1d = nn.Conv1d(in_channels=1, out_channels=32, kernel_size=2, stride=1, padding=0)
        self.maxpool1d = nn.MaxPool1d(kernel_size=2, stride=2)
        self.second_conv1d = nn.Conv1d(in_channels=32, out_channels=32, kernel_size=2, stride=1, padding=0)
        self.flatten = nn.Flatten()
        self.linear = nn.Linear(32, 40)
        self.dropout = nn.Dropout(p=0.5)
        self.out = nn.Linear(40, 1)

    def forward(self, x):
        x = F.relu(self.first_conv1d(x))
        x = self.maxpool1d(x)
        x = F.relu(self.second_conv1d(x))
        x = self.maxpool1d(x)
        x = self.flatten(x)
        x = self.dropout(x)
        x = self.out(x)
        return x


RuntimeError: mat1 dim 1 must match mat2 dim 0

The input and output of each layer seems to correspond, but what is the problem?