Fix ps_decoder2 input width when pert_dim is None; add regression test and CI - #51
Merged
Conversation
PSDecoder for the lochNESS-next head was built with geneinput=0 whenever pert_dim was not given, giving a first layer of Linear(d_model, d_model). The perturbation encoder defaults pert_dim to d_model in that case, so the concatenated [cell_emb_orig, pert_emb_next] input is 2*d_model wide and the first forward pass fails with "mat1 and mat2 shapes cannot be multiplied (128x64 and 32x32)". Reuse the local pert_dim already computed for the encoder so the decoder's input width always matches the encoder's output width. Fixes #50 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G9KDzjgXDQg5zs9uVybiuR
Builds PerturbationTFModel with pred_lochness_next=True and no pert_dim, mirroring notebook/train_pertTF_with__lochNESS.ipynb, and checks that ps_decoder2's first layer accepts 2 * d_model and that a forward pass with pert_labels_next succeeds. Both tests fail on main with "mat1 and mat2 shapes cannot be multiplied" and pass with the fix. Run with: python -m pytest tests/ Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G9KDzjgXDQg5zs9uVybiuR
Installs CPU-only torch from the PyTorch wheel index, then the package with a new [test] extra (pytest, torch>=2.2, tqdm), and runs pytest on Python 3.10 and 3.12. torch>=2.2 is required for torch.nn.attention. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G9KDzjgXDQg5zs9uVybiuR
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Fixes #50
Problem
Training with
pred_lochness_next=True(e.g.notebook/train_pertTF_with__lochNESS.ipynb) crashes in the first forward pass:ps_decoder2was built withgeneinput=0wheneverpert_dimwas not given, so its first layer wasLinear(d_model, d_model). The perturbation encoder defaultspert_dimtod_modelin that case, so the concatenated[cell_emb_orig, pert_emb_next]input is2 * d_modelwide.Changes
perttf/model/pertTF.py): buildps_decoder2with the same localpert_dimthe encoder uses, so decoder input width always matches encoder output width. One line.tests/test_pertTF_model.py): buildsPerturbationTFModelwith the notebook's arguments and checks the decoder width and a full forward pass. Both tests fail onmainwith the error above and pass with the fix..github/workflows/ci.yml,pyproject.toml): GitHub Actions runspyteston every push and PR, Python 3.10 and 3.12, CPU-only torch. Adds a[test]extra. First run on this branch: https://github.com/davidliwei/pertTF/actions/runs/33589260892 (both jobs green, ~75 s each).Not addressed
An explicit
pert_dim != d_modelstill fails atpertTF.py:156when perturbation labels are fed into the transformer input. Pre-existing and independent; noted in #50.🤖 Generated with Claude Code