Skip to content

test: GPU score non-determinism causes flaky failures in context-attribution, requirement_check_alora, groundedness_e2e #1291

Closed

Description

@planetf1

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

  1. GPU floating-point non-determinism: cuBLAS/cuDNN operations are not guaranteed reproducible without torch.use_deterministic_algorithms(True) and fixed seeds.
  2. Assertion tolerances too tight: ±0.1 score tolerance for requirement_check_alora is narrower than the observed GPU score variance. The test just barely tips over the boundary.
  3. Variable-length output: context-attribution produces 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 the abs tolerance from 0.1 to 0.15, or verify the expected score was calibrated on GPU hardware
  • context-attribution: assert subset membership or at-minimum span count rather than exact list equality
  • groundedness_e2e: set a fixed torch.manual_seed in the test fixture, or run with torch.backends.cudnn.deterministic = True
  • All three: consider @pytest.mark.flaky(reruns=3) via pytest-rerunfailures as 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

  1. added
    p2
    on Jun 18, 2026
  2. planetf1 commented on Jun 18, 2026

    @planetf1
    ContributorAuthor

    requirement_check_alora — Score non-determinism, not a bug

    HPC 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"}. The io.yaml likelihood transformation 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 checks score > 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.0 README: "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.

  3. planetf1 commented on Jun 18, 2026

    @planetf1
    ContributorAuthor

    context-attribution — Non-deterministic sentence count and ordering

    HPC results (granite-4.0-micro, 2× NVIDIA GPU nodes): 0/20 passes across two independent 10-run batches.

    Assertion failure: test_intrinsics_formatters.py:830

    assert t_json == pytest.approx(e_json, abs=0.1)

    Error: Impossible to compare lists with different sizes. Lengths: 7 and 12

    The abs=0.1 tolerance is a red herring here — the context-attribution output contains no float fields (all int, str, or None). 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. The explode transformation 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):

    (You may get slightly different orderings of context sentences, depending on your hardware or environment.)

    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_check path:

    if "requirement_check" in cfg.short_name:
        # existing path...
        t_json = t_json["requirement_check"]
        e_json = e_json["requirement_check"]
    
    elif cfg.short_name == "context_attribution":
        # Context attribution produces non-deterministic ordering and count
        # of attribution records (HF README explicitly warns about this).
        # Check that expected attributions are covered by actual attributions
        # rather than asserting exact equality.
        import collections
        _key = lambda rec: (rec["response_begin"], rec["response_end"],
                            rec["attribution_begin"], rec["attribution_end"])
        expected_keys = {_key(r) for r in e_json}
        actual_keys = {_key(r) for r in t_json}
        missing = expected_keys - actual_keys
        if missing:
            raise AssertionError(
                f"context-attribution missing {len(missing)} expected records: {missing}"
            )
        continue

    The continue skips the pytest.approx at line 830 for this test case.

  4. planetf1 commented on Jun 18, 2026

    @planetf1
    ContributorAuthor

    test_groundedness_e2e_string_documents — Parser bug in production code, not GPU non-determinism

    ⚠️ Major revision of prior comment. Deep per-stage debug reveals a completely different root cause.

    Per-stage debug (10 runs, capturing raw LLM output + parser behavior)

    Stage 1 (citations intrinsic adapter): 10/10 stable. Always outputs exactly 1 citation r[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-691 only looks at the flat path:

    support_level_raw = (judgment.get("support_level") or "").upper().strip()

    When the nested format appears, judgment.get("support_level") returns None → support_level_raw = "" → falls through to else: "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 of GroundednessRequirement gets 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:

    # Handle both flat and nested support_level
    support_level_raw = (judgment.get("support_level") or "").upper().strip()
    if not support_level_raw:
        # Try nested format: {"span_id": 0, "citations": [{"support_level": "..."}]}
        for cit in judgment.get("citations", []):
            if isinstance(cit, dict):
                support_level_raw = (cit.get("support_level") or "").upper().strip()
                break

    2. Improve prompt clarity (rag.py:598-606) by adding explicit flat output example:

    "Example output (flat format, no nested arrays):\n"
    '[{"span_id": 0, "support_level": "FULLY_SUPPORTED"}, ...]\n\n'

    3. After fix: The test assertion assert result.as_bool() is True should 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.py to prevent regression.

  5. planetf1 commented on Jun 18, 2026

    @planetf1
    ContributorAuthor

    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)

    Model Parser version JSON format Result
    granite-4.0-micro (old) Unfixed 70% nested, 30% flat 5/10 pass
    granite-4.0-micro (new) Fixed 100% flat 10/10 pass ✅
    granite-4.1-3b Unfixed 100% flat 10/10 pass ✅
    granite-4.1-3b Fixed 100% flat 10/10 pass ✅

    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 judgment

    Performance impact

    • Each LLM call takes ~12s with granite-4.0-micro
    • Full groundedness check makes 2 LLM calls = ~24s total
    • Parser fix adds negligible overhead (no additional LLM calls)
  6. planetf1 commented on Jun 18, 2026

    @planetf1
    ContributorAuthor

    Testing methodology summary

    HPC environment

    • Cluster: BLUEVELA_LSF, login3
    • GPU: NVIDIA GPU, PyTorch 2.11.0+cu130
    • Model: ibm-granite/granite-4.0-micro (default), ibm-granite/granite-4.1-3b (comparison)

    granite-4.0-micro e2e (with parser fix) — 10/10 pass ✅

    Job ID Duration Runs Notes
    1204595 2950s (49 min) 10 e2e pytest cold start per run
    1205222 232s (4 min) 10 Deep debug (model loaded once)

    Per-run (warm model): ~12-18s (2 LLM-as-judge calls: necessity + support assessment)

    granite-4.1-3b vs old parser — 10/10 pass ✅

    Job ID Duration Runs Notes
    1206257 203s (3 min) 10 Deep debug (model loaded once)

    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 ✅

    Job ID Duration Runs Notes
    1205222 232s (4 min) 10 Deep debug (model loaded once)

    Test methodology

    1. Deep debug script: Loads model once, runs N iterations. Best for measuring per-iteration timing.
    2. e2e pytest loop: Runs pytest separately each time (cold start model each run). Matches CI behavior.
    3. Model comparison: Uses deep debug script with both models for fair comparison.

    All tests run on HPC via LSF bsub with:

    • gpu "num=1/task:mode=exclusive_process:mps=yes"
    • Queue: normal, Resource usage: 16000MB+

    Code changes summary

    File Change Purpose
    mellea/stdlib/requirements/rag.py Parser handles nested support_level in citations[] Fix: model mirrors input structure
    mellea/stdlib/requirements/rag.py Prompt adds explicit flat-format example Prevention: reduce format confusion
    test/.../test_groundedness_requirement.py Unit test for nested format Verify parser handles both formats
    test/.../test_intrinsics_formatters.py requirement_check: check binary direction only Fix: logprob scores are GPU-non-deterministic
    test/.../test_intrinsics_formatters.py context-attribution: subset check Fix: HF README warns about ordering/count variance

    LLM-as-judge locations

    Only GroundednessRequirement uses LLM-as-judge:

    • _identify_citation_necessity (rag.py:285) — 1 LLM call
    • _assess_citation_support (rag.py:385) — 1 LLM call
    • Total per groundedness check: ~24s (2 calls × ~12s each)
  7. planetf1 commented on Jun 18, 2026

    @planetf1
    ContributorAuthor

    PR Created

    Draft PR: #1292

    Status:

    • Parser fix: committed (ca5963e)
    • Formatters test fix: committed
    • HPC verification: running (job 1212156, ~12min estimate)
    • Next: Wait for HPC results, then remove draft status
  8. planetf1 commented on Jun 18, 2026

    @planetf1
    ContributorAuthor

    HPC verification passed:

    1. Parser unit tests: 5/5 PASSED
    2. e2e groundedness 10x: 10/10 PASSED (previously 5/10 with old parser)
    3. Formatters tests: requirement_check_alora + context-attribution: 2/2 PASSED

    Draft PR #1292 created. Ready for review.

  9. self-assigned this
    on Jun 18, 2026
  10. planetf1 commented on Jun 19, 2026

    @planetf1
    ContributorAuthor

    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)

    Test Result Notes
    answerability_* (4) ✅ PASS
    hallucination_detection ⚠️ XFAIL Transformers 5.0 incompatibility (known)
    query_clarification, query_rewrite ✅ PASS
    context_relevance (non-alora) ✅ PASS Bare continue in PR = no real assertion
    context_relevance_alora ❌ FAILED JSONDecodeError - model truncated output: "{ context_relevance: relevant, response: As of my last update"
    citations ✅ PASS
    context-attribution ✅ PASS Subset check works
    requirement_check (non-alora) ✅ PASS
    requirement_check_alora ✅ PASS Direction check (>=0.5) works
    uncertainty (non-alora) ✅ PASS
    uncertainty_alora ❌ FAILED Log-prob flip: 0.83 → 0.06, direction check insufficient on this hardware/run

    Two new failures need fixing:

    1. context_relevance_alora: Generation truncation causing JSON parse error (max_new_tokens not set)
    2. 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 Result Notes
    test_certainty ✅ PASS
    test_requirement_check ✅ PASS
    test_find_context_attributions ⚠️ XFAIL Existing marker strict=False
    test_find_context_attributions_resolve ⚠️ XFAIL Existing marker strict=False
    test_certainty_with_tools ✅ PASS

    xfails 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_documents

    Test 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:

    1. test_run_transformers[context_relevance_alora] - Generation truncation (set max_new_tokens)
    2. test_run_transformers[uncertainty_alora] - Log-prob non-determinism worse than expected

    2 xfails to investigate:

    1. test_find_context_attributions - Context-attribution count may vary beyond [:7] prefix
    2. test_find_context_attributions_resolve - Same issue
  11. planetf1 commented on Jun 19, 2026

    @planetf1
    ContributorAuthor

    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 is test_groundedness_requirement_documents_in_message. Running it separately now (job 1280169).

  12. added
    area/adapter-functions
    on Jun 19, 2026
  13. planetf1 commented on Jun 19, 2026

    @planetf1
    ContributorAuthor

    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.

  14. added
    bug
    on Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/adapter-functionsbugp2testing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions