Skip to content

fix: skip _compute_latent_samples in PYAUTO_TEST_MODE #1294

Description

@Jammy2211

Overview

After the latent refactor series shipped (z_features/complete/latent_refactor.md), the autolens SLaM smoke test times out at the 5-minute mark inside the first SLaM stage's post-fit latent processing. Root cause: PyAutoFit:autofit/non_linear/search/updater.py:226 (_compute_latent_samples) ignores PYAUTO_TEST_MODE. It always draws output.latent_draw_via_pdf_size samples (default 100) and runs analysis.compute_latent_samples(...) on each — and PyAutoGalaxy's AnalysisDataset.LATENT_BATCH_MODE = "jit" override means that's a Python loop of per-sample JIT dispatches because the einstein-radius latent's ZeroSolver isn't vmap-compatible.

Test mode by definition mocks the fit, so the latent values are never asserted on — short-circuiting _compute_latent_samples in test mode unblocks smoke testing immediately with no behavioural change to real runs.

Plan

  • Add a skip_latents() helper in PyAutoConf:autoconf/test_mode.py (alongside existing skip_visualization(), skip_checks() etc) that composes is_test_mode() OR PYAUTO_SKIP_LATENTS=1.
  • In PyAutoFit:autofit/non_linear/search/updater.py, short-circuit _compute_latent_samples to return None when skip_latents() is true.
  • Add unit test covering both the test-mode trigger and the explicit PYAUTO_SKIP_LATENTS=1 trigger.
  • Validate against the previously-timing-out SLaM smoke command.
Detailed implementation plan

Affected Repositories

  • rhayes777/PyAutoFit (primary — updater.py short-circuit)
  • rhayes777/PyAutoConf (test_mode.py adds skip_latents() helper)

Work Classification

Library.

Branch Survey

Repository Current Branch Dirty?
./PyAutoFit main clean
./PyAutoConf main clean

Suggested branch: feature/test-mode-skip-latents
Worktree root: ~/Code/PyAutoLabs-wt/test-mode-skip-latents/ (created later by /start_library)

Implementation Steps

  1. PyAutoConf — add skip_latents() to autoconf/test_mode.py:

    def skip_latents():
        """Return True if latent variable computation should be skipped."""
        return is_test_mode() or os.environ.get("PYAUTO_SKIP_LATENTS", "0") == "1"

    Place after skip_checks() to match the file's existing layout.

  2. PyAutoFit — short-circuit _compute_latent_samples in autofit/non_linear/search/updater.py:226:

    def _compute_latent_samples(self, ...):
        """Compute and persist latent variable samples if configured."""
        from autoconf.test_mode import skip_latents
        if skip_latents():
            return None
        if not ((during_analysis and conf.instance["output"]["latent_during_fit"])
                or (not during_analysis and conf.instance["output"]["latent_after_fit"])):
            return
        ...

    _profile_and_summarize (line 117 callsite) already accepts latent_samples=None, so no downstream changes.

  3. PyAutoFit unit test in test_autofit/non_linear/search/ (confirm test layout first; if no test_updater.py exists, add one or use the appropriate adjacent file). Three cases:

    • With PYAUTO_TEST_MODE=1 set → _compute_latent_samples returns None without invoking analysis.compute_latent_samples.
    • With PYAUTO_SKIP_LATENTS=1 set (test mode off) → same behaviour.
    • Default (both unset) → existing path still runs (mock analysis.compute_latent_samples to return a sentinel; assert it's called).

    No JAX in the unit test.

  4. Validate with the SLaM smoke command that previously timed out:

    PYAUTO_TEST_MODE=2 PYAUTO_SKIP_FIT_OUTPUT=1 PYAUTO_SKIP_VISUALIZATION=1 \
    PYAUTO_SKIP_CHECKS=1 PYAUTO_SMALL_DATASETS=1 PYAUTO_FAST_PLOTS=1 \
    python scripts/imaging/features/advanced/slam/start_here.py

    Should complete in seconds. Then a no-PYAUTO_TEST_MODE real-mode fit to confirm latent.csv still produced as before.

Key Files

  • PyAutoConf/autoconf/test_mode.py — add skip_latents() helper
  • PyAutoFit/autofit/non_linear/search/updater.py:226 (_compute_latent_samples) — short-circuit
  • PyAutoFit/test_autofit/non_linear/search/ (test layout TBD) — unit test

Out of Scope

  • Per-latent LATENT_BATCH_MODE (so fast latents vmap while einstein-radius stays jit-per-sample). That's the real-mode SLaM perf fix and lives in a separate follow-up at PyAutoPrompt/autogalaxy/latent_batch_mode_per_latent.md (TBA). This issue only unblocks smoke testing.
  • No new workspace CLAUDE.md documentation: the existing fast-smoke env set covers test mode; PYAUTO_SKIP_LATENTS=1 is for power users and is discoverable via autoconf/test_mode.py.

Original Prompt

Click to expand starting prompt

Located at PyAutoPrompt/issued/test_mode_skip_latents.md after routing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions