forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 30
perf(glm5next): size the persisting-L2 set-aside for the weight prefetcher #578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
MadeBy561
wants to merge
4
commits into
local-inference-lab:dev/jovian-judgement
from
MadeBy561:perf/glm53-l2-prefetch-persisting-set-aside
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c3b683f
perf(glm5next): L2 weight prefetch for SM120 decode
439bd36
fix(glm5next): L2 prefetch review follow-ups
72c39c0
perf(glm5next): fire L2 prefetch windows before the all-reduces
9ab68a1
perf(glm5next): size the persisting-L2 set-aside for weight prefetch
MadeBy561 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| """Persisting-L2 set-aside sizing for the GLM-5.3 L2 weight prefetcher.""" | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from vllm.models.glm5next.nvidia import l2_prefetch as l2pf | ||
|
|
||
| MAX = 84_000_000 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("raw", "max_bytes", "expected"), | ||
| [ | ||
| ("max", MAX, MAX), | ||
| (" MAX ", MAX, MAX), | ||
| ("all", MAX, MAX), | ||
| ("40", MAX, 40_000_000), | ||
| ("40.5", MAX, 40_500_000), | ||
| ("200", MAX, MAX), # clamped to the device maximum | ||
| ("0", MAX, 0), | ||
| ("off", MAX, 0), | ||
| ("", MAX, 0), | ||
| (None, MAX, 0), | ||
| ("-5", MAX, 0), | ||
| ("bogus", MAX, 0), | ||
| ("max", 0, 0), # device without a persisting L2 set-aside | ||
| ], | ||
| ) | ||
| def test_persisting_l2_request(raw, max_bytes, expected): | ||
| assert l2pf.persisting_l2_request(raw, max_bytes) == expected | ||
|
|
||
|
|
||
| def test_default_request_is_device_maximum(): | ||
| assert l2pf.PERSIST_L2 == "max" | ||
|
|
||
|
|
||
| def _driver(): | ||
| from cuda.bindings import driver as cu | ||
|
|
||
| return cu | ||
|
|
||
|
|
||
| def _read_limit(cu, device: torch.device) -> int: | ||
| with torch.cuda.device(device): | ||
| torch.empty(1, device=device) # make the primary context current | ||
| err, value = cu.cuCtxGetLimit(cu.CUlimit.CU_LIMIT_PERSISTING_L2_CACHE_SIZE) | ||
| assert err == cu.CUresult.CUDA_SUCCESS | ||
| return int(value) | ||
|
|
||
|
|
||
| def _set_limit(cu, device: torch.device, value: int) -> None: | ||
| with torch.cuda.device(device): | ||
| torch.empty(1, device=device) | ||
| (err,) = cu.cuCtxSetLimit(cu.CUlimit.CU_LIMIT_PERSISTING_L2_CACHE_SIZE, value) | ||
| assert err == cu.CUresult.CUDA_SUCCESS | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA device required") | ||
| def test_configure_persisting_l2_applies_to_the_primary_context(): | ||
| cu = _driver() | ||
| device = torch.device("cuda", 0) | ||
| err, dev = cu.cuDeviceGet(0) | ||
| assert err == cu.CUresult.CUDA_SUCCESS | ||
| err, max_bytes = cu.cuDeviceGetAttribute( | ||
| cu.CUdevice_attribute.CU_DEVICE_ATTRIBUTE_MAX_PERSISTING_L2_CACHE_SIZE, dev | ||
| ) | ||
| assert err == cu.CUresult.CUDA_SUCCESS | ||
| if max_bytes <= 0: | ||
| pytest.skip("device has no persisting L2 set-aside") | ||
| before = _read_limit(cu, device) | ||
| try: | ||
| assert l2pf.configure_persisting_l2(device, request="max") == max_bytes | ||
| assert _read_limit(cu, device) == max_bytes | ||
|
|
||
| # A zero request never touches the driver state. | ||
| assert l2pf.configure_persisting_l2(device, request="0") == 0 | ||
| assert _read_limit(cu, device) == max_bytes | ||
|
|
||
| # Over-sized requests are clamped to the device maximum. | ||
| assert l2pf.configure_persisting_l2(device, request="100000") == max_bytes | ||
| finally: | ||
| _set_limit(cu, device, before) | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA device required") | ||
| def test_prefetcher_applies_the_env_request_once(monkeypatch): | ||
| cu = _driver() | ||
| device = torch.device("cuda", 0) | ||
| before = _read_limit(cu, device) | ||
| calls: list[str | None] = [] | ||
| real = l2pf.configure_persisting_l2 | ||
|
|
||
| def spy(dev, request=None): | ||
| calls.append(request) | ||
| return real(dev, request=request) | ||
|
|
||
| monkeypatch.setattr(l2pf, "configure_persisting_l2", spy) | ||
| monkeypatch.setattr(l2pf.L2Prefetcher, "_instances", {}) | ||
| monkeypatch.setattr(l2pf, "_persisting_l2_applied", {}) | ||
| try: | ||
| first = l2pf.L2Prefetcher.get(device) | ||
| second = l2pf.L2Prefetcher.get(device) | ||
| assert first is second | ||
| assert calls == [None] | ||
| assert first.persisting_l2_bytes == _read_limit(cu, device) | ||
| finally: | ||
| _set_limit(cu, device, before) | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Exercise a nondefault
PERSIST_L2request.calls == [None]proves the one-time lifecycle only. It does not prove that theNonepath usesPERSIST_L2. An implementation that always selects"max"passes this test.Set
l2pf.PERSIST_L2to a bounded nondefault value before the firstget(). Assert the clamped expected limit and retain the singleton assertion.🤖 Prompt for AI Agents