I’ve put torch.autograd.set_detect_anomaly(True) at the start of my script but I’m not getting anything new in the stack. I’m not sure what I’m doing wrong.
Edit: I thought maybe I wasn’t getting that traceback you were talking about because I was running it in spyder, but here’s the traceback in a jupyter notebook:
> RuntimeError                              Traceback (most recent call last)
> <ipython-input-1-94a4c9e38816> in <module>
>     198 start = time.time()
>     199 res = optimize.basinhopping(my.fun, x0, niter=niter, T=temp, stepsize=stepsize,
> --> 200                             take_step=take_step, minimizer_kwargs=arg)
>     201 end = time.time()
>     202 sec = end - start
> 
> ~\Anaconda3\lib\site-packages\scipy\optimize\_basinhopping.py in basinhopping(func, x0, niter, T, stepsize, minimizer_kwargs, take_step, accept_test, callback, interval, disp, niter_success, seed)
>     667 
>     668     bh = BasinHoppingRunner(x0, wrapped_minimizer, take_step_wrapped,
> --> 669                             accept_tests, disp=disp)
>     670 
>     671     # start main iteration loop
> 
> ~\Anaconda3\lib\site-packages\scipy\optimize\_basinhopping.py in __init__(self, x0, minimizer, step_taking, accept_tests, disp)
>      72 
>      73         # do initial minimization
> ---> 74         minres = minimizer(self.x)
>      75         if not minres.success:
>      76             self.res.minimization_failures += 1
> 
> ~\Anaconda3\lib\site-packages\scipy\optimize\_basinhopping.py in __call__(self, x0)
>     284             return self.minimizer(x0, **self.kwargs)
>     285         else:
> --> 286             return self.minimizer(self.func, x0, **self.kwargs)
>     287 
>     288 
> 
> ~\Anaconda3\lib\site-packages\scipy\optimize\_minimize.py in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
>     616     elif meth == 'slsqp':
>     617         return _minimize_slsqp(fun, x0, args, jac, bounds,
> --> 618                                constraints, callback=callback, **options)
>     619     elif meth == 'trust-constr':
>     620         return _minimize_trustregion_constr(fun, x0, args, jac, hess, hessp,
> 
> ~\Anaconda3\lib\site-packages\scipy\optimize\slsqp.py in _minimize_slsqp(func, x0, args, jac, bounds, constraints, maxiter, ftol, iprint, disp, eps, callback, **unknown_options)
>     397 
>     398             # Compute objective function
> --> 399             fx = func(x)
>     400             try:
>     401                 fx = float(np.asarray(fx))
> 
> ~\Anaconda3\lib\site-packages\scipy\optimize\optimize.py in function_wrapper(*wrapper_args)
>     325     def function_wrapper(*wrapper_args):
>     326         ncalls[0] += 1
> --> 327         return function(*(wrapper_args + args))
>     328 
>     329     return ncalls, function_wrapper
> 
> ~\Anaconda3\lib\site-packages\scipy\optimize\optimize.py in __call__(self, x, *args)
>      63     def __call__(self, x, *args):
>      64         self.x = numpy.asarray(x).copy()
> ---> 65         fg = self.fun(x, *args)
>      66         self.jac = fg[1]
>      67         return fg[0]
> 
> ~\Desktop\JMP\Analysis\Original estimation 3-22-19\myLib_new2.py in fun(x, cons, est, trans, model, data)
>     115             ll = ll + logL(x, theta, model, data[d])
>     116         ll = ll / 1e+2
> --> 117         ll.backward()
>     118         grad = np.array(x.grad.cpu())
>     119         print(ll.item() * 1e+2)
> 
> ~\AppData\Roaming\Python\Python37\site-packages\torch\tensor.py in backward(self, gradient, retain_graph, create_graph)
>     196                 products. Defaults to ``False``.
>     197         """
> --> 198         torch.autograd.backward(self, gradient, retain_graph, create_graph)
>     199 
>     200     def register_hook(self, hook):
> 
> ~\AppData\Roaming\Python\Python37\site-packages\torch\autograd\__init__.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables)
>      98     Variable._execution_engine.run_backward(
>      99         tensors, grad_tensors, retain_graph, create_graph,
> --> 100         allow_unreachable=True)  # allow_unreachable flag
>     101 
>     102 
> 
> RuntimeError: The size of tensor a (28000) must match the size of tensor b (56000) at non-singleton dimension 0