Skip to content

Perf, reproducibility, test suite + CI, packaging - #1

Merged
Micka420-collab merged 1 commit into
mainfrom
claude/session-1ukuxh
Jul 21, 2026
Merged

Perf, reproducibility, test suite + CI, packaging#1
Micka420-collab merged 1 commit into
mainfrom
claude/session-1ukuxh

Conversation

@Micka420-collab

Copy link
Copy Markdown
Owner

What

A round of measured, low-risk improvements across the codebase:

Performance

  • text_features.py — memoize per-token vectors in HashingTextFeaturizer. The sha256 + RNG expansion was recomputed for every token occurrence; embed_batch over 5 000 state descriptions goes from 0.93 s → 0.10 s (×9.3) with bit-identical output.
  • controller.py — cache subgoal text → target latent in MPCController, so the same goal isn't re-embedded and re-projected through from_lang at every step of an episode.
  • llm/planner.py — memoize the LLM goal classification per instruction (temperature 0 ⇒ deterministic). In openrouter mode this turns one API call per env step into one per goal; transient failures are deliberately not cached so a later step can retry.

Reproducibility / correctness

  • evaluate.py_alignment_cosine sampled actions from the global np.random state, making the reported metric depend on whatever ran before evaluate(). It now uses a dedicated seeded RNG (cfg.seed + 30_000, disjoint from the train/eval/probe seed bases). Determinism is covered by a test.
  • checkpoint.pytorch.load(..., weights_only=True): checkpoints only contain tensors and plain YAML-derived config types, so the unsafe pickle path is unnecessary.

Tests + CI (fits the repo's "measure-don't-guess" contract)

  • tests/ — 31 fast tests (~4 s CPU): env contracts + per-seed determinism + termination for all 5 built-in envs, model shapes/gradients, featurizer determinism, end-to-end train → evaluate smoke for both the feedforward and rssm world models, checkpoint round-trip (verifies the weights_only=True change), controller cache behavior, and baseline (random / LLM-only / PPO / DQN) smoke tests.
  • .github/workflows/ci.yml — runs the suite on push/PR with CPU torch.

Packaging

  • pyproject.toml — the package is now installable (pip install -e ".[dev]"), with optional extras llm (OpenRouter planner) and minigrid; .gitignore gains *.egg-info/.
  • README: CI badge + test instructions in the quick start.

Verification

  • pytest -q31 passed in 3.4 s (local, CPU).
  • End-to-end smoke: python -m latentbridge.experiment (tiny override) trains, evaluates, and saves/loads the checkpoint through the new weights_only=True path.
  • Featurizer micro-benchmark confirms ×9.3 speedup with np.array_equal(old, new) == True.

No behavior or metric definitions change — outputs are identical, just faster and deterministic.

🤖 Generated with Claude Code

https://claude.ai/code/session_018FBEJut651qfyEWR5A3shP


Generated by Claude Code

- text_features: memoize per-token vectors (x9 faster embed_batch, identical output)
- controller: cache subgoal text -> target latent (no re-embed/from_lang per step)
- planner: memoize LLM goal classification per instruction (one API call per goal
  instead of one per env step in openrouter mode; failures are not cached)
- evaluate: _alignment_cosine uses a dedicated seeded RNG instead of global
  np.random, making the metric independent of call order
- checkpoint: torch.load(weights_only=True) — checkpoints are tensors + plain
  config types, no need for unsafe pickle loading
- tests/: 31 fast tests (env contracts + determinism, model shapes/grads,
  end-to-end train->evaluate smoke incl. rssm, checkpoint round-trip, baselines)
- .github/workflows/ci.yml: run the suite on push/PR (CPU torch)
- pyproject.toml: installable package (pip install -e ".[dev]"), optional extras
  for llm/minigrid deps

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018FBEJut651qfyEWR5A3shP
@Micka420-collab
Micka420-collab merged commit 0667630 into main Jul 21, 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.

2 participants