Megvii-BaseDetection / Megvii-BaseDetection/YOLOX

Some questions about half-precision

Open
#1,345 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

I have got a tensorrt model by:
python tools/trt.py -f exps/example/yolox_voc/yolox_myvoc_m.py -c best_ckpt.pth
but I get :
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.cuda.HalfTensor) should be the same
when I used the tensorrt model to inference by:
python tools/demo.py image -f exps/example/yolox_voc/yolox_myvoc_m.py --path dog.jpg --trt --save_result --fp16

this is because of the code in the tools/demo.py:
`

    if trt_file is not None:
        from torch2trt import TRTModule

        model_trt = TRTModule()
        model_trt.load_state_dict(torch.load(trt_file))

        x = torch.ones(1, 3, exp.test_size[0], exp.test_size[1]).cuda()
        self.model(x)
        self.model = model_trt

`

the dtype of x is torch.float32 but the dtype of the models weights is torch.float16 at this time.

However,when i add a line of code (x = x.half()) befor the self.model(x),like this:
`

     if trt_file is not None:
         from torch2trt import TRTModule

         model_trt = TRTModule()
         model_trt.load_state_dict(torch.load(trt_file))

         x = torch.ones(1, 3, exp.test_size[0], exp.test_size[1]).cuda()

         x = x.half()

         self.model(x)
         self.model = model_trt

`

and to run the demo.py by:
python tools/demo.py image -f exps/example/yolox_voc/yolox_myvoc_m.py --path dog.jpg --trt --save_result --fp16

I got the following Error finnaly:
RuntimeError: CUDA error: an illegal memory access was encountered

So,how could I overcome this problem?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tools/demo.py and the TensorRT setup path invoked by tools/trt.py, then reproduce the reported command using --trt and --fp16. Compare the input dtype used during TensorRT initialization with the loaded model weights and investigate the illegal CUDA memory access. Done means the demo inference runs successfully with the reported commands.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.