cuda.core: map ml_dtypes bfloat16 to kDLBfloat in DLPack export #3359
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 275 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.336
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3359"
general
weight: 0.35
seberg
Description
closes #3337
_smv_dtype_numpy_to_dlpackpicked the DLPack type code fromnumpy.dtype.kind, butml_dtypes.bfloat16has kind"V", so a bf16 view fell through to the unsupported-dtypeBufferErrorand could not be exported — even though the import side already acceptskDLBfloat(mapping it back tobfloat16whenml_dtypesis installed) and_tensor_map.pyxmapsbfloat16the same way. A bf16 tensor from PyTorch/CuPy/JAX can be viewed but not re-exported.This adds an explicit bfloat16 branch ahead of the kind chain that emits
kDLBfloatwith 16 bits, guarded by the module-levelml_dtypesavailability check already used on the import side.The new test round-trips through
StridedMemoryView.from_dlpackitself, so it cannot skip on stacks where NumPy's own DLPack support for extended dtypes is unavailable — the hole that let the existingtest_dlpack_export_roundtrip_dtypes[bfloat16]miss this via its NumPy-consumer probe.Evidence from the released cuda-core 1.2.2 wheel (host memory; numpy 2.3.5, ml_dtypes 0.6.0), matching the issue's reproducer:
with float16/uint16 views of the same buffer exporting fine. Additionally:
cython -3oncuda/core/_memoryview.pyxproduces identical diagnostics on base and on this branch (the two existing cuStreamWaitEvent assign notes are pre-existing; none added), and the new branch's dtype equality check matchesbfloat16while not matching bool/uint16/float16/int8. Full build and suite validation runs in this repository's CI.Checklist
---
AI assistance disclosure: the change and test were prepared with an AI coding agent (GLM-5.3) under my direction; I reviewed each line, verified the reproducer and evidence above, and stand behind the change. The new test carries
@pytest.mark.agent_authored(model="glm-5.3")per the provenance rules in AGENTS.md.