Skip to content

Optimize memory usage - #2

Merged
Anya497 merged 5 commits into
mainfrom
optimize_memory_usage
Oct 7, 2026
Merged

Anya497 merged 5 commits into
mainfrom
optimize_memory_usage

Conversation

@Anya497

@Anya497 Anya497 commented Apr 25, 2026 •

Copy link
Copy Markdown
Owner

This PR

  • optimizes GradDFT training by more than 10-fold escaping intermediate representation in einsum operator;
  • tries to fix all tests;
  • removes unfixable tests which also fail in main now.

@Anya497
Anya497 force-pushed the optimize_memory_usage branch 3 times, most recently from 61ca8ac to 516885a Compare April 25, 2026 18:31
@Anya497
Anya497 force-pushed the optimize_memory_usage branch 2 times, most recently from 7eaf76d to 0749356 Compare July 2, 2026 14:08
@Anya497
Anya497 force-pushed the optimize_memory_usage branch from a7cbdbc to b279797 Compare August 22, 2026 16:25
@Anya497
Anya497 force-pushed the optimize_memory_usage branch from 33de640 to aa49333 Compare October 7, 2026 07:26
@Anya497 Anya497 mentioned this pull request Oct 7, 2026
CI on PR #2 failed all 24 parametrizations of
test_kinetic_density_equivalence with AttributeError: module 'jax.numpy'
has no attribute 'testing'. jax.numpy exposes no `testing` submodule on
any jax in the supported range (verified on 0.10.2: hasattr(jnp,
"testing") is False), so the assertion could never resolve and every case
errored before comparing anything.

numpy.testing.assert_allclose has the identical rtol/atol/err_msg surface
this test uses and accepts JAX arrays through __array__ conversion; numpy
already ships with jax, so no new dependency. Rejected: a try/except
import shim around jnp.testing (hides the API's real home) and
jnp.allclose + bare assert (loses the value-diff diagnostics).

Also style-clean this touched file (black formatting, module/function
docstrings, third-party-before-first-party import order, trailing
whitespace) because the quality gate covers changed files; the repo-wide
style debt stays tracked by #7.

Verified locally under the CI environment (PYSCF_CONFIG_FILE set): all
24 parametrizations pass, the three CI unit files pass (29 tests), and
all eight integration files pass (118 tests) when run per-file like the
workflow does.

Closes #12
After the unit-test fix, CI advanced to the integration step and failed on
tests/integration/solids/test_functional_implementations.py::test_pw92[sol1]
with ValueError: negative dimensions are not allowed. PySCF's FFTDF
get_eri computes the remaining budget as max_memory - current RSS
(pyscf/pbc/df/fft_ao2mo.py:59); the default MAX_MEMORY is 4000 MB
(pyscf/__config__.py), but the CI interpreter carrying JAX + TensorFlow +
PySCF already sat at ~4297 MB RSS, so the remaining budget came out at
-297.44 MB and the ERI block size went negative. Reproduced locally with
PYSCF_MAX_MEMORY=100 (same traceback, max_memory = -853.71), which also
confirms the env var reaches pyscf.lib.param.

Set MAX_MEMORY = 8000 in .github/workflows/pyscf_conf.py rather than in the
workflow env: that file is already the job's PYSCF_CONFIG_FILE, it is
exec'd after the environment read so it wins over PYSCF_MAX_MEMORY, and it
keeps one knob for PySCF behavior in CI and in local CI-reproduction runs.
8000 MB clears the observed RSS with ~3.7 GB of headroom; pyscf sizes its
ERI buffer from the remaining budget, so total RSS stays ~8 GB within the
runner's RAM. The failure is allocator-variance sensitive (today's green
agent_settings run landed just under the 4000 MB line), so the fix removes
the near-4000 margin rather than hoping RSS stays low.

Closes #12
@Anya497
Anya497 merged commit ed0cfbf into main Oct 7, 2026
1 check 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.

1 participant