Skip to content

test_run_transformers fails on MPS due to CUDA-specific golden files; resource predicates missing #1342

Closed

Description

@planetf1

Background

test/formatters/granite/test_intrinsics_formatters.py::test_run_transformers is parametrised over the full set of intrinsic adapter formatter combos. Three cases originally failed on Apple Silicon (MPS) machines:

  • context-attribution
  • context_relevance_alora
  • uncertainty_alora

Current state (updated Aug 2026)

context_relevance_alora is now handled — the test skips it with a deprecation note (context_relevance adapter deprecated (Granite 4.0 only, not maintained)). Hard removal tracked in #1338.

Two cases remain:

  • context-attribution — active adapter, golden-file divergence on MPS
  • uncertainty_alora — active adapter, golden-file divergence on MPS

What's happening

load_transformers_lora already selects the best available device (CUDA → MPS → CPU), so the tests do run on MPS. They fail at the golden-file assertion step because MPS and CUDA produce different floating-point results — e.g. context-attribution produces 7 attribution spans on MPS vs 12 in the expected file, which was generated on CUDA hardware. The comparison tolerance (abs=0.1) is not the issue; the output structures themselves differ.

This is not a missing hardware path — it's that the expected output files encode CUDA-specific inference results.

Related gap: resource predicate

test_run_transformers has no resource predicate. The comment # THIS TEST DOES NOT REQUIRE A GPU is accurate for the transformer loading path, but gives no guidance on MPS/CUDA divergence. There is no require_gpu, no MPS-specific xfail, and no skip guard — so developers on Apple Silicon get a hard failure with no explanation.

Options considered

A. Regenerate golden files per device — produces MPS-specific and CUDA-specific expected files. Correct but adds maintenance burden; needs a mechanism to select the right file at test time.

B. MPS xfail (like the existing Transformers 5.0 xfail) — add if torch.backends.mps.is_available(): pytest.xfail("MPS/CUDA floating-point divergence produces different span counts") inside the assertion block. Low effort, honest, and unblocks MPS developers in the short term.

C. Structural assertion instead of golden-file comparison — on non-CUDA devices, validate that the output is parseable, keys are present, and scores are in range, without checking exact values. Requires more test refactoring.

D. require_gpu() with CUDA-only flag — skip on MPS entirely. require_gpu currently has no cuda_only parameter; it would need extending. This gives up on MPS support rather than fixing it.

The project intent (device selection already includes MPS) points toward A or C as the long-term answer, with B as an interim measure.

Activity

  1. added
    area/backends
    p2
    bug
    on Aug 10, 2026
  2. planetf1 commented on Oct 5, 2026

    @planetf1
    ContributorAuthor

    Fixed.

    Verified against upstream/main (2026-10-05). The two remaining cases no longer compare device-specific golden values (test/formatters/granite/test_intrinsics_formatters.py):

    • uncertainty_alora — asserts the coarse direction bucket (>= 0.5), which is what check_certainty's pass/fail boundary actually depends on; exact floats differ per GPU
    • context-attribution — asserts the expected records are a subset of the actual output (extra records tolerated, matching the HF README's non-determinism warning)

    Both carry the #1291 analysis in their comments, and the remaining adapters keep the abs=0.1 approx fallback. This is option C (structural assertion) generalised — a strict superset of the MPS-xfail in option B, so it holds on CUDA too.

    On the related resource-predicate gap: resolved by decision in the test header — the test does not require a GPU and should not be marked @require_gpu, so the divergence guard is the structural assertion itself rather than a skip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/backendsbugp2testing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions