You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
predicates.py Apple Silicon VRAM estimate uses static heuristic instead of actual available memory, causing GPU-gated tests to run on under-resourced hardware #783
_apple_silicon_vram_gb() in test/predicates.py estimates usable GPU memory using a static formula:
min(total * 0.75, total - 16)
On a 32 GB machine this gives 16 GB, but psutil.virtual_memory().available at runtime shows ~18.5 GB actually free. More importantly, the formula is evaluated at pytest collection time with no knowledge of current system load, and
it doesn't align with how CUDA reports free VRAM (which the audit-markers skill's formula was written against).
Observed effect:test/stdlib/components/intrinsic/test_core.py has require_gpu(min_vram_gb=12), which the skill correctly computed using the adapter accumulation formula. However, on a 32 GB Apple Silicon machine the
predicate reports 16 GB available, so the gate passes. The model then runs under memory pressure and produces incoherent output (garbled JSON with raw token IDs), failing the test.
Proposed fix
Replace the static heuristic in _apple_silicon_vram_gb() with psutil.virtual_memory().available, which reflects actual free memory at collection time and is consistent with how CUDA reports free VRAM. The audit-markers skill
formula would then work correctly on both platforms without changes.
Branch:fix/audit-markers-vram-cross-check
Notes
psutil is already a project dependency (used by require_ram() in the same file)
The CUDA path in _gpu_vram_gb() reports total device memory, not free — may also be worth revisiting for consistency, but is a separate concern
@planetf1 I hit this issue while testing #782 and tried working with Claude to fix it, but hit EOD right before leaving for my 4-day weekend vacation. I figured you could take a look once you're back.
I'm not sure if Claudes description above makes sense, my tl;dr is that silicon uses unified ram and has to be treated differently than cuda so the test properly marked 12GB was pushing my ram to pressure and failing, this implies that a 12GB tests should not run on a 32GB Mac?
So I just had Claude summarize our findings and open this issue
I did consider this when I originally implemented -- but opted for a 'finger in the air' heuristic which mapped to my personal experience as a first pass.
We use min(total * 0.75, total - 16)
The 0.75 factor is an approximation of the max GPU allocation for unified memory (see sysctl iogpu.wired_limit_mb to view/change), and the 16GB free space for IDEs, and other desktop tools
So in the case of a 32GB machine we went up with min(24,16) = 16
For 64GB we have min(48,48) = 48
Both seem reasonable
You said you 'hit' this issue - do you mean you felt your machine was under-utilized? Or overloaded? or did tests fail? Or was it a code review observation?
I was indeed aware of the tool to get actual virtual memory usage - the problem is that it too is imperfect - it's the amount of memory available in the perfect world - sometimes pages are slow to release. It also includes virtual memory and we have to be careful not to introduce paging.
it also makes tests more non-deterministic since what tests run would fluctuate by more than a fairly fixed set based on machine config
So it could be worse, not better
A more sophisticated approach might therefore also need to consider
memory pressure (as reported by sys monitor), paging activity
Even better would be, via whatever stack/tool is in use, to discover whether all the model layers are loaded onto the gpu, or we missed
Observed effect: test/stdlib/components/intrinsic/test_core.py has require_gpu(min_vram_gb=12), which the skill correctly computed using the adapter accumulation formula. However, on a 32 GB Apple Silicon machine the
predicate reports 16 GB available, so the gate passes. The model then runs under memory pressure and produces incoherent output (garbled JSON with raw token IDs), failing the test.
Were you able to reproduce this multiple times?
Do you know what you memory usage (especially pinned memory) was?
How about memory pressure?
Can we get any debugging from the framework (may be worth trying to add this to better understand what is going on) - I would expect calls to pass, fail.. garbled output is a little concerning
Another thing to consider -- there's two parts to this
a) How much gpu memory we consider is 'usable' (the heuristic)
b) how much gpu memory we guess (with the agent) that the test might use
b) should also be considered - I think we can only hope that the agent has a good initial guess, but that tweaking further may be needed for some tests
Do you have any idea how much memory the test was trying to use? ie was the estimation assigned in the test appropriate
(will try this out myself when I get back to this issue tomorrow etc)
Do you have any idea how much memory the test was trying to use?
I'm not actually sure how to check the exit mem usage, I only have the activity monitor with doesn't show that. Is there a tool/app on macOS you know of that I could use instead?
I was just thinking about what activity monitor shows - there are multiple memory columns that can be viewed, as well as a summary which includes 'wired' memory (I may have mentioned pinned).
Ran into this whilst running the full docs/examples/ suite. The SOFAI graph-colouring example (sofai_graph_coloring.py) loads two models simultaneously — phi:2.7b (1.6 GB) and pielee/qwen3-4b-thinking-2507_q8 (4.3 GB). On a 32 GB Apple Silicon machine with other models still resident from earlier tests (guardian 8b at ~11 GB, llama3.2 at ~5.6 GB), ollama runs out of headroom and the model runner crashes:
ollama._types.ResponseError: model runner has unexpectedly stopped,
this may be due to resource limitations or an internal error (status code: 500)
Notably, the example has no require_gpu() or require_ram() gate, so even a corrected VRAM estimate wouldn't skip it — it just runs and dies under memory pressure.
Two things would help here:
The predicate fix proposed in this issue (actual available memory, not static heuristic)
Adding a resource gate to the SOFAI example so it skips gracefully when there isn't enough headroom
This may help keep memory usage more in control - though does not directly address this issue with how space is calculated
Will revisit the log above once happy with the eviction in #804
@ajbozarth you had a hypothesis this was a memory issue, but I don't believe there's sufficient evidence to prove this. You saw NaNs but that could be an issue with xgrammar, code versions, torch — not necessarily memory.
I am unable to reproduce. Used stress-ng to eat memory while running test_find_context_attributions in isolation on a 32 GB Apple Silicon machine (macOS 26.5):
Available RAM
Result
Duration
17.3 GB
PASS
37s
10.4 GB
PASS
49s
5.4 GB
PASS
51s
Passes at all levels, no NaN logits observed even at 5.4 GB available (well below the 12 GB gate).
Resolution proposal
The static heuristic (min(total * 0.75, total - 16)) is imperfect but stable — same machine always gates the same tests, which is what we want for reproducibility. The alternatives discussed (psutil available, memory pressure APIs) trade a known problem (occasionally too optimistic) for a worse one (non-deterministic test selection depending on system load).
Recommendation: keep the current heuristic. When a specific test fails on a machine class, bump that test's min_vram_gb rather than changing the global estimator.
Outstanding
@ajbozarth — I was unable to reproduce the NaN logits under simulated memory pressure (see above). Could you:
check ollama is up to date and dependencies synced
try running with OLLAMA_DEBUG=1 ? (to see if there are any oddities re: memory from ollama?)
Try running test_find_context_attributions in isolation (not as part of a full suite run) and confirm whether it still fails - maybe try stress-ng, or explicitly loading gradually increasing models into GPU memory with ollama to see if there's a breaking point (as I couldn't break mine)
If it does break, try with MPS_DEBUG=1 and/or PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 to get more diagnostic output from the MPS backend
That would help determine whether this is memory-related at all or a version-specific xgrammar/torch issue.
Will remove from my list for now as I think it needs work on your system.
I've actually been consistently successfully running tests since #804 merged, so I think that that actually indirectly solved this. I wouldn't be surprised if the current heuristic was just causing flaky but timing consistent issues due to the ollama issue not being factored into the usage calculation.
tl;dr thank you for investigating and we can close this for now
Activity
ajbozarth commentedon Apr 2, 2026
@planetf1 I hit this issue while testing #782 and tried working with Claude to fix it, but hit EOD right before leaving for my 4-day weekend vacation. I figured you could take a look once you're back.
I'm not sure if Claudes description above makes sense, my tl;dr is that silicon uses unified ram and has to be treated differently than cuda so the test properly marked 12GB was pushing my ram to pressure and failing, this implies that a 12GB tests should not run on a 32GB Mac?
So I just had Claude summarize our findings and open this issue
planetf1 commentedon Apr 7, 2026
I did consider this when I originally implemented -- but opted for a 'finger in the air' heuristic which mapped to my personal experience as a first pass.
We use
min(total * 0.75, total - 16)The 0.75 factor is an approximation of the max GPU allocation for unified memory (see
sysctl iogpu.wired_limit_mbto view/change), and the 16GB free space for IDEs, and other desktop toolsSo in the case of a 32GB machine we went up with min(24,16) = 16
For 64GB we have min(48,48) = 48
Both seem reasonable
You said you 'hit' this issue - do you mean you felt your machine was under-utilized? Or overloaded? or did tests fail? Or was it a code review observation?
I was indeed aware of the tool to get actual virtual memory usage - the problem is that it too is imperfect - it's the amount of memory available in the perfect world - sometimes pages are slow to release. It also includes virtual memory and we have to be careful not to introduce paging.
it also makes tests more non-deterministic since what tests run would fluctuate by more than a fairly fixed set based on machine config
So it could be worse, not better
A more sophisticated approach might therefore also need to consider
Even better would be, via whatever stack/tool is in use, to discover whether all the model layers are loaded onto the gpu, or we missed
planetf1 commentedon Apr 7, 2026
You said:
Were you able to reproduce this multiple times?
Do you know what you memory usage (especially pinned memory) was?
How about memory pressure?
Can we get any debugging from the framework (may be worth trying to add this to better understand what is going on) - I would expect calls to pass, fail.. garbled output is a little concerning
Another thing to consider -- there's two parts to this
a) How much gpu memory we consider is 'usable' (the heuristic)
b) how much gpu memory we guess (with the agent) that the test might use
b) should also be considered - I think we can only hope that the agent has a good initial guess, but that tweaking further may be needed for some tests
ajbozarth commentedon Apr 7, 2026
this is the limiting factor I hit. I would watch the test max out memory pressure in the system console during that test and it would always fail.
yes this particulate test (in desc) was consistently failing
planetf1 commentedon Apr 7, 2026
Do you have any idea how much memory the test was trying to use? ie was the estimation assigned in the test appropriate
(will try this out myself when I get back to this issue tomorrow etc)
ajbozarth commentedon Apr 7, 2026
I'm not actually sure how to check the exit mem usage, I only have the activity monitor with doesn't show that. Is there a tool/app on macOS you know of that I could use instead?
planetf1 commentedon Apr 8, 2026
I was just thinking about what activity monitor shows - there are multiple memory columns that can be viewed, as well as a summary which includes 'wired' memory (I may have mentioned pinned).
when I look at this PR I'll figure it out...
planetf1 commentedon Apr 9, 2026
Ran into this whilst running the full
docs/examples/suite. The SOFAI graph-colouring example (sofai_graph_coloring.py) loads two models simultaneously —phi:2.7b(1.6 GB) andpielee/qwen3-4b-thinking-2507_q8(4.3 GB). On a 32 GB Apple Silicon machine with other models still resident from earlier tests (guardian 8b at ~11 GB, llama3.2 at ~5.6 GB), ollama runs out of headroom and the model runner crashes:Notably, the example has no
require_gpu()orrequire_ram()gate, so even a corrected VRAM estimate wouldn't skip it — it just runs and dies under memory pressure.Two things would help here:
ajbozarth commentedon Apr 9, 2026
output for ref:
Terminal output
planetf1 commentedon Apr 9, 2026
This may help keep memory usage more in control - though does not directly address this issue with how space is calculated
Will revisit the log above once happy with the eviction in #804
planetf1 commentedon Apr 9, 2026
The
test_hallucination_detectiontolerance flakiness observed alongside these runs is now tracked separately in #809.planetf1 commentedon Apr 9, 2026
@ajbozarth you had a hypothesis this was a memory issue, but I don't believe there's sufficient evidence to prove this. You saw NaNs but that could be an issue with xgrammar, code versions, torch — not necessarily memory.
I am unable to reproduce. Used
stress-ngto eat memory while runningtest_find_context_attributionsin isolation on a 32 GB Apple Silicon machine (macOS 26.5):Passes at all levels, no NaN logits observed even at 5.4 GB available (well below the 12 GB gate).
Resolution proposal
The static heuristic (
min(total * 0.75, total - 16)) is imperfect but stable — same machine always gates the same tests, which is what we want for reproducibility. The alternatives discussed (psutil available, memory pressure APIs) trade a known problem (occasionally too optimistic) for a worse one (non-deterministic test selection depending on system load).Recommendation: keep the current heuristic. When a specific test fails on a machine class, bump that test's
min_vram_gbrather than changing the global estimator.Outstanding
@ajbozarth — I was unable to reproduce the NaN logits under simulated memory pressure (see above). Could you:
test_find_context_attributionsin isolation (not as part of a full suite run) and confirm whether it still fails - maybe try stress-ng, or explicitly loading gradually increasing models into GPU memory with ollama to see if there's a breaking point (as I couldn't break mine)MPS_DEBUG=1and/orPYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0to get more diagnostic output from the MPS backendThat would help determine whether this is memory-related at all or a version-specific xgrammar/torch issue.
Will remove from my list for now as I think it needs work on your system.
ajbozarth commentedon Apr 10, 2026
I've actually been consistently successfully running tests since #804 merged, so I think that that actually indirectly solved this. I wouldn't be surprised if the current heuristic was just causing flaky but timing consistent issues due to the ollama issue not being factored into the usage calculation.
tl;dr thank you for investigating and we can close this for now
planetf1 commentedon Apr 13, 2026
Ok thanks for updating. I'm not surprised - the ollama purging is a massive help -- and the existing heuristic wasn't a bad starting point