How about sidestepping the problem like this?
def forward(self, x):
    x_where_self_x_is_positive = x * (self.x > 0).float()
    x_where_self_x_is_negative = x * (self.x < 0).float()
    return self.linear1(x_where_self_x_is_positive) + self.linear2(x_where_self_x_is_negative)

Explanation
self.x > 0 returns a tensor of boolean values which I cast to float using .float(), this gives me a tensor of zeros and ones where the ones coincide with the positive values in self.x
Then all I have to do is multiply x by this mask and I get a tensor containing values of x where the corresponding element of self.x is positive, and zeros elsewhere.
Doing the same for the negative values in self.x gives me a tensor containing values of x in most of the other positions. I say most because if any element of self.x == 0, then both tensors will contain 0 in the corresponding position.
Finally, I calculate both linear layers, and add up the results.
Maybe I have misunderstood your requirement…
Note that self.linear1(x_where_self_x_is_positive) will not necessarily == 0 at all the positions where self.x == 0
Maybe this fits your requirements better…
def forward(self, x):
    result_where_self_x_is_positive = self.linear1(x) * (self.x > 0).float()
    result_where_self_x_is_negative = self.linear2(x) * (self.x < 0).float()
    return result_where_self_x_is_positive + result_where_self_x_is_negative