Repository navigation
Description
Summary
Three intrinsic tests fail intermittently on GPU hardware. Pass rates on unmodified upstream/main (317d5d9) across 10 independent runs:
| Test | Pass rate (main) | Pass rate (branch PR #1269) |
|---|---|---|
test_run_transformers[context-attribution] |
1/10 | 5/10 |
test_run_transformers[requirement_check_alora] |
1/10 | 1/10 |
test_groundedness_e2e_string_documents |
2/10 | 4/10 |
Note: context_relevance_alora and uncertainty_alora (0/10 on all hardware) are tracked separately in #1286 — those are a deterministic peft bug, not flakiness.
Observed failure modes
test_run_transformers[context-attribution]
The model returns a variable number of attribution spans. The test asserts an exact list length:
AssertionError: assert [{'attribution'...}, ...] == approx([...])
Impossible to compare lists with different sizes.
Lengths: 7 and 12
Captured model output on a failing run:
[{"r": 0, "c": [0, 19]}, {"r": 1, "c": [2, 0, 1, 19, 3, 72, 70, 71, 4, 21]}]On a passing run the model identifies the expected 12 citation span indices; on a failing run it produces only 7. The adapter function is non-deterministic in how many spans it attributes.
test_run_transformers[requirement_check_alora]
Score falls just outside the ±0.1 tolerance window:
AssertionError: assert {'score': 0.3208213073183745} == approx({'score': 0.2185103906492881 ± 0.1})
Max absolute difference: 0.1023109166690864
Max relative difference: 0.4682199156071104
The obtained score (0.321) exceeds the expected (0.219 ± 0.1) by just 0.002 above the upper bound. The tolerance window is narrower than the natural GPU score variance for this adapter.
test_groundedness_e2e_string_documents
On failing runs, the model incorrectly marks a clearly grounded sentence as NOT_SUPPORTED:
assert False is True
where False = as_bool()
ValidationResult(False,
reason='Response is not grounded - the following spans are not properly supported:\n\n'
'- "The Eiffel Tower is located in Paris, France." [NOT_SUPPORTED]\n\n'
'Summary: 0/1 spans needing citations are fully supported.',
score=None).as_bool
The test provides the sentence "The Eiffel Tower is located in Paris, France." verbatim in the document list and asks the model to verify the response "The Eiffel Tower is located in Paris, France." — a textbook grounded response. On failing runs the adapter returns NOT_SUPPORTED for the span. The same input passes on 2 of 10 GPU runs, confirming this is non-determinism rather than a logic error.
Likely causes
- GPU floating-point non-determinism: cuBLAS/cuDNN operations are not guaranteed reproducible without
torch.use_deterministic_algorithms(True)and fixed seeds. - Assertion tolerances too tight: ±0.1 score tolerance for
requirement_check_alorais narrower than the observed GPU score variance. The test just barely tips over the boundary. - Variable-length output:
context-attributionproduces a non-deterministic number of spans; the test asserts exact list equality rather than checking that the expected spans are a subset of the returned spans.
Possible fixes
requirement_check_alora: widen theabstolerance from 0.1 to 0.15, or verify the expected score was calibrated on GPU hardwarecontext-attribution: assert subset membership or at-minimum span count rather than exact list equalitygroundedness_e2e: set a fixedtorch.manual_seedin the test fixture, or run withtorch.backends.cudnn.deterministic = True- All three: consider
@pytest.mark.flaky(reruns=3)viapytest-rerunfailuresas a short-term mitigation
Reproduction
# Requires GPU (min 8 GB VRAM for groundedness test)
for i in $(seq 1 10); do
uv run pytest \
'test/formatters/granite/test_intrinsics_formatters.py::test_run_transformers[context-attribution]' \
'test/formatters/granite/test_intrinsics_formatters.py::test_run_transformers[requirement_check_alora]' \
'test/stdlib/requirements/test_groundedness_requirement_e2e.py::test_groundedness_e2e_string_documents' \
-q
done
# Expect roughly 1–5 passes across 10 runs for each test
Activity
planetf1 commentedon Jun 18, 2026
requirement_check_alora— Score non-determinism, not a bugHPC results (granite-4.0-micro, 2× NVIDIA GPU nodes): 0/20 passes across two independent 10-run batches.
Root cause: The requirement-check adapter is a binary classifier — it outputs
{"score": "yes"}or{"score": "no"}. Theio.yamllikelihoodtransformation converts this to a float using the model's token-level log-probability of "yes". These log-probs are inherently non-deterministic on GPU (cuDNN reduction order, softmax, layer norm), so the same input produces different scores on different hardware or even the same hardware at different times.Production impact: None.
mellea/stdlib/requirements/requirement.py:52(requirement_check_to_bool) only checksscore > 0.5(binary direction), never the exact float value. The adapter correctly classifies the input as "no" in every run; it's the confidence score that varies.HF docs confirm this is expected: From
ibm-granite/granitelib-core-r1.0README: "The threshold for converting this score to a binary outcome is left to the user and may need to be tuned for your use-case." No claim of cross-hardware score stability.Contrast with granite 3.x: The 3.x adapter was purely binary (single token Y/N). The score float is a new feature of the 4.x adapter's JSON output format.
Proposed fix: Change the test from float comparison to binary direction check — matching what production code actually validates.
planetf1 commentedon Jun 18, 2026
context-attribution— Non-deterministic sentence count and orderingHPC results (granite-4.0-micro, 2× NVIDIA GPU nodes): 0/20 passes across two independent 10-run batches.
Assertion failure:
test_intrinsics_formatters.py:830Error:
Impossible to compare lists with different sizes. Lengths: 7 and 12The
abs=0.1tolerance is a red herring here — the context-attribution output contains no float fields (allint,str, orNone). The actual failure is a list length mismatch: the golden file captured 7 attribution records from one GPU run, but other runs produce 9, 10, or 12 records due to the adapter returning a different number of context sentences per response sentence.Root cause
The context-attribution adapter implements a leave-one-out (LOO) importance ranking. For each response sentence, it assigns a ranked list of context sentences (
{"r": N, "c": [idx0, idx1, ...]}). The number of context sentences and their ordering are inherently non-deterministic on GPU hardware. Theexplodetransformation then converts each inner list into separate records, so variable input length → variable output length.HF docs confirm this is expected
From
ibm-granite/granitelib-core-r1.0/context-attribution/README.md(appears twice):Production impact
None.
mellea/stdlib/components/intrinsic/core.py:54-101(find_context_attributions) returns the raw list of attribution records as-is — no filtering, no ordering guarantees, no exact count checks. The caller receives a list of dicts and is free to sort, filter, or rank them however they like. The production code does not enforce stricter invariants than "a list of attribution dicts was returned."Proposed fix
Replace the exact equality assertion with a subset check: verify that the golden attributions (the "known good" core attributions) are present in the actual output. Extra or reordered attributions are the expected non-determinism. Add this branch at line 828, parallel to the existing
requirement_checkpath:The
continueskips thepytest.approxat line 830 for this test case.planetf1 commentedon Jun 18, 2026
test_groundedness_e2e_string_documents— Parser bug in production code, not GPU non-determinismPer-stage debug (10 runs, capturing raw LLM output + parser behavior)
Stage 1 (
citationsintrinsic adapter): 10/10 stable. Always outputs exactly 1 citationr[0:45] <- d0(0:45)covering the full response. No GPU non-determinism.Stage 2 (span extraction): Deterministic. Always extracts 1 span
[0:45].Stage 3 (necessity LLM judgment): 10/10
needs_citation=True.Stage 4 (support LLM-as-judge): THE BUG.
The LLM output is correct 10/10 runs
Every run the raw JSON contains
"support_level": "FULLY_SUPPORTED". The model always agrees the citation supports the span.BUT, the model outputs two different valid JSON structures:
Flat (flat, ~30% of runs) — PARSER WORKS:
[{"span_id": 0, "support_level": "FULLY_SUPPORTED"}]Nested (nested, ~70% of runs) — PARSER FAILS:
[{"span_id": 0, "citations": [{"support_level": "FULLY_SUPPORTED"}]}]The parser at
mellea/stdlib/requirements/rag.py:690-691only looks at the flat path:When the nested format appears,
judgment.get("support_level")returnsNone→support_level_raw = ""→ falls through toelse: "NOT_SUPPORTED".The model is ALWAYS correct. The parser is broken.
Why does the model output nested format?
The prompt at
rag.py:558-607(_build_batch_support_prompt) shows the INPUT spans with nested citations:{"span_id": 0, "text": "...", "citations": [ Citation 0 (from doc 0): "..." ]}But the expected OUTPUT format in instructions is flat:
'[{"span_id": ..., "support_level": ...}, ...]'The model gets confused by the nested input structure and mirrors it in the output. This is a prompt clarity issue — granite-4.0-micro (1B params) is particularly prone to format confusion.
This is a production bug
The parser lives in
mellea/stdlib/requirements/rag.py:662(_parse_batch_support_output) — production code, not test code. Every user ofGroundednessRequirementgets incorrect results when the model outputs the nested format.Proposed fix (two parts, both in production code)
1. Fix the parser (
rag.py:690-692) to handle both formats:2. Improve prompt clarity (
rag.py:598-606) by adding explicit flat output example:3. After fix: The test assertion
assert result.as_bool() is Trueshould be stable again because the parser will correctly extract the support level regardless of JSON structure.4. Add a unit test for the nested format in
test/stdlib/requirements/test_groundedness_requirement.pyto prevent regression.planetf1 commentedon Jun 18, 2026
granite-4.1-3b vs granite-4.0-micro: model comparison
Deep analysis shows the issue is specific to granite-4.0-micro.
The parser fix is correct regardless of model choice.
Test comparison (10 runs each, HPC)
Key finding
granite-4.1-3b consistently outputs flat JSON format because the larger model is better at following format instructions. granite-4.0-micro (smaller model) mirrors the prompt's nested input structure ~70% of the time.
Recommendation
Keep granite-4.0-micro for tests because it's faster and uses less memory. The parser fix makes it reliable. The fix is defensive engineering — it handles what any model produces, regardless of model choice.
Where else is LLM-as-judge used?
Only in
GroundednessRequirement:_identify_citation_necessity(rag.py:285) - citation necessity judgment_assess_citation_support(rag.py:385) - citation support judgmentPerformance impact
planetf1 commentedon Jun 18, 2026
Testing methodology summary
HPC environment
granite-4.0-micro e2e (with parser fix) — 10/10 pass ✅
Per-run (warm model): ~12-18s (2 LLM-as-judge calls: necessity + support assessment)
granite-4.1-3b vs old parser — 10/10 pass ✅
Per-run (warm model): ~20s
Key finding: granite-4.1-3b consistently produces flat JSON format. The issue is model-specific to granite-4.0-micro.
granite-4.0-micro model comparison — 10/10 pass ✅
Test methodology
All tests run on HPC via LSF bsub with:
gpu "num=1/task:mode=exclusive_process:mps=yes"Code changes summary
mellea/stdlib/requirements/rag.pysupport_levelincitations[]mellea/stdlib/requirements/rag.pytest/.../test_groundedness_requirement.pytest/.../test_intrinsics_formatters.pytest/.../test_intrinsics_formatters.pyLLM-as-judge locations
Only
GroundednessRequirementuses LLM-as-judge:_identify_citation_necessity(rag.py:285) — 1 LLM call_assess_citation_support(rag.py:385) — 1 LLM callplanetf1 commentedon Jun 18, 2026
PR Created
Draft PR: #1292
Status:
planetf1 commentedon Jun 18, 2026
HPC verification passed:
Draft PR #1292 created. Ready for review.
planetf1 commentedon Jun 19, 2026
HPC full intrinsic sweep results (single run, GPU p1-r11-n3)
Environment: PyTorch 2.11.0+cu130, CUDA, granite-4.0-micro
Phase 1:
test_run_transformers(15 GPU test combos)answerability_*(4)hallucination_detectionquery_clarification,query_rewritecontext_relevance(non-alora)continuein PR = no real assertioncontext_relevance_alora"{ context_relevance: relevant, response: As of my last update"citationscontext-attributionrequirement_check(non-alora)requirement_check_alora>=0.5) worksuncertainty(non-alora)uncertainty_aloraTwo new failures need fixing:
context_relevance_alora: Generation truncation causing JSON parse error (max_new_tokens not set)uncertainty_alora: Log-prob non-determinism can flip certainty across 0.5 threshold (worse than requirement_check)Phase 2:
test_core.py(5 qualitative tests)test_certaintytest_requirement_checktest_find_context_attributionsstrict=Falsetest_find_context_attributions_resolvestrict=Falsetest_certainty_with_toolsxfails to investigate: The context-attribution xfails use
result[:7] == expected(prefix match) but the full list length may be different. Previous tester may have given up on exact list comparison. These xfails will pass or fail randomly due to GPU non-determinism.Phase 3:
test_rag.py(14 qualitative tests)14 passed, 0 failed - All 14 string-comparison tests passed this run. Earlier investigation flagged 10 as "HIGH RISK" but they all matched the golden values. May be hardware/model-specific variance that didn manifest this run, or the golden values were captured from this same hardware.
Phase 4:
test_guardian.py(6 qualitative tests)6 passed, 0 failed - All guardian tests passed (string labels and threshold checks).
Phase 5:
test_groundedness_e2e_string_documentsTest name not found on this branch - the PR renamed/removed it. The original e2e groundedness test may have been replaced with the per-stage unit tests and the parser fix verification tests.
Summary
2 new failures need fixing before these flaky tests clean:
test_run_transformers[context_relevance_alora]- Generation truncation (set max_new_tokens)test_run_transformers[uncertainty_alora]- Log-prob non-determinism worse than expected2 xfails to investigate:
test_find_context_attributions- Context-attribution count may vary beyond[:7]prefixtest_find_context_attributions_resolve- Same issueplanetf1 commentedon Jun 19, 2026
Correction: The "test name changed" note in my previous comment was wrong — the original pytest script used a stale test name (
test_groundedness_e2e_string_documents) that was never a real test. The actual e2e groundedness test istest_groundedness_requirement_documents_in_message. Running it separately now (job 1280169).planetf1 commentedon Jun 19, 2026
context_relevance_alora test failure is tracked separately in #1301 — root cause is missing max_completion_tokens in the HF adapter io.yaml, compounded by upstream deprecation notice recommending prompting over this adapter.
fix(rag): handle nested JSON format in LLM support assessment parser
fix(intrinsics): restore aLoRA offsets and fix groundedness parser (g…
test(backends): add real-model GPU e2e for intrinsic adapter_scope ro…