You don't need to change to use this, but just FYI, there is pylearn2.utils.grad, which is just a wrapper around T.grad that sets disconnected_inputs to 'ignore'.