Repository navigation
fix(decision-transformer): cast tensor calibration rows to the model dtype - #5038
Merged
Merged
Conversation
…dtype The tensor-calibration path added in ModelCloud#4894 hands the caller's own tensors to `DecisionTransformerModel.forward`. Loading at the default bfloat16 and passing `torch.randn` rows - float32, the natural spelling - fails inside the first matmul: RuntimeError: mat1 and mat2 must have the same dtype, but got Float and BFloat16 The error comes from torch's kernel at capture time, not from the loader, and it says nothing about which calibration key or which dtype pair is wrong. `move_input_capture_example` now casts floating rows to the model's weight dtype for definitions that declare `calibration_inputs = "tensor_kwargs"`. Integer rows (timesteps, attention masks) keep their dtype, and every other definition is untouched because the cast is gated on that flag. tests/test_decision_transformer_calibration_dtype_4755.py 7 passed tests/test_decision_transformer_4755.py 5 passed tests/module_tree/test_decision_transformer_model_tree.py 6 passed tests/test_calibration_data_device.py 17 passed, 5 skipped format/check.sh clean The new tests cover the reported failure end to end (bf16 model, float32 rows, quantize, finite `action_preds`), the integer rows staying integer, an fp32 model being left alone, the same cast being a no-op when the dtypes already agree, and the token path not being cast.
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.
Summary
The tensor-calibration path added in #4894 hands the caller's own tensors to
DecisionTransformerModel.forward. Loading at the default bfloat16 and passingtorch.randnrows - float32, the natural spelling - fails inside the first matmul during input capture:The error comes from torch's kernel, not from the loader, so it names neither the calibration key nor the dtype pair. The shipped end-to-end test loads the model as fp32, which is why the path was green.
Change
move_input_capture_examplecasts floating rows to the model's weight dtype when the definition declarescalibration_inputs = "tensor_kwargs":Same three combinations, before and after:
RuntimeErrorin the first matmulaction_predsTests
The end-to-end test is the reported failure: bf16 load, float32 rows, quantize, then
action_predsmust be finite and shaped(1, 8, 3). The rest pin the boundaries - integer rows stay integer, an fp32 model is left alone, the cast is a no-op when dtypes agree, and a definition without the flag is not cast.Note
Related to #4755, which is closed by #4894. This is the one gap my evaluation did not catch: I tested the shipped feature with the model loaded at its default dtype and float32 samples and hit it, which is likely how a user meets it too.