Unfortunately, I don’t have any further advice. Sorry! I do know that the switch function is not designed to break the gradient so there is something about that which can be addressed. Perhaps you could try narrowing it down to the Theano-only portions of your code and bringing it to their Github page.