Perf, reproducibility, test suite + CI, packaging - #1
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A round of measured, low-risk improvements across the codebase:
Performance
text_features.py— memoize per-token vectors inHashingTextFeaturizer. The sha256 + RNG expansion was recomputed for every token occurrence;embed_batchover 5 000 state descriptions goes from 0.93 s → 0.10 s (×9.3) with bit-identical output.controller.py— cachesubgoal text → target latentinMPCController, so the same goal isn't re-embedded and re-projected throughfrom_langat every step of an episode.llm/planner.py— memoize the LLM goal classification per instruction (temperature 0 ⇒ deterministic). Inopenroutermode 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_cosinesampled actions from the globalnp.randomstate, making the reported metric depend on whatever ran beforeevaluate(). 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.py—torch.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-endtrain → evaluatesmoke for both the feedforward andrssmworld models, checkpoint round-trip (verifies theweights_only=Truechange), 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 extrasllm(OpenRouter planner) andminigrid;.gitignoregains*.egg-info/.Verification
pytest -q→ 31 passed in 3.4 s (local, CPU).python -m latentbridge.experiment(tiny override) trains, evaluates, and saves/loads the checkpoint through the newweights_only=Truepath.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