Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Ninja is required to load C++ extensions #1454

Open
yjcreation opened this issue Jul 29, 2022 · 9 comments
Open

RuntimeError: Ninja is required to load C++ extensions #1454

yjcreation opened this issue Jul 29, 2022 · 9 comments

Comments

@yjcreation
Copy link

yjcreation commented Jul 29, 2022

run code by python tools/eval.py -n yolox-s -c yolox_s.pth -b 2 -d 1 --conf 0.001

error:
2022-07-30 00:16:44.546 | ERROR | yolox.core.launch:launch:98 - An error has been caught in function 'launch', process 'MainProcess' (73156), thread 'MainThread' (85696):
Traceback (most recent call last):

File "tools/eval.py", line 219, in
args=(exp, args, num_gpu),
│ │ └ 1
│ └ Namespace(batch_size=2, ckpt='yolox_s.pth', conf=0.001, devices=1, dist_backend='nccl', dist_url=None, exp_file=None, experim...
└ ╒═══════════════════╤════════════════════════════════════════════════════════════════════════════════════════════════════════...

File "d:\pywork\3.debug\yolox\yolox\core\launch.py", line 98, in launch
main_func(*args)
│ └ (╒═══════════════════╤═══════════════════════════════════════════════════════════════════════════════════════════════════════...
└ <function main at 0x0000023B5407F730>

File "tools/eval.py", line 194, in main
model, is_distributed, args.fp16, trt_file, decoder, exp.test_size
│ │ │ │ │ │ │ └ (640, 640)
│ │ │ │ │ │ └ ╒═══════════════════╤════════════════════════════════════════════════════════════════════════════════════════════════════════...
│ │ │ │ │ └ None
│ │ │ │ └ None
│ │ │ └ False
│ │ └ Namespace(batch_size=2, ckpt='yolox_s.pth', conf=0.001, devices=1, dist_backend='nccl', dist_url=None, exp_file=None, experim...
│ └ False
└ YOLOX(
(backbone): YOLOPAFPN(
(backbone): CSPDarknet(
(stem): Focus(
(conv): BaseConv(
(conv): ...

File "d:\pywork\3.debug\yolox\yolox\evaluators\coco_evaluator.py", line 242, in evaluate
eval_results = self.evaluate_prediction(data_list, statistics)
│ │ │ └ tensor([2.1702, 0.0110, 4.0000], device='cuda:0')
│ │ └ [{'image_id': 0, 'category_id': 56, 'bbox': [-33.6690673828125, 9.699737548828125, 3907.0078125, 2132.7041015625], 'score': 0...
│ └ <function COCOEvaluator.evaluate_prediction at 0x0000023B58CC9BF8>
└ <yolox.evaluators.coco_evaluator.COCOEvaluator object at 0x0000023B60FC6F28>

File "d:\pywork\3.debug\yolox\yolox\evaluators\coco_evaluator.py", line 317, in evaluate_prediction
from yolox.layers import COCOeval_opt as COCOeval

File "d:\pywork\3.debug\yolox\yolox\layers_init_.py", line 11, in
from .fast_coco_eval_api import COCOeval_opt

File "d:\pywork\3.debug\yolox\yolox\layers\fast_coco_eval_api.py", line 17, in
FastCOCOEvalOp().jit_load()
└ <class 'yolox.layers.jit_ops.FastCOCOEvalOp'>

File "d:\pywork\3.debug\yolox\yolox\layers\jit_ops.py", line 107, in jit_load
verbose=verbose,
└ True

File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1136, in load
keep_intermediates=keep_intermediates)
└ True

File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1347, in _jit_compile
is_standalone=is_standalone)
└ False

File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1418, in _write_ninja_file_and_build_library
verify_ninja_availability()
└ <function verify_ninja_availability at 0x0000023B632F7268>

File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1474, in verify_ninja_availability
raise RuntimeError("Ninja is required to load C++ extensions")

RuntimeError: Ninja is required to load C++ extensions
How can I solve this on a windows machine ?

When i use pip install ninja, it shows Requirement already satisfied: ninja in d:\f\anaconda3\envs\yolox\lib\site-packages (1.10.2.3)

@FateScript
Copy link
Member

What about direct build by the following code:

from yolox.layers import FastCOCOEvalOp
FastCOCOEvalOp().jit_load()

@yjcreation
Copy link
Author

Where should the above code be added?

Before this problem occurs, I have added the above two lines of code to yolox/layers/fast_ coco_ eval_ api.py.
What should I do?

@FateScript
Copy link
Member

Where should the above code be added?

Plz try it in a terminal like python3 or ipython

@yjcreation
Copy link
Author

When i try it in a terminal like python3, I have the same error.yolox is my virtual environment:
`(yolox) D:\pywork\3.debug\YOLOX>python
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.

from yolox.layers import FastCOCOEvalOp
Using C:\Users\15496\AppData\Local\torch_extensions\torch_extensions\Cache\py37_cu113 as PyTorch extensions root...
Traceback (most recent call last):
File "D:\F\Anaconda3\envs\pytorch\lib\runpy.py", line 193, in run_module_as_main
"main", mod_spec)
File "D:\F\Anaconda3\envs\pytorch\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "D:\F\Anaconda3\envs\yolox\Scripts\ninja.exe_main
.py", line 4, in
ModuleNotFoundError: No module named 'ninja'
Traceback (most recent call last):
File "", line 1, in
File "D:\pywork\3.debug\YOLOX\yolox\layers_init
.py", line 11, in
from .fast_coco_eval_api import COCOeval_opt
File "D:\pywork\3.debug\YOLOX\yolox\layers\fast_coco_eval_api.py", line 17, in
FastCOCOEvalOp().jit_load()
File "D:\pywork\3.debug\YOLOX\yolox\layers\jit_ops.py", line 107, in jit_load
verbose=verbose,
File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1136, in load
keep_intermediates=keep_intermediates)
File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1347, in _jit_compile
is_standalone=is_standalone)
File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1418, in _write_ninja_file_and_build_library
verify_ninja_availability()
File "D:\F\Anaconda3\envs\yolox\lib\site-packages\torch\utils\cpp_extension.py", line 1474, in verify_ninja_availability
raise RuntimeError("Ninja is required to load C++ extensions")
RuntimeError: Ninja is required to load C++ extensions`

@FateScript
Copy link
Member

Plz make sure that ninja is installed in your conda env.

@yjcreation
Copy link
Author

yjcreation commented Aug 1, 2022

i'm sure that ninja is installed in my conda env yolox.
image

But i found that errorFile "D:\F\Anaconda3\envs\pytorch\lib\runpy.py", line 193, in run_module_as_main "main", mod_spec) File "D:\F\Anaconda3\envs\pytorch\lib\runpy.py", line 85, in run_code exec(code, run_globals) in the previous comment. So i installed ninja in another conda env pytorch. pytorch is my another conda env, i don't know why it went to my another virtual environment pytorch to find ninja in the virtual environment of yolox?

@zhoujinhai
Copy link

zhoujinhai commented Aug 25, 2022

What about direct build by the following code:

from yolox.layers import FastCOCOEvalOp
FastCOCOEvalOp().jit_load()

I am add this code in train.py, and get the following err:

Traceback (most recent call last):
  File "/home/jinhai_zhou/work/YOLOX/tools/train.py", line 17, in <module>
    FastCOCOEvalOp().jit_load()
  File "/home/jinhai_zhou/work/YOLOX/yolox/layers/jit_ops.py", line 107, in jit_load
    verbose=verbose,
  File "/home/anaconda3/envs/Yolo/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 997, in load
    keep_intermediates=keep_intermediates)
  File "/home/anaconda3/envs/Yolo/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1202, in _jit_compile
    with_cuda=with_cuda)
  File "/home/anaconda3/envs/Yolo/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1268, in _write_ninja_file_and_build_library
    verify_ninja_availability()
  File "/home/anaconda3/envs/Yolo/lib/python3.6/site-packages/torch/utils/cpp_extension.py", line 1323, in verify_ninja_availability
    raise RuntimeError("Ninja is required to load C++ extensions")
RuntimeError: Ninja is required to load C++ extensions

I have the same problem, but the ninja was installed in my conda env
image

@yjcreation Then I solved it by following code:

wget https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-linux.zip
sudo unzip ninja-linux.zip -d /usr/local/bin/
sudo update-alternatives --install /usr/bin/ninja ninja /usr/local/bin/ninja 1 --force 

@xiaomaofeng
Copy link

Is there any solution in windows environment with this problem?

@szymonkulpinski
Copy link

szymonkulpinski commented Feb 28, 2024

What solved it for me (so far) in a windows environment:
I made sure that I have ninja 1.11.1 installed in pip, re-installed YoloX and downloaded the ninja.exe for windows from ninja-build repo and added it to PATH together with my venv:

    my_env = os.environ.copy()
    my_env["PATH"] = "D:\\code\\YoloX\\.venv\\;" + my_env["PATH"]
    my_env["PATH"] = "D:\\code\\YoloX\\ninja\\;" + my_env["PATH"]
    os.environ.update(my_env)

After that had to fix #1346 and now I am currently fixing #1307.

UPDATE:
I gave up and I run it in WSL instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants