Hi, I am also very interested in this question. We are trying to implement a “custom” (to our problem) piecewise function using simple if/else logic. Simplified example; we create torch parameters (a,b,c and d)  and say that e.g. “if input < 5: value = ainput + b, else: value = cinput + d”.
The backpropagation and optimization seems to only give gradients for some of the values though, although we know that some of the inputs are in the different “ranges” (we have inputs both over and under 5, following the example above).
Will Pytorch accept such a function and the backpropagation + optimization (SGD) algorithm actually work for our function?