[Vulkan] Missing/partial op support blocks full delegation of a dynamic-shape transformer encoder
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Área
- backend, computer-graphics
Línea de trabajo
Start with the supplied partitioning repro, then read backends/vulkan/op_registry.py and the Vulkan partitioner to map each reported gap. Inspect UnaryOp.cpp, unary_op.yaml, ScalarTensor.cpp, Expand.cpp, Full.cpp, and SDPA.cpp for the existing runtime paths. Done means the selected missing or incorrect operations are correctly partitioned without changing GELU numerics, and the repro shows the intended Vulkan delegation.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
🐛 Describe the bug
I'm adding a Vulkan option to examples/models/nemotron3_diarization, which has a 31-layer transformer encoder with a dynamic sequence length and runs in FP32. The encoder can't be delegated as a single Vulkan partition. The current workarounds are:
- eager attention with an additive mask;
RemoveRedundantOpsTransformbefore partitioning;aten.geluinoperator_blocklist, so it falls back to XNNPACK.
With these, the encoder lowers to 32 Vulkan + 31 XNNPACK partitions and the process peaks at about 3.5 GiB. When every GELU stays on Vulkan, peak is about 0.7 GiB.
Checked at 00e50304c6. backends/vulkan/op_registry.py is unchanged on current main.
Repro
Partitioning only; no GPU needed.
import collections
import torch
import torch.nn.functional as F
from executorch.backends.vulkan.partitioner import vulkan_partitioner as vp
from executorch.backends.vulkan.partitioner.vulkan_partitioner import VulkanPartitioner
from executorch.exir import EdgeCompileConfig, to_edge_transform_and_lower
from torch.export import Dim, export
skips = collections.Counter()
_log_skip = vp.VulkanSupportedOperators.log_skip
def log_skip(self, node, reason):
if node.op == "call_function":
name = vp.utils.node_io_str(node).split(" = ")[1].split("(")[0]
skips[(name, reason)] += 1
_log_skip(self, node, reason)
vp.VulkanSupportedOperators.log_skip = log_skip
class Block(torch.nn.Module):
def __init__(self, sdpa):
super().__init__()
self.sdpa = sdpa
self.qkv = torch.nn.Linear(64, 192)
self.ff = torch.nn.Linear(64, 64)
def forward(self, x, lengths):
b, s, _ = x.shape
mask = (torch.arange(s)[None, :] < lengths[:, None])[:, None, None, :]
q, k, v = self.qkv(x).view(b, s, 3, 2, 32).permute(2, 0, 3, 1, 4)
if self.sdpa:
y = F.scaled_dot_product_attention(q, k, v, attn_mask=mask)
else:
bias = torch.where(mask, 0.0, -torch.inf)
y = torch.softmax(q @ k.transpose(-1, -2) * 32**-0.5 + bias, -1) @ v
return F.gelu(self.ff(y.transpose(1, 2).reshape(b, s, 64)))
for sdpa in (False, True):
skips.clear()
ep = export(
Block(sdpa).eval(),
(torch.randn(1, 16, 64), torch.tensor([16])),
dynamic_shapes=({1: Dim("s", min=2, max=1000)}, {}),
strict=False,
)
edge = to_edge_transform_and_lower(
ep,
partitioner=[VulkanPartitioner({"require_dynamic_shapes": True})],
compile_config=EdgeCompileConfig(_check_ir_validity=False),
)
graph = edge.exported_program().graph_module.graph
delegates = sum("call_delegate" in str(n.target) for n in graph.nodes)
print(f"\n== {'sdpa' if sdpa else 'eager'}: {delegates} Vulkan delegate(s)")
for (name, reason), count in sorted(skips.items()):
print(f" {count}x {name}: {reason}")
Output:
== eager: 3 Vulkan delegate(s)
4x aten.expand_copy.default: no dynamic shape support
2x aten::scalar_tensor: no operator implementation
== sdpa: 4 Vulkan delegate(s)
1x aten.any.dim: no operator implementation
4x aten.expand_copy.default: no dynamic shape support
1x aten.full_like.default: no dynamic shape support
2x aten.mul.Scalar: no operator implementation
2x aten::scalar_tensor: no operator implementation
Exact GELU is missing from this output because Vulkan accepts it (see item 1).
Gaps
-
aten.geluwithapproximate="none"is computed with the tanh approximation.- The registry accepts every GELU: op_registry.py#L216.
gelu()ignoresapproximate: UnaryOp.cpp#L179-L185.- The shader always uses tanh: unary_op.yaml#L33-L34.
This changes numerics without any warning. With every GELU on Vulkan, the encoder's output probabilities differed from the reference by up to 6.3e-3 (tested on MoltenVK), against a 1e-4 FP32 tolerance.
Suggested fix: add an erf-based variant selected from
args[1]. GLSL has noerf, so it needs a polynomial approximation, e.g. Abramowitz–Stegun 7.1.26 (max error ≈1.5e-7). Until then, the partitioner could rejectapproximate != "tanh". -
aten.scalar_tensoris never partitioned.- EXIR keeps
scalar_tensoras an ATen op in the edge graph: replace_aten_with_edge_pass.py#L17-L21. - Vulkan only registers
exir_ops.edge.aten.scalar_tensor.default: op_registry.py#L1569-L1575.
The partitioner therefore reports "no operator implementation", even though a kernel exists: ScalarTensor.cpp#L51.
Registering
torch.ops.aten.scalar_tensor.defaultis not enough by itself. The graph builder serializesnode.target.__name__(vulkan_graph_builder.py#L486). For an ATen overload that isscalar_tensor.default, but the runtime looks upaten.scalar_tensor.default.It shows up from
torch.where(mask, 0.0, -inf)and from the SDPA decomposition. - EXIR keeps
-
aten.expand_copyhassupports_resize=False: op_registry.py#L1315.- With
require_dynamic_shapes=True, every expand is rejected. That includes static-shape expands, such as HF RoPE'sinv_freq[None, :, None].expand(...), and the same-shape expands frommatmuldecomposition. - The runtime already implements resizing: Expand.cpp#L19-L49.
- This may only need the flag plus a dynamic-shape test.
- With
-
aten.full/full_like/zeros*/ones*don't setsupports_resize: op_registry.py#L1547-L1562.- The runtime already implements resizing: Full.cpp#L19-L32.
- Same fix as 3.
-
Decomposed SDPA needs two ops that aren't registered:
aten.mul.Scalar: the decomposition scales both q and k bysqrt(scale).aten.any.dimon bool: comes from_safe_softmax, along withfull_like,eq.Scalarandlogical_not.
Instead of adding these one by one, a better option may be to lower
aten.scaled_dot_product_attentionto the existing fusedet_vk.sdpa. It takes q, k, v, an additive mask and a scale, and supports resizing: SDPA.cpp#L890-L999.Nothing produces
et_vk.sdpatoday. SDPA is not inops_not_to_decompose(vulkan_partitioner.py#L48-L52), and no pass rewrites it. Bool masks would need converting to additive masks.
Expected impact
I tested a 2-layer model built from the real Nemotron config, with the same per-layer ops, using eager attention and RemoveRedundantOpsTransform. Leaving GELU on Vulkan gives a single encoder delegate; only scalar_tensor stays outside. So item 1 alone restores single-partition delegation for this model. Items 2–5 would remove the need for eager attention and the extra pass.
This issue was drafted with Claude Code. The repro output above is from an actual run.
Versions
ExecuTorch at 00e50304c68e4bfa645ef2e8432f1795cfa2f6b7 (Vulkan registry identical on current main), macOS arm64. Runtime numbers from MoltenVK on Apple M1 Pro.
cc @SS-JIA @manuelcandales @digantdesai @cbilgin
- Lenguaje dominante
- Python
- Estrellas
- 5k
- Forks
- 1.2k
- Merge medio
- 2 d 7 h
- PR fusionados (30 d)
- 521
Preparar el entorno
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pytorch/executorch
-
enhancement triaged
Dificultad 2/5 Medio día Aptitud para principiantes 68/100
pytorch/executorch#21640 ·
Los mantenedores suelen responder en 1 día
-
[RFC] ExecuTorch Persisting Device Specialized Delegate ArtifactsPosiblemente ocupada @JacobSzwejbka la tomó hace 1 día. Abierto
pytorch/executorch#23192 · 1 comentario · 1 reacción · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[QNN] Enable ConvTranspose + BatchNorm fusion after #23170Posiblemente ocupada @psiddh la tomó hace 1 día. Abiertomodule: qnn partner: qualcomm
pytorch/executorch#23185 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
enhancement module: examples
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
pytorch/executorch#23164 · 7 comentarios · 2 reacciones ·
Los mantenedores suelen responder en 1 día
-
Qualcomm: 8-bit per-channel weight scales are floored at the 16-bit eps, and the HTP miscomputes near-zero channelsPosiblemente ocupada @psiddh la tomó hace 4 días. Abiertomodule: qnn module: quantization partner: qualcomm
pytorch/executorch#23160 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de pytorch/executorch
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
PedestrianDynamics/pyFDS-Evac#343 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
theskumar/python-dotenv#708 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 2 días
-
Docs Timedelta
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
pandas-dev/pandas#69919 ·
Los mantenedores suelen responder en 1 día
-
API documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
zephyrproject-rtos/west#1009 · 2 comentarios ·
Los mantenedores suelen responder en 3 días