Reputation: 131
I am trying to run the script lstm_ptb.py but it is throwing a TypeError for the following line:
shrink_factor = ifelse(T.gt(norm_gparams,max_grad_norm),max_grad_norm/norm_gparams,1.)
This is what this line is trying to achieve:
if norm_gparams > max_grad_norm:
shrink_factor = max_grad_norm/norm_gparams
else:
shrink_factor = 1.
It says:
TypeError: The two branches should have identical types, but they are TensorType(float64, scalar) and TensorType(float32, scalar) respectively. This error could be raised if for example you provided a one element list on the
then
branch but a tensor on theelse
branch
How to resolve the error please? Thanks
Upvotes: 3
Views: 600
Reputation: 3281
Your problem caused by 1.
in else
part. By default it assigned as float32
type. You just need to convert it:
shrink_factor = ifelse(T.gt(norm_gparams,max_grad_norm),max_grad_norm/norm_gparams,np.float64(1.))
or convert the max_grad_norm/norm_gparams
value:
shrink_factor = ifelse(T.gt(norm_gparams,max_grad_norm),(max_grad_norm/norm_gparams).astype('float32'),1.)
so both value have the same type
Upvotes: 1