facebookresearch / facebookresearch/detectron2

Slow inference on Mac with M1 processor architecture

Open
#4,888 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
34.7k
Forks
7.9k
PR merge metrics
No merged PRs in 30d

Description

While comparing the detectron performance on an old Intel-Mac and a newer M1-Mac we observed, that detectron takes about half an hour for an 5 seconds inference on the newer macs. Is this issue known and is there a fix for that? We also got some interesting errors in our logs:

`
2023-03-28 15:51:03 2023-03-28 13:51:03,297 [AnyIO worker] [INFO ]  Loaded model, starting inference took 316.69 secs
2023-03-28 15:51:04 /opt/pysetup/detection_serving/.venv/lib/python3.8/site-packages/torch/_tensor.py:575: UserWarning: floor_divide is deprecated, and will be removed in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values.
2023-03-28 15:51:04 To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor'). (Triggered internally at  /pytorch/aten/src/ATen/native/BinaryOps.cpp:467.)
2023-03-28 15:51:04   return torch.floor_divide(self, other)
2023-03-28 15:51:18 /opt/pysetup/detection_serving/.venv/lib/python3.8/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  /pytorch/c10/core/TensorImpl.h:1156.)
2023-03-28 15:51:18   return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
2023-03-28 15:51:18 [W NNPACK.cpp:79] Could not initialize NNPACK! Reason: Unsupported hardware.
2023-03-28 16:24:10 2023-03-28 14:24:10,015 [AnyIO worker] [INFO ]  Inference took 1986.69 secs
2023-03-28 16:24:10 2023-03-28 14:24:10,963 [AnyIO worker] [INFO ]  Encoding took 0.95 secs
2023-03-28 16:24:10 2023-03-28 14:24:10,964 [AnyIO worker] [INFO ]  Detection took 2304.33 secs
`

The inference runs in a docker container which has been built with the --platform=linux/amd64 flag. Detectron is installed via: `pip install ./docker/cpu/detectron2-0.6+cpu-cp38-cp38-linux_x86_64.whl ` and a local wheel file.

# Instructions to reproduce the issue
1) Create python:3.8.10-slim-buster docker container on M1-Mac.
2) Install detectron via wheel-file: `pip install ./docker/cpu/detectron2-0.6+cpu-cp38-cp38-linux_x86_64.whl `
3) Run some demo code for inference.

# Expected behaviour
Inference in about 5 seconds for one image.

# Behaviour on M1 Mac
`Inference took 1986.69 secs`

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue in a python:3.8.10-slim-buster Docker container on an M1 Mac using the docker/cpu/detectron2-0.6+cpu-cp38-cp38-linux_x86_64.whl and the demo inference code. Investigate the --platform=linux/amd64 setup and the logged NNPACK warning; done means one-image inference is close to the expected 5 seconds rather than thousands of seconds.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.