Fix memory accounting for integrated CUDA devices - #4187
Open
harshitakrishna18 wants to merge 1 commit into
Open
Fix memory accounting for integrated CUDA devices#4187harshitakrishna18 wants to merge 1 commit into
harshitakrishna18 wants to merge 1 commit into
Conversation
harshitakrishna18
marked this pull request as draft
August 27, 2026 03:39
harshitakrishna18
marked this pull request as ready for review
August 29, 2026 19:19
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.
What does this PR do?
get_max_memory()currently reports CUDA memory and available CPU RAM as separate memory budgets. This is incorrect for integrated CUDA devices because both values refer to the same shared physical memory.As a result, downstream code such as
infer_auto_device_map()can treat the two values as independent capacities and plan a model placement that exceeds the machine's actual available memory.This PR:
torch.cuda.get_device_properties(i).is_integratedwhile discovering CUDA devices."cpu"memory budget when an integrated CUDA device is detected.getattr(..., False)so devices and older PyTorch versions without theis_integratedattribute retain the existing behavior.is_integratedattribute.This follows the existing MPS behavior, where shared host and accelerator memory is exposed as a single allocation pool.
Fixes #4183
Testing
Added a parameterized unit test for
get_max_memory()that runs without requiring CUDA hardware.The test mocks CUDA device discovery, available device memory, device properties, CPU memory, and CUDA initialization. It covers:
is_integrated=True), verifying that no separate"cpu"memory budget is returned.is_integrated=False), verifying that the existing CUDA and CPU budgets are preserved.is_integrated, verifying compatibility with older PyTorch versions through thegetattr(..., False)fallback.Results:
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.