Apply the bit-vs-byte suffix rule to the binary size units - #4197
Open
vineethsaivs wants to merge 1 commit into
Open
Apply the bit-vs-byte suffix rule to the binary size units#4197vineethsaivs wants to merge 1 commit into
vineethsaivs wants to merge 1 commit into
Conversation
convert_file_size_to_int() reads a lowercase trailing "b" as bits and divides by 8, but only on the decimal units. The three binary branches (KiB, MiB, GiB) take the plain multiplier, so "1Gib" is read as one gibibyte instead of one gibibit and comes out 8x too large. "1Gib" and "1GiB" currently return the same number. Apply the same two-line form the GB/MB/KB branches already use, so all six units agree on what a trailing "b" means. An uppercase "B" takes the identical path it took before. The value is what max_memory entries are parsed with, in get_max_memory, get_balanced_memory, infer_auto_device_map and load_checkpoint_in_model, so an 8x overshoot is silent: it plans a device map against memory that is not there. test_convert_file_size gains the six lowercase-b spellings; the three decimal ones already pass and are there as controls.
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.
Symptom
convert_file_size_to_int()treats a lowercase trailingbas bits and divides by 8, but only for the decimal units. The binary units ignore the suffix:"1Gib"and"1GiB"return the same number, so a size given in gibibits is read as gibibytes and comes out 8x too large. The same holds forKibandMib.Root cause
Six sibling branches in the same function, and only three of them apply the rule:
This is not a question of whether bit units should be supported: the decimal branches already say they are, and give the exact two-line form. The
*iBbranches sit above them and were never updated.Fix
Apply the same two lines to the three binary branches so all six units agree on what a trailing
bmeans. An uppercaseBtakes the identical path it took before, and thefloatparsing added in #1799 plus themem_size < 0guard from #2507 are untouched.Why it matters
This is what
max_memoryentries are parsed with, inget_max_memory,get_balanced_memory,infer_auto_device_mapandload_checkpoint_in_model. An 8x overshoot there is silent: it plans a device map against memory that is not there, rather than raising.Test
Extended the existing
ModelingUtilsTester::test_convert_file_sizewith the six lowercase-bspellings:The three decimal cases in that loop (
100Kb,100Mb,2Gb) pass on both sides, so they are controls rather than tests of the new code.ruff checkreports the same 41 findings on these two files before and after the change (my ruff is newer than the pinned one), andruff format --checkis clean. Threetest_infer_auto_device_map_*_buffer*tests fail when the whole file is run, both with and without this change, and pass in isolation either way, so they are unrelated ordering flakes.