File size: 1,539 Bytes
201dc77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""U11-10: --verify-resume-only must exit nonzero when the bitwise resume check FAILED."""
import importlib.util
import os
import types

REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


def _load():
    spec = importlib.util.spec_from_file_location(
        "probe_under_test", os.path.join(REPO, "scripts", "qwen3_sft_probe.py")
    )
    m = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(m)
    return m


def _trainer(verify_passed, stop_exit_code=0):
    t = types.SimpleNamespace(stop_exit_code=stop_exit_code)
    if verify_passed is not None:
        t.verify_passed = verify_passed
    return t


def test_failed_verification_is_nonzero():
    p = _load()
    assert p.final_exit_code(_trainer(False), verify_only=True, any_rank=bool) == 1


def test_missing_verdict_is_a_failure_not_a_pass():
    p = _load()
    assert p.final_exit_code(_trainer(None), verify_only=True, any_rank=bool) == 1


def test_passed_verification_and_normal_run_are_zero():
    p = _load()
    assert p.final_exit_code(_trainer(True), verify_only=True, any_rank=bool) == 0
    assert p.final_exit_code(_trainer(None, stop_exit_code=0), verify_only=False, any_rank=bool) == 0
    assert p.final_exit_code(_trainer(None, stop_exit_code=82), verify_only=False, any_rank=bool) == 82


def test_one_failing_rank_fails_every_rank():
    p = _load()
    # any_rank stands in for the cross-rank MAX: another rank failed.
    assert p.final_exit_code(_trainer(True), verify_only=True, any_rank=lambda local_bad: True) == 1