pytorch - 💡(How to fix) Fix [C++ API][Packaging] nlohmann/json.hpp is exposed again by public headers in PyTorch 2.10 wheels [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#181565Fetched 2026-04-28 06:24:43
View on GitHub
Comments
2
Participants
2
Timeline
49
Reactions
0
Author
Participants
Assignees
Timeline (top)
mentioned ×18subscribed ×18labeled ×7commented ×2

Error Message

python - <<'PY' import pathlib import torch

root = pathlib.Path(torch.file).parent print("torch version:", torch.version) print("torch root:", root)

paths = [ "include/ATen/functorch/Interpreter.h", "include/torch/csrc/profiler/python/combined_traceback.h", "include/nlohmann/json.hpp", "third_party/nlohmann/include/nlohmann/json.hpp", ]

for p in paths: print(p, (root / p).exists()) PY

Code Example

python - <<'PY'
  import pathlib
  import torch

  root = pathlib.Path(torch.__file__).parent
  print("torch version:", torch.__version__)
  print("torch root:", root)

  paths = [
      "include/ATen/functorch/Interpreter.h",
      "include/torch/csrc/profiler/python/combined_traceback.h",
      "include/nlohmann/json.hpp",
      "third_party/nlohmann/include/nlohmann/json.hpp",
  ]

  for p in paths:
      print(p, (root / p).exists())
  PY

---

TORCH_ROOT=$(python - <<'PY'
  import pathlib
  import torch
  print(pathlib.Path(torch.__file__).parent)
  PY
  )

  printf '#include <ATen/functorch/Interpreter.h>\n' | \
    c++ -x c++ -std=c++17 \
    -I"${TORCH_ROOT}/include" \
    -I"${TORCH_ROOT}/include/torch/csrc/api/include" \
    -fsyntax-only -

---

fatal error: nlohmann/json.hpp: No such file or directory

---

PyTorch version: 2.10.0+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 12.3.0-1ubuntu1~22.04.3) 12.3.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.13.11 | packaged by Anaconda, Inc. | (main, Dec 10 2025, 21:28:48) [GCC 14.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-60-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A

Versions of relevant libraries:
[pip3] pytest-sipu-triton-plugin==0.1.0
[pip3] torch==2.10.0+cpu
[conda] pytest-sipu-triton-plugin    0.1.0            pypi_0              pypi
[conda] torch                        2.10.0+cpu       pypi_0              pypi
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

In PyTorch 2.10, some installed public C++ headers include <nlohmann/json.hpp>, for example:

  • torch/include/ATen/functorch/Interpreter.h
  • torch/include/torch/csrc/profiler/python/combined_traceback.h
  • torch/include/torch/csrc/utils/generated_serialization_types.h

However, the PyTorch wheel does not appear to install nlohmann/json.hpp, and TorchConfig.cmake does not export an include path or target for nlohmann.

As a result, downstream C++ extensions / backend integrations that depend on PyTorch headers fail to compile unless nlohmann_json is installed separately.

This appears to be a regression of the same class as #130678. The previous fix in #131925 moved the nlohmann dependency out of NCCLUtils.hpp, but PyTorch 2.10 exposes it again through other installed public headers, e.g. ATen/functorch/Interpreter.h and torch/csrc/profiler/python/ combined_traceback.h.

The PyTorch source tree vendors nlohmann under third_party/nlohmann/include, so I would expect either:

  1. nlohmann/json.hpp to be installed as part of the wheel, or
  2. TorchConfig.cmake to export the required include path / CMake target, or
  3. public installed headers not to expose this dependency.

Repro

In a clean environment with PyTorch 2.10 installed but without system/conda nlohmann_json:

python - <<'PY'
import pathlib
import torch

root = pathlib.Path(torch.__file__).parent
print("torch version:", torch.__version__)
print("torch root:", root)

paths = [
    "include/ATen/functorch/Interpreter.h",
    "include/torch/csrc/profiler/python/combined_traceback.h",
    "include/nlohmann/json.hpp",
    "third_party/nlohmann/include/nlohmann/json.hpp",
]

for p in paths:
    print(p, (root / p).exists())
PY

Then try compiling a minimal source that only includes a public PyTorch header:

TORCH_ROOT=$(python - <<'PY'
import pathlib
import torch
print(pathlib.Path(torch.__file__).parent)
PY
)

printf '#include <ATen/functorch/Interpreter.h>\n' | \
  c++ -x c++ -std=c++17 \
  -I"${TORCH_ROOT}/include" \
  -I"${TORCH_ROOT}/include/torch/csrc/api/include" \
  -fsyntax-only -

Actual behavior

Compilation fails with:

fatal error: nlohmann/json.hpp: No such file or directory

Expected behavior

Downstream projects should be able to compile against the C++ headers installed by the PyTorch wheel without manually installing an undeclared transitive dependency.

Versions

This was reproduced with a pip-installed PyTorch wheel.

PyTorch version: 2.10.0+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 12.3.0-1ubuntu1~22.04.3) 12.3.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.13.11 | packaged by Anaconda, Inc. | (main, Dec 10 2025, 21:28:48) [GCC 14.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-60-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A

Versions of relevant libraries:
[pip3] pytest-sipu-triton-plugin==0.1.0
[pip3] torch==2.10.0+cpu
[conda] pytest-sipu-triton-plugin    0.1.0            pypi_0              pypi
[conda] torch                        2.10.0+cpu       pypi_0              pypi

cc @seemethere @malfet @atalman @tinglvv @nWEIdia @jbschlosser

extent analysis

TL;DR

Install nlohmann_json separately or modify PyTorch to not expose this dependency in its public headers.

Guidance

  • Verify that nlohmann/json.hpp is not installed by checking the include paths provided by TorchConfig.cmake.
  • Check if the PyTorch wheel installation includes nlohmann/json.hpp by looking for it in the torch/include directory.
  • Consider installing nlohmann_json as a separate dependency to resolve the compilation issue.
  • If using CMake, ensure that the TorchConfig.cmake file exports the required include path or target for nlohmann.

Example

No code snippet is provided as the issue is related to dependency management and header inclusion.

Notes

The issue seems to be a regression of a previous problem, and the fix might involve modifying PyTorch to handle the nlohmann dependency correctly.

Recommendation

Apply workaround: Install nlohmann_json separately, as this is the most straightforward solution to resolve the compilation issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING