Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

theano.gradient.verify_grad lack of checking the validity of inputs #6804

Open
cheyennee opened this issue Dec 4, 2023 · 1 comment
Open

Comments

@cheyennee
Copy link

problem:
theano.gradient.verify_grad doesnt check the validity of inputs. In following snippet code, input_1 and input_alpha should have same shape. When I input them into theano.tensor.nnet.relu, this API throws error. While in theano.gradient.verify_grad, it outputs None without error.

repo code:

import theano
import theano.tensor as T
import numpy as np
def custom_activation(x, alpha):
    return theano.tensor.nnet.relu(x, alpha)

x1 = T.tensor3('x1')
alpha = T.tensor4('alpha')

output = custom_activation(x1, alpha)
loss = T.sum(output ** 2)
grad_x1, grad_alpha = T.grad(loss, [x1, alpha])
input_1 = np.random.random((1, 2, 3)).astype('float32')
input_alpha = np.random.random((1, 2, 1, 1)).astype('float32')

rng = np.random.RandomState(123)
print(theano.gradient.verify_grad(custom_activation, pt=[input_1, input_alpha], rng=rng))
@cheyennee cheyennee changed the title theano.gradient.verify_grad doesnt check the validity of inputs theano.gradient.verify_grad lack of checking the validity of inputs Dec 4, 2023
@cheyennee
Copy link
Author

Same problem can be found in theano.tensor.nnet.nnet.binary_crossentropy.
repo code:

import theano
import theano.tensor as T
import numpy as np
def custom_activation(output, target):
    return theano.tensor.nnet.nnet.binary_crossentropy(output, target)
output = T.tensor4('output')
target = T.tensor4('target')
output = custom_activation(output, target)
loss = T.sum(output ** 2)
grad_inputs, grad_gamma = T.grad(loss, [output, target])
output_data = np.random.random((1, 1, 1, 1)).astype('float32')
target_data = np.random.random((1, 2, 3, 1)).astype('float32')
rng = np.random.RandomState(123)
print(theano.gradient.verify_grad(custom_activation, pt=[output_data, target_data], rng=rng))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant