feat: Add BF16 tensor support via dlpack #371
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does the PR do?
Adds BF16 tensor support via DLPack.
tensor.as_numpy()
will not be supported forTYPE_BF16
tensors at this time due to lack of native support for BF16 in numpy.These BF16 tensors can easily be converted around with zero copies to dlpack-compatible frameworks like PyTorch and TensorFlow with their respective
to_dlpack
andfrom_dlpack
utilities.Checklist
<commit_type>: <Title>
Commit Type:
Check the conventional commit type
box here and add the label to the github PR.
Related PRs:
Test plan:
See testing PR.
Caveats:
as_numpy()
is not supported on BF16 tensors due to lack of native BF16 support innumpy
, and DLPack must be used instead.Background
LLMs are commonly trained in BF16, and when deployed for serving often have a pre/post processing model written in Python. This makes lack of BF16 support in the python models a blocker or requires significant workarounds for writing an ensemble/BLS LLM pipeline.
Adding BF16 support to the python backend will simplify this workflow.
Example
Example
model.py
using BF16 tensors viadlpack
andtorch
: