Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #539
Problem
predict()reuses the fitTrainer. Afterfit(..., precision="bf16-mixed"), the network outputs were thereforebfloat16tensors, and the estimators'.cpu().numpy()conversion failed withTypeError: Got unsupported ScalarType BFloat16. This affectedpredict()of regressors and LSS models,predict_proba()of classifiers, and everything built on them (evaluate(),score(), andInferenceModel.from_estimator(...).predict()/.predict_proba()).Fix
TaskModel.predict_step(deeptab/training/lightning_module.py) upcastsfloat16/bfloat16outputs tofloat32before returning them. Every estimator's prediction path goes through it. Full-precision andfloat64outputs are untouched, and theReturnssection of the docstring documents the upcast.Tests
tests/integration/test_mixed_precision_predict.py(new file) fits withprecision="bf16-mixed"on CPU:test_regressor_predict_after_bf16_training:float32predictions.test_classifier_predict_proba_after_bf16_training:float32probabilities summing to 1, and validpredict()labels.test_lss_predict_after_bf16_training:float32for bothraw=Falseandraw=True.All three fail on
mainand pass with this change.Docs
No change needed.
precisionis already documented as a Lightning option passed through byfit().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)