From cd6f58461848e3da6f4d336048bb29b87d78c0b6 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sat, 18 Jul 2026 09:56:27 +0000 Subject: [PATCH] feat(vram): parse IEC binary size suffixes (KiB..PiB) ParseSizeString accepted only SI suffixes, so a "20GiB" floor was rejected outright. Model and VRAM sizes are conventionally quoted in IEC units, and silently reading GiB as GB would understate a floor by about 7%. Purely additive: these inputs previously returned an unknown-suffix error. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ettore Di Giacinto --- pkg/vram/estimate.go | 17 +++++++++++++++-- pkg/vram/hf_estimate_test.go | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/vram/estimate.go b/pkg/vram/estimate.go index c91004a4b..faf3f1199 100644 --- a/pkg/vram/estimate.go +++ b/pkg/vram/estimate.go @@ -169,8 +169,9 @@ func EstimateMultiContext(ctx context.Context, files []FileInput, contextSizes [ } // ParseSizeString parses a human-readable size string (e.g. "500MB", "14.5 GB", "2tb") -// into bytes. Supports B, KB, MB, GB, TB, PB (case-insensitive, space optional). -// Uses SI units (1 KB = 1000 B). +// into bytes. Supports B, KB, MB, GB, TB, PB (case-insensitive, space optional) +// as SI units (1 KB = 1000 B), and the IEC suffixes KiB, MiB, GiB, TiB, PiB as +// binary units (1 KiB = 1024 B). func ParseSizeString(s string) (uint64, error) { s = strings.TrimSpace(s) if s == "" { @@ -212,6 +213,18 @@ func ParseSizeString(s string) (uint64, error) { multiplier = 1000 * 1000 * 1000 * 1000 case "P", "PB": multiplier = 1000 * 1000 * 1000 * 1000 * 1000 + // IEC binary suffixes. Model and VRAM sizes are conventionally quoted in + // these, so treating "GiB" as "GB" would understate a floor by 7%. + case "KIB": + multiplier = 1024 + case "MIB": + multiplier = 1024 * 1024 + case "GIB": + multiplier = 1024 * 1024 * 1024 + case "TIB": + multiplier = 1024 * 1024 * 1024 * 1024 + case "PIB": + multiplier = 1024 * 1024 * 1024 * 1024 * 1024 default: return 0, fmt.Errorf("unknown size suffix: %q", suffix) } diff --git a/pkg/vram/hf_estimate_test.go b/pkg/vram/hf_estimate_test.go index 345d9ec24..d0b66e9e9 100644 --- a/pkg/vram/hf_estimate_test.go +++ b/pkg/vram/hf_estimate_test.go @@ -25,6 +25,11 @@ var _ = Describe("ParseSizeString", func() { Entry("short suffix 100M", "100M", uint64(100_000_000)), Entry("short suffix 2G", "2G", uint64(2_000_000_000)), Entry("short suffix 1K", "1K", uint64(1_000)), + Entry("binary 1KiB", "1KiB", uint64(1024)), + Entry("binary 512MiB", "512MiB", uint64(512*1024*1024)), + Entry("binary 6GiB", "6GiB", uint64(6*1024*1024*1024)), + Entry("binary 2TiB", "2TiB", uint64(2*1024*1024*1024*1024)), + Entry("binary 1.5 gib lowercase with space", "1.5 gib", uint64(1.5*1024*1024*1024)), ) DescribeTable("invalid sizes",