pytorch / pytorch/executorch

Export fails: sdpa_with_kv_cache not registered despite clean build from source (_portable_lib missing)

Open
#11,471 7 comments 0 reactions 1 assignee View on GitHub

@kimishpatel is already working on this.

Since Sep 25, 2025.

Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

Issue

Despite following both:

I was unable to export a Llama model using the SDPA path. The custom op torch.ops.llama.sdpa_with_kv_cache is never registered, and _portable_lib.so is missing entirely from the build artifacts. The exporter crashes as soon as it tries to import executorch.extension.llm.custom_ops.


Environment
Component Version
OS Ubuntu 22.04 LTS
Python 3.10.18 (venv)
CMake 3.22.1
GCC 11.4
Ninja 1.11.1
Git + LFS git 2.34.1 / git-lfs 3.4.0
Buck2 Auto-downloaded (2024-02-15-x86_64)
ExecuTorch version 0.6.0 (cloned from main branch)

Steps followed
git clone --recursive https://github.com/pytorch/executorch.git
cd executorch
git submodule sync --recursive
git submodule update --init --recursive --jobs 8
git lfs pull

python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
./install_requirements.sh         # also tried: pip install -e ".[examples]"

./install_executorch.sh --clean
./install_executorch.sh           

Everything completes without errors. A wheel is produced and installed into the venv.


What goes wrong

Running this sanity check:

from executorch.extension.llm.custom_ops import custom_ops
import torch
print("SDPA op present:", hasattr(custom_ops, "sdpa_with_kv_cache"))
print("TorchAO op present:", hasattr(torch.ops.torchao, "dequantize_affine"))

Prints:

SDPA op present: False
TorchAO op present: True

Further:

>>> from executorch.extension.llm.custom_ops import custom_ops
Traceback (most recent call last):
  File ".../custom_ops.py", line 20, in <module>
    op = torch.ops.llama.sdpa_with_kv_cache.default
AttributeError: '_OpNamespace' 'llama' object has no attribute 'sdpa_with_kv_cache'

...

ModuleNotFoundError: No module named 'executorch.extension.pybindings._portable_lib'

Unzipping the wheel confirms: _portable_lib.so is missing entirely.


ARM's Tutorial Failure

Exporting Llama-3.2-1B fails immediately at the attention replacement phase:

python -m executorch.examples.models.llama.export_llama \
  --checkpoint ~/.llama/checkpoints/Llama3.2-1B-Instruct/consolidated.00.pth \
  --params     ~/.llama/checkpoints/Llama3.2-1B-Instruct/params.json \
  -kv --use_sdpa_with_kv_cache -X --xnnpack-extended-ops \
  --max_seq_length 1024 --max_context_length 32000 \
  --output_name llama3.pte ...

Fails with:

ModuleNotFoundError: No module named 'executorch.extension.pybindings._portable_lib'
AttributeError: '_OpNamespace' 'llama' object has no attribute 'sdpa_with_kv_cache'

Expected
from executorch.extension.llm.custom_ops import custom_ops
assert hasattr(custom_ops, "sdpa_with_kv_cache")  # → True

and the exporter should succeed with --use_sdpa_with_kv_cache.

Versions

PyTorch version: 2.7.0+cpu
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-9ubuntu1) 11.4.0
Clang version: Could not collect
CMake version: version 3.31.6
Libc version: glibc-2.39

Python version: 3.10.18 (main, Jun 4 2025, 08:56:00) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.8.0-51-generic-x86_64-with-glibc2.39
Is CUDA available: False
CUDA runtime version: 12.6.85
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 2070
Nvidia driver version: 560.35.05
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.10.2
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.10.2
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.10.2
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.10.2
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.10.2
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.10.2
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.10.2
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.10.2
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==2.2.6
[pip3] torch==2.7.0+cpu
[pip3] torchao==0.10.0+git8b264ce1
[pip3] torchaudio==2.7.0+cpu
[pip3] torchdata==0.11.0
[pip3] torchsr==1.0.4
[pip3] torchtune==0.6.1
[pip3] torchvision==0.22.0+cpu

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.