Skip to content

Fix formatted_int printing 1,000.0K / 1,000.0M at unit boundaries - #14342

Open
kevin9327 wants to merge 1 commit into
unslothai:mainfrom
kevin9327:fix-formatted-int-unit-rollover
Open

kevin9327 wants to merge 1 commit into
unslothai:mainfrom
kevin9327:fix-formatted-int-unit-rollover

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

Bug

unsloth.utils.hf_hub.formatted_int picks the unit from the raw value and then rounds to one decimal. A value just under a million or a billion picks the smaller unit, then rounds up to 1000.0 of it:

formatted_int(999_999)      # '1,000.0K', should be '1.0M'
formatted_int(999_999_999)  # '1,000.0M', should be '1.0B'

Fix

For each unit, check whether the value rounded to one decimal stays below 1000. If it doesn't, move to the next unit. Output for all other values is the same as before. The raw thresholds (< 1000 prints the integer, otherwise K/M/B) are also unchanged.

Test

tests/test_hf_hub_formatted_int.py loads unsloth/utils/hf_hub.py by path, so it doesn't import torch or the full package. It checks values around each boundary. The 999_999 and 999_999_999 cases fail before the fix and pass after. The other eight pass both before and after.

python -m pytest -q --noconftest tests/test_hf_hub_formatted_int.py   # 10 passed

AI assistance: I used an AI coding assistant (Grok Bot) to help find and write this fix. I reviewed the change and ran the test myself.

Values just below a million or a billion round up to 1000.0 of the smaller
unit, so 999,999 printed as 1,000.0K instead of 1.0M.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-20T12:37:32.471901Z 904ea23 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants