Skip to content

Fix: Convert np.float64 to native float in memory logging#2242

Merged
regisss merged 1 commit into
huggingface:mainfrom
yafshar:fix/convert-npfloat64-to-float
Sep 4, 2025
Merged

Fix: Convert np.float64 to native float in memory logging#2242
regisss merged 1 commit into
huggingface:mainfrom
yafshar:fix/convert-npfloat64-to-float

Conversation

@yafshar
Copy link
Copy Markdown
Contributor

@yafshar yafshar commented Sep 3, 2025

Summary

This PR updates the to_gb_rounded() utility function to return a native Python float instead of a np.float64. This change ensures cleaner and more readable logging output when memory stats are reported.

Changes

  • Cast result of np.round() to float in to_gb_rounded().

Motivation

Previously, memory values were logged as np.float64(82.78), which is verbose and less readable.

{'loss': 0.8835, 'grad_norm': 0.45611411333084106, 'learning_rate': 0.0004, 'epoch': 1.82, 'memory_allocated (GB)': np.float64(44.35), 'max_memory_allocated (GB)': np.float64(82.8), 'total_memory_available (GB)': np.float64(94.62)}

By converting to native float, logs now show values like 82.78, improving clarity for users and developers.

{'loss': 0.8835, 'grad_norm': 0.45611411333084106, 'learning_rate': 0.0004, 'epoch': 1.82, 'memory_allocated (GB)': 44.35, 'max_memory_allocated (GB)': 82.8, 'total_memory_available (GB)': 94.62}

Impact

  • Improves log readability.
  • No functional changes to memory calculations.
  • Safe and backward-compatible.

Testing

  • Verified that memory values are now printed as native floats.
  • No changes to numerical accuracy or behavior.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@yafshar yafshar requested a review from regisss as a code owner September 3, 2025 18:23
@karol-brejna-i karol-brejna-i self-assigned this Sep 4, 2025
Copy link
Copy Markdown
Collaborator

@karol-brejna-i karol-brejna-i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Collaborator

@regisss regisss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@regisss regisss merged commit a7fd116 into huggingface:main Sep 4, 2025
2 of 5 checks passed
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@yafshar yafshar deleted the fix/convert-npfloat64-to-float branch September 4, 2025 15:30
gplutop7 pushed a commit to HabanaAI/optimum-habana-fork that referenced this pull request Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants