ImportError: cannot import name 'is_compiling' from 'torch._dynamo'

I have a jetson agx orin developer kit and I am following instructions from here to install cuda version of pytorch and torchvision. I successfully installed everything and the verification outputs are the following

 import torch
>>> import torchvision
>>> print(torch.__version__)
>>> print('CUDA available: ' + str(torch.cuda.is_available()))
CUDA available: True
>>> print('cuDNN version: ' + str(torch.backends.cudnn.version()))
cuDNN version: 8600
>>> print(torchvision.__version__)

Then I ran the following inference script

from detectron2.engine import DefaultPredictor
from detectron2.utils.visualizer import Visualizer
import cv2
from detectron2.utils.visualizer import ColorMode
from detectron2.config import get_cfg
from detectron2 import model_zoo
import os
import matplotlib.pyplot as plt

cfg = get_cfg()

cfg.MODEL.WEIGHTS = os.path.join("/detectron2_on_kitti/mask_rcnn_output/output_resnet-50/", "model_final.pth") 
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.7   # set a custom testing threshold
predictor = DefaultPredictor(cfg)

imgPath = "/dataset/data_semantics/testing/image_2/000000_10.png"
im = cv2.imread(imgPath)
outputs = predictor(im)  
v = Visualizer(im[:, :, ::-1],
               instance_mode=ColorMode.SEGMENTATION   # remove the colors of unsegmented pixels. This option is only available for segmentation models
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
plt.figure(figsize=(14, 20))
plt.imshow(out.get_image()[:, :, ::-1])

It produces the error ImportError: cannot import name 'is_compiling' from 'torch._dynamo' . Any thoughts on this?


Usually, this is a compatibility issue.
Have you checked the PyTorch/TorchVision version that the sample support?

More, there is no such import for is_compiling.
Is it called by an underlying module?


After installing, pytorch and torchvision as described in here, I installed detectron2 as python -m pip install 'git+'. All of this produced no errors. But only when I run the inference, the error appears. The full error msg is as follows

Traceback (most recent call last):
  File "/home/theia/Ash/repos/detectron2_on_kitti/", line 21, in <module>
    outputs = predictor(im)  # format is documented at
  File "/home/theia/.local/lib/python3.8/site-packages/detectron2/engine/", line 317, in __call__
    predictions = self.model([inputs])[0]
  File "/home/theia/anaconda3/envs/vision/lib/python3.8/site-packages/torch/nn/modules/", line 1480, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/theia/.local/lib/python3.8/site-packages/detectron2/modeling/meta_arch/", line 150, in forward
    return self.inference(batched_inputs)
  File "/home/theia/.local/lib/python3.8/site-packages/detectron2/modeling/meta_arch/", line 204, in inference
    features = self.backbone(images.tensor)
  File "/home/theia/anaconda3/envs/vision/lib/python3.8/site-packages/torch/nn/modules/", line 1480, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/theia/.local/lib/python3.8/site-packages/detectron2/modeling/backbone/", line 139, in forward
    bottom_up_features = self.bottom_up(x)
  File "/home/theia/anaconda3/envs/vision/lib/python3.8/site-packages/torch/nn/modules/", line 1480, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/theia/.local/lib/python3.8/site-packages/detectron2/modeling/backbone/", line 445, in forward
    x = self.stem(x)
  File "/home/theia/anaconda3/envs/vision/lib/python3.8/site-packages/torch/nn/modules/", line 1480, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/theia/.local/lib/python3.8/site-packages/detectron2/modeling/backbone/", line 356, in forward
    x = self.conv1(x)
  File "/home/theia/anaconda3/envs/vision/lib/python3.8/site-packages/torch/nn/modules/", line 1480, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/theia/.local/lib/python3.8/site-packages/detectron2/layers/", line 118, in forward
    is_dynamo_compiling = check_if_dynamo_compiling()
  File "/home/theia/.local/lib/python3.8/site-packages/detectron2/layers/", line 43, in check_if_dynamo_compiling
    from torch._dynamo import is_compiling
ImportError: cannot import name 'is_compiling' from 'torch._dynamo' (/home/theia/anaconda3/envs/vision/lib/python3.8/site-packages/torch/_dynamo/

Process finished with exit code 1

Interestingly it appears only in my jetson agx orin using conda. In my laptop, if I install pytorch and torchvision in a conda environment, it doesnt come up

@shyamashi can you try installing the PyTorch 2.0 wheel for JetPack 5 instead? That has torch._dynamo.is_compiling, whereas it had not yet been added to the build of PyTorch in the 1.14.0a0+44dac51c.nv23.02 wheel.

Alternatively, you could try commenting out this code from detectron2 (or checkout an older branch/tag of detectron2) and make it return False:

Thanks @dusty_nv for the reply. I have installed Pytorch 2.0 and torchvision 0.15 and the errors are gone.

In case anyone experiences the same error, there’s a detailed summary available at my wiki

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.