Skip to content

GPU inference? #11

@cleong110

Description

@cleong110

Is there a way to run this with GPU acceleration? I tried a number of different ways to run the models on GPU, but no matter what I do I still get errors like

RuntimeError: Input and hidden tensors are not at the same device, found input tensor at cuda:0 and hidden tensor at cpu

It seems that you need to save a different traced .pth?
https://docs.pytorch.org/docs/stable/jit.html#frequently-asked-questions seems to suggest that one must load the model architecture, "trace" it on a GPU and then save that.

Full traceback:

Traceback of TorchScript, serialized code (most recent call last):                                                                                                                            
  File "code/__torch__/pose_to_segments/src/model.py", line 22, in forward                                                                                                                    
    seq_length = ops.prim.NumToTensor(torch.size(pose_data, 1))                                                                                                                               
    input = torch.reshape(pose_data, [_0, int(seq_length), -1])                                                                                                                               
    _1 = (encoder).forward((pose_projection).forward(input, ), )                                                                                                                              
          ~~~~~~~~~~~~~~~~ <--- HERE                                                                                                                                                          
    _2 = (sign_bio_head).forward(_1, )                                                                                                                                                        
    _3 = (sentence_bio_head).forward(_1, )                                                                                                                                                    
  File "code/__torch__/torch/nn/modules/rnn.py", line 78, in forward                                                                                                                          
    _1 = [hx, hx0]                                                                                                                                                                            
    _2 = [weight_ih_l0, weight_hh_l0, bias_ih_l0, bias_hh_l0, weight_ih_l0_reverse, weight_hh_l0_reverse, bias_ih_l0_reverse, bias_hh_l0_reverse, weight_ih_l1, weight_hh_l1, bias_ih_l1, bias
_hh_l1, weight_ih_l1_reverse, weight_hh_l1_reverse, bias_ih_l1_reverse, bias_hh_l1_reverse, weight_ih_l2, weight_hh_l2, bias_ih_l2, bias_hh_l2, weight_ih_l2_reverse, weight_hh_l2_reverse, bi
as_ih_l2_reverse, bias_hh_l2_reverse, weight_ih_l3, weight_hh_l3, bias_ih_l3, bias_hh_l3, weight_ih_l3_reverse, weight_hh_l3_reverse, bias_ih_l3_reverse, bias_hh_l3_reverse]                 
    input, _3, _4 = torch.lstm(argument_1, _1, _2, True, 4, 0., True, True, True)                                                                                                             
                    ~~~~~~~~~~ <--- HERE                                                                                                                                                      
    return input                                                                                                                                                                              
                                                                                                                                                                                              
Traceback of TorchScript, original code (most recent call last):                                                                                                                              
/home/ubuntu/anaconda3/envs/trans/lib/python3.10/site-packages/torch/nn/modules/rnn.py(812): forward                                                                                          
/home/ubuntu/anaconda3/envs/trans/lib/python3.10/site-packages/torch/nn/modules/module.py(1488): _slow_forward                                                                                
/home/ubuntu/anaconda3/envs/trans/lib/python3.10/site-packages/torch/nn/modules/module.py(1501): _call_impl                                                                                   
/home/ubuntu/workspace/transcription/pose_to_segments/src/model.py(140): forward                                                                                                              
/home/ubuntu/anaconda3/envs/trans/lib/python3.10/site-packages/torch/nn/modules/module.py(1488): _slow_forward                                                                                
/home/ubuntu/anaconda3/envs/trans/lib/python3.10/site-packages/torch/nn/modules/module.py(1501): _call_impl                                                                                   
/home/ubuntu/anaconda3/envs/trans/lib/python3.10/site-packages/torch/jit/_trace.py(1056): trace_module                                                                                        
/home/ubuntu/anaconda3/envs/trans/lib/python3.10/site-packages/torch/jit/_trace.py(794): trace                                                                                                /home/ubuntu/workspace/transcription/pose_to_segments/src/train.py(153): <module>                                                                                                             
/home/ubuntu/anaconda3/envs/trans/lib/python3.10/runpy.py(86): _run_code                                                                                                                      
/home/ubuntu/anaconda3/envs/trans/lib/python3.10/runpy.py(196): _run_module_as_main
RuntimeError: Input and hidden tensors are not at the same device, found input tensor at cuda:0 and hidden tensor at cpu

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions