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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I wonder if we can do one better and just pass ownership of the buffer directly via Buffer::from_vec. This would require the memory-layout to be the same, but I would think it is.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems can't go direct in this pr,
bf16doesn't implementArrowNativeType, soBuffer::from_vecrejects it (arrow-rs registers the trait forf16/f32/f64among the floats, but notbf16). The root cause sits one layer deeper: Apache Arrow's logical type system has no bf16 primitive at all, which is why Lance falls back to FixedSizeBinary(2) in the first place.Maybe two ways to bridge it for a true zero-copy path, both larger than this pr's scope:
unsafetransmuteVec<bf16>→Vec<u16>viaVec::from_raw_parts, thenBuffer::from_vec. Sound becausebf16is#[repr(transparent)]overu16— same size and alignment, so the allocator Layout is preserved — but adds a newunsafeblock, which feels out of scope for a perf-only change.Enable the
bytemuckfeature onhalfin the workspace and usebytemuck::cast_vec::<bf16, u16>. Safe at the call site; the layouts match statically viarepr(transparent), so the runtime size/align check can't fire. Cost is a workspace dependency feature bump.This pr already removes the per-element allocation, which was the hot-path cost on 4096×512 batches. What's left is one linear pass over ~4 MB of bf16 data — likely a smaller win than the allocation fix this
PR captures.
Personally, I prefer to keep the current PR as-is and pursue one of the options as a follow-up, such as Option 2. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine to keep as is. I will merge. But either of those sound good as potential follow ups.