Fix dtype_byte_size for FP8 fnuz / e8m0fnu dtypes#4063
Open
lollinng wants to merge 1 commit into
Open
Conversation
dtype_byte_size only special-cased torch.float8_e4m3fn and float8_e5m2. The other 1-byte FP8 variants (float8_e4m3fnuz, float8_e5m2fnuz, float8_e8m0fnu) fell through to the regex r'[^\d](\d+)$', which finds no trailing digit and raised ValueError. This broke compute_module_sizes / device-map inference / estimate-memory for models using those dtypes. Handle all available 1-byte FP8 dtypes (guarded with hasattr for older torch). Adds a regression test. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
dtype_byte_sizeonly special-casestorch.float8_e4m3fnandtorch.float8_e5m2. The other 1-byte FP8 dtypes —float8_e4m3fnuz,float8_e5m2fnuz, andfloat8_e8m0fnu— fall through to:Their string forms end in
...fnuz/...fnu(no trailing digit), sobit_search is Noneand the function raisesValueError: dtype is not a valid dtype. This breaks anything that sizes such tensors —compute_module_sizes,infer_auto_device_map,estimate-memory, etc. — for models stored in those dtypes.Fix
Handle all available 1-byte FP8 dtypes, guarded with
hasattrso it stays correct on older torch where some variants don't exist.Testing done (CPU)
Added
tests/test_modeling_utils.py::ModelingUtilsTester::test_dtype_byte_size. With torch 2.12:Standard dtypes unchanged (
float32=4,float16/bfloat16=2,int8=1,float64=8,bool=1/8).ruff check/ruff format --checkclean.