Thanks for your reply!
The code below is used to convert faster-rcnn model to Torchscript model. you can use the cmd:
python script.py --model-out ./ --trace trace
to reproduce the phenomenon. (You just need to copy the code to a file and to name the file script.py)
import torch
import torchvision
import numpy as np
import argparse
from torchvision import transforms
import cv2

def do_script(model):
    model_script = torch.jit.script(model)
    model_script.eval()
    return model_script

def do_trace(model, in_size=100):
    tmp = torch.rand(1, 3, in_size, in_size).to(next(model.parameters()).device)
    print('Trace data device: %s'%tmp.device)
    print('Trace model device: %s'%next(model.parameters()).device)
    model_trace = torch.jit.trace(model, tmp)
    model_trace.eval()
    return model_trace

def dict_to_tuple(out_dict):
    if "masks" in out_dict.keys():
        return (out_dict["boxes"], out_dict["scores"], out_dict["labels"], out_dict["masks"])
    return (out_dict["boxes"], out_dict["scores"], out_dict["labels"])

class TraceWrapper(torch.nn.Module):
    def __init__(self, model):
        super().__init__()
        self.model = model

    def forward(self, inp):
        out = self.model(inp)
        return dict_to_tuple(out[0])

def save_jit_model(args, script=True):
    model_funcs = [torchvision.models.detection.fasterrcnn_resnet50_fpn] 
    names = ["faster_rcnn"]

    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
    for name, model_func in zip(names, model_funcs):
        model = model_func(pretrained=True)
        model.to(device)
        #for nm, param in model.state_dict().items():
        #    print(nm, param.size(), param.device)
        #print('Loading model device: %s'%next(model.parameters()).device)

        in_size = 100
        in_p = torch.rand(1, 3, in_size, in_size)
        if script == False:
            model = TraceWrapper(model)
            inp = in_p.to(device)
        else:
            inp = [in_p[0].to(device)]
        
        model.eval()

        with torch.no_grad():
            out = model(inp)

            if script:
                out = dict_to_tuple(out[0])
                script_module = do_script(model)
                script_out = script_module([inp[0]])[1]
                script_out = dict_to_tuple(script_out[0])
            else:
                script_module = do_trace(model)
                script_out = script_module(inp)

            #assert len(out[0]) > 0 and len(script_out[0]) > 0

            torch._C._jit_pass_inline(script_module.graph)
            torch.jit.save(script_module, args.model_out + '/' + name + ".pt")

def main():
    parser = argparse.ArgumentParser(description='This app is used to convert faster-rcnn model to torchscript')
    parser.add_argument('--model-in', type=str, help='To specify the input model path')
    parser.add_argument('--model-out', type=str, help='To specify the output model path')
    parser.add_argument('--num-classes', type=int, help='To specify the number of classes')
    parser.add_argument('--trace', type=str, default='trace', help='To specify a image used to be tested')

    args = parser.parse_args()
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')

    save_jit_model(args, args.trace == 'script')

if __name__ == '__main__':
    main()