PyTorch 2.0 compile problem in mac

Hi I am trying to run the following code in my mac

import torch
import torchvision.models as models

model = models.resnet18()
optimizer = torch.optim.SGD(model.parameters(), lr=0.01)
compiled_model = torch.compile(model)

x = torch.randn(16, 3, 224, 224)
optimizer.zero_grad()
out = compiled_model(x)
out.sum().backward()
optimizer.step()

It is throwing this error

BackendCompilerFailed: debug_wrapper raised CppCompileError: C++ compile error

Command:
g++ /var/folders/0d/syd94gdj2fvgzt42r00zyh840000gn/T/torchinductor_mohit/eh/cehz4qmb25b7f22uecphqlnronbtybx2buc2d3lhquxtt7zs3d7j.cpp -shared -fPIC -Wall -std=c++17 -Wno-unused-variable -I/Users/mohit/opt/anaconda3/envs/pytorch_2/lib/python3.10/site-packages/torch/include -I/Users/mohit/opt/anaconda3/envs/pytorch_2/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -I/Users/mohit/opt/anaconda3/envs/pytorch_2/lib/python3.10/site-packages/torch/include/TH -I/Users/mohit/opt/anaconda3/envs/pytorch_2/lib/python3.10/site-packages/torch/include/THC -I/Users/mohit/opt/anaconda3/envs/pytorch_2/include/python3.10 -lomp -O3 -ffast-math -fno-finite-math-only -Xclang -fopenmp -D C10_USING_CUSTOM_GENERATED_MACROS -o/var/folders/0d/syd94gdj2fvgzt42r00zyh840000gn/T/torchinductor_mohit/eh/cehz4qmb25b7f22uecphqlnronbtybx2buc2d3lhquxtt7zs3d7j.so

Output:
In file included from /var/folders/0d/syd94gdj2fvgzt42r00zyh840000gn/T/torchinductor_mohit/eh/cehz4qmb25b7f22uecphqlnronbtybx2buc2d3lhquxtt7zs3d7j.cpp:2:
/var/folders/0d/syd94gdj2fvgzt42r00zyh840000gn/T/torchinductor_mohit/zt/cztcl2vp5yqlnhofzpqfficjcxgyict6e3xhfdd7sdbkipp4p44x.h:6:10: fatal error: ‘omp.h’ file not found
#include <omp.h>
^~~~~~~
1 error generated.

Set torch._dynamo.config.verbose=True for more information

You can suppress this exception and fall back to eager by setting:
torch._dynamo.config.suppress_errors = True

Please help me with this issue

This was fixed in nightlies where now the default compiler defaults to aot_eager so you can fix your code if you run torch.compile(m, backend="aot_eager")

1 Like