Skip to content

[Python] Support bfloat16 in Python bindings via ml_dtypes - #31677

Draft
bhushan23 wants to merge 1 commit into
microsoft:mainfrom
bhushan23:dev/bhushan23/bfp16_python_support
Draft

[Python] Support bfloat16 in Python bindings via ml_dtypes#31677
bhushan23 wants to merge 1 commit into
microsoft:mainfrom
bhushan23:dev/bhushan23/bfp16_python_support

Conversation

@bhushan23

@bhushan23 bhushan23 commented Aug 5, 2026

Copy link
Copy Markdown

Description

Marshal bfloat16 tensors through OrtValue and session.run using the ml_dtypes.bfloat16 numpy extension dtype, since numpy has no native bfloat16. The dtype's type_num is resolved lazily at first use and cached, then wired into IsNumericDType, OnnxRuntimeTensorToNumpyType, and NumpyTypeToOnnxRuntimeTensorType so bfloat16 arrays flow through the standard input/output paths.

Adds ml_dtypes as a base runtime dependency and covers the plumbing with OrtValue round-trip and Identity/Add session.run tests.

Motivation and Context

onnx-runtime has support for bfloat16 for CUDA EP but is not usable via python APIs e.g. session.run due to lack of support for bfloat16 dtype in numpy.

Projects such as aimet-onnx depends on onnx-runtime for quantization and with this change calibrate with bf16

Marshal bfloat16 tensors through OrtValue and session.run using the
ml_dtypes.bfloat16 numpy extension dtype, since numpy has no native
bfloat16. The dtype's type_num is resolved lazily at first use and
cached, then wired into IsNumericDType, OnnxRuntimeTensorToNumpyType,
and NumpyTypeToOnnxRuntimeTensorType so bfloat16 arrays flow through
the standard input/output paths.

Adds ml_dtypes as a base runtime dependency and covers the plumbing
with OrtValue round-trip and Identity/Add session.run tests.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@tianleiwu

Copy link
Copy Markdown
Contributor

See #22306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants