How to compile in debug mode?

Hi, I wanted to transfer pytorch model to torchscript, so I used

test_model = torch.jit.script(model)

which model is a .pth checkpoint.
However, I got following errors:

File "/", line 54, in eval_one_epoch
    test_model = torch.jit.script(model)
  File "/xx/anaconda3/envs/xxx/lib/python3.7/site-packages/torch/jit/", line 898, in script
    obj, torch.jit._recursive.infer_methods_to_compile
  File "/xx/anaconda3/envs/xxx/lib/python3.7/site-packages/torch/jit/", line 352, in create_script_module
    return create_script_module_impl(nn_module, concrete_type, stubs_fn)
  File "/xx/anaconda3/envs/xxx/lib/python3.7/site-packages/torch/jit/", line 406, in create_script_module_impl
    script_module = torch.jit.RecursiveScriptModule._construct(cpp_module, init_fn)
  File "/xx/anaconda3/envs/xxx/lib/python3.7/site-packages/torch/jit/", line 388, in _construct
  File "/xx/anaconda3/envs/xxx/lib/python3.7/site-packages/torch/jit/", line 373, in init_fn
    cpp_module.setattr(name, orig_value)
RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details)

It seemed to tell no more useful trace back. What means to compile in debug mode and how can I do? Or any other suggestions?

I guess the error message suggests to rebuild PyTorch from source with DEBUG=1 to get more debug information. Could you post the model definition which raises this error, please?