Skip to content

torch.compile() may fail in some configuration #3986

Description

@tardyp

Bug

Docling fails to convert a PDF on Apple Silicon macOS when Torch model compilation is enabled by default.

The conversion reaches the layout-detection stage, then fails inside PyTorch TorchInductor with:

  torch._inductor.exc.InductorError:
  TypeError: BooleanAtom not allowed in this context.

Relevant traceback path:

  Docling layout model
    -> Transformers object-detection engine
      -> torch.compile()
        -> TorchDynamo/TorchInductor
          -> SymPy symbolic shape handling
            -> BooleanAtom not allowed in this context

Disabling Docling’s Torch compilation allows the same PDF to convert successfully:

  DOCLING_INFERENCE_COMPILE_TORCH_MODELS=false \
  uvx --native-tls docling \
    --to md \
    -v \
    --image-export-mode referenced \
    <mypdf>.pdf

The workaround produced valid Markdown output and referenced image artifacts. Therefore, the failure appears limited to the compiled inference path rather than PDF parsing or the conversion pipeline itself.

It would be useful if Docling either:

  • Automatically fell back to eager inference when torch.compile()/TorchInductor fails; or
  • Disabled model compilation by default for unsupported or unstable platform/backend combinations.

Steps to reproduce

  1. Use an Apple Silicon Mac.
  2. Obtain a PDF with the relevant characteristics. The original test file was a 64-page encrypted PDF.
  3. Run:
      uvx --native-tls docling \
        --to md \
        -v \
        --image-export-mode referenced \
        <mypdf>.pdf
  4. Observe that Docling selects the MPS accelerator:
      Accelerator device: 'mps'
    
  5. Observe that it initializes the Transformers object-detection layout engine.
  6. Observe conversion failure during layout processing:
      Stage layout failed
      TypeError: BooleanAtom not allowed in this context.
    
  7. Run the same conversion with model compilation disabled:
      DOCLING_INFERENCE_COMPILE_TORCH_MODELS=false \
      uvx --native-tls docling \
        --to md \
        -v \
        --image-export-mode referenced \
        <mypdf>pdf
  8. Observe that conversion succeeds.

Docling version

  Docling version: 2.119.0
  Docling Core version: 2.91.0
  Docling IBM Models version: 3.14.0
  Docling Parse version: 7.12.1
  Python: cpython-312 (3.12.11)
  Platform: macOS-26.5.2-arm64-arm-64bit

Python version

  Python 3.12.11

Additional environment information:

  PyTorch: 2.13.0
  Device selected by Docling: mps
  OS: macOS arm64

The exact error is:

  torch._inductor.exc.InductorError: TypeError: BooleanAtom not allowed in this context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions