Skip to content

fix: cast bfloat16 tensors to float32 before numpy conversion in MLX pipeline#57

Closed
kswanjitsu wants to merge 1 commit into
maziyarpanahi:masterfrom
kswanjitsu:fix/mlx-bfloat16-conversion
Closed

fix: cast bfloat16 tensors to float32 before numpy conversion in MLX pipeline#57
kswanjitsu wants to merge 1 commit into
maziyarpanahi:masterfrom
kswanjitsu:fix/mlx-bfloat16-conversion

Conversation

@kswanjitsu

Copy link
Copy Markdown

Problem

When loading models with bfloat16 weights (e.g. OpenMed/privacy-filter-nemotron) through the MLX pipeline, conversion fails with:

TypeError: Got unsupported ScalarType BFloat16

This happens in _to_numpy() because PyTorch CPU does not support .numpy() on bfloat16 tensors.

Fix

Cast bfloat16 tensors to float32 before calling .numpy(). The resulting MLX weights are stored in float32, which is fully supported on all Apple Silicon chips and incurs no meaningful accuracy loss for token classification.

Affected models

  • OpenMed/privacy-filter-nemotron (and any future bf16 models)

Testing

Verified that create_mlx_pipeline("OpenMed/privacy-filter-nemotron") completes weight conversion successfully after this fix.

…pipeline

PyTorch CPU does not support `.numpy()` on bfloat16 tensors, causing a
`TypeError: Got unsupported ScalarType BFloat16` when converting models
like `privacy-filter-nemotron` (which uses bf16 weights) to MLX format.

Cast the tensor to float32 before calling `.numpy()` when the dtype is
bfloat16. The resulting MLX weights are stored in float32, which is fully
supported on all Apple Silicon chips.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@maziyarpanahi

Copy link
Copy Markdown
Owner

closing in the favor of this PR: #58

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