Skip to content

Fix 2 retry pipeline bugs on GPU#73

Merged
awvwgk merged 2 commits into
microsoft:mainfrom
tvogels:fix_gpu_retries
May 18, 2026
Merged

Fix 2 retry pipeline bugs on GPU#73
awvwgk merged 2 commits into
microsoft:mainfrom
tvogels:fix_gpu_retries

Conversation

@tvogels
Copy link
Copy Markdown
Collaborator

@tvogels tvogels commented May 18, 2026

The retry path in src/skala/pyscf/retry.py contained two gpu4pyscf incompatibilities that together caused single-point calculations to fail on GPU but succeed on CPU for systems whose first SCF call did not converge.

  1. SCFState.post_cycle_callback asserted isinstance(envs["norm_ddm"], (float, int)) but gpu4pyscf stores norm_ddm as a 0-d cupy.ndarray, so the assertion fires on the first GPU SCF cycle. This PR always converts to float to make gpu4pyscf and pyscf compatible.

  2. increment_level_shift did if level_shift > 0. CPU pyscf defaults SCF.level_shift to 0, gpu4pyscf defaults it to None, so the comparison raises TypeError on the GPU retry path. This PR treats None and 0 identically as "no level shift yet" and start from level_shift_init.

The retry path in src/skala/pyscf/retry.py contained two
gpu4pyscf-incompatibilities that together caused single-point
calculations to fail on GPU but succeed on CPU for systems whose first
SCF call did not converge (see msr-ai4science/feynman#21391):

1. SCFState.post_cycle_callback asserted
       isinstance(envs["norm_ddm"], (float, int))
   but gpu4pyscf stores norm_ddm as a 0-d cupy.ndarray, so the assertion
   fires on the first GPU SCF cycle. Coerce to a Python float instead so
   downstream consumers see a uniform numeric type on both backends.

2. increment_level_shift did `if level_shift > 0`. CPU pyscf defaults
   SCF.level_shift to 0, gpu4pyscf defaults it to None, so the
   comparison raises TypeError on the GPU retry path. Treat None and 0
   identically as "no level shift yet" and start from level_shift_init.

Verified by reproducing the original failure on all 8 GPU-failing
structures from feynman#21391 (CCoN, H2FeO2, H2Cl2Fe, CH3Cl, CH3Br,
C3H3IN2, H10N2O2Pt, C2H6O2Pd) and confirming they now succeed with
with_retry=True on cuda. Existing test_scf_retry.py still passes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tvogels tvogels requested a review from awvwgk May 18, 2026 13:40
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@awvwgk awvwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing

@awvwgk
Copy link
Copy Markdown
Member

awvwgk commented May 18, 2026

Felix @pultar, you found a similar issue, so this should also fix the problem you observed.

@awvwgk awvwgk merged commit 7916d9f into microsoft:main May 18, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants