Repository navigation
fix(looper): read accelerator memory telemetry from the active device - #3438
Merged
Merged
Conversation
The EoRA processor log row queried torch.cuda.memory_stats directly and gated the second device on torch.cuda.device_count(). On a host whose active accelerator is not CUDA (Ascend NPU, XPU, CPU-only) the CUDA allocator reports no statistics for those devices, so the row silently read 0.00MB and the second-device branch was never taken even with several visible NPUs. Add resolve_memory_stats_callable()/memory_stats_for_device() next to the existing resolve_empty_cache_callable()/empty_cache_for_device() pair and use them for allocator telemetry in gptqmodel/looper/eora_processor.py and gptqmodel/looper/loop_processor.py. CUDA behaviour is unchanged. Signed-off-by: li-lizhe <147392333@qq.com>
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.
Summary
EoraProcessor.process()computed its per-modulePROCESS_USED_MEMORYvalue withtorch.cuda.memory_stats(DEVICE_0)and only looked at the second device whentorch.cuda.device_count() > 1.DEVICE_0/DEVICE_1come fromauto_select_torch_device(), so on ahost whose active accelerator is an Ascend NPU they are
npu:0/npu:1whiletorch.cuda.device_count()is 0: the CUDA allocator reports no statistics for those devices, the log rowsilently read
0.00MB, and the second-device branch was unreachable.get_max_memory()ingptqmodel/looper/loop_processor.pycarried the sametorch.cudaquery.resolve_memory_stats_callable()/memory_stats_for_device()are added next to the existingresolve_empty_cache_callable()/empty_cache_for_device()pair, and both call sites now use them. Thesecond-device condition is
DEVICE_1 != DEVICE_0. Distinct devices retain their log slots even whenstatistics are empty or unavailable (reported as
0.00MB), preserving the CUDA two-device format.CPU behaviour is unchanged (telemetry simply stays empty when no allocator applies).
Fixes #3437
What Changed
get_max_memory()andEoraProcessor.process(), preserving current versus peak reporting.0.00MBslot when its query is empty or fails, rather than silently dropping it.Tests
Review validation used mocked allocator APIs; it did not rerun the contributor's hardware validation below.
git diff --checkaction_required)Contributor's initial hardware verification
Real hardware: Ascend 910B host (aarch64, 4 NPUs,
torch 2.15.0.dev+torch_npu,torch.cuda.is_available() == False). The realgptqmodel/utils/torch.pywas loaded frommainand fromthis branch on that host, and the log row was computed both ways while allocations were actually held on
two NPUs:
The original five unit tests in
tests/test_accelerator_memory_stats.pyfail onmain(
AttributeError: ... has no attribute 'memory_stats_for_device') and pass with this change. They were runon the same Ascend host with a stand-in for the
monkeypatchfixture, andpython -m py_compileplusruff check(ruff 0.16.8 withformat/ruff.toml) report no new findings for the changed files.Notes
gptqmodelquantization with an EoRA adapter on the NPU host: that machine hastorch/torch_npubut not the rest of the gptqmodel dependency set, so only the changed module wasexercised there.
Review Requirements
Kernel Accuracy Requirements
AI assistance
This change was prepared with AI assistance. The contributor reviewed the diff and this description and
approved publishing it.
Link to Devin session: https://app.devin.ai/sessions/cc3422193f164d47afc2ba905ebcc77b
Open in Devin Desktop: https://app.devin.ai/desktop/session/cc3422193f164d47afc2ba905ebcc77b?variant=devin
Requested by: @Qubitium