Skip to content

fix(training): return float32 predictions under mixed precision - #540

Open
ChrisW09 wants to merge 1 commit into
mainfrom
fix/bf16-predict
Open

ChrisW09 wants to merge 1 commit into
mainfrom
fix/bf16-predict

Conversation

@ChrisW09

@ChrisW09 ChrisW09 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #539

Problem

predict() reuses the fit Trainer. After fit(..., precision="bf16-mixed"), the network outputs were therefore bfloat16 tensors, and the estimators' .cpu().numpy() conversion failed with TypeError: Got unsupported ScalarType BFloat16. This affected predict() of regressors and LSS models, predict_proba() of classifiers, and everything built on them (evaluate(), score(), and InferenceModel.from_estimator(...).predict()/.predict_proba()).

Fix

TaskModel.predict_step (deeptab/training/lightning_module.py) upcasts float16/bfloat16 outputs to float32 before returning them. Every estimator's prediction path goes through it. Full-precision and float64 outputs are untouched, and the Returns section of the docstring documents the upcast.

Tests

tests/integration/test_mixed_precision_predict.py (new file) fits with precision="bf16-mixed" on CPU:

  • test_regressor_predict_after_bf16_training: float32 predictions.
  • test_classifier_predict_proba_after_bf16_training: float32 probabilities summing to 1, and valid predict() labels.
  • test_lss_predict_after_bf16_training: float32 for both raw=False and raw=True.

All three fail on main and pass with this change.

Docs

No change needed. precision is already documented as a Lightning option passed through by fit().

Checks

  • just test: 3239 passed, 46 skipped, 28 xfailed; coverage 91.29%
  • just docs: build succeeded (warnings treated as errors)
  • just check: all hooks passed (ruff, prettier, pyright)

predict() reuses the fit Trainer, so after fit(precision="bf16-mixed") the
network outputs were bfloat16 tensors, and converting them with .numpy()
failed for regressors, classifiers' predict_proba() and LSS models.
Upcast half-precision outputs to float32 in TaskModel.predict_step.

Fixes #539

This branch has not been deployed

No deployments
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.

[BUG] predict()/predict_proba() crash after fit(precision="bf16-mixed"): unsupported ScalarType BFloat16

1 participant