Conversation
Three additions to `FCLayers`, all independent of any particular model: - `residual`: optionally add a skip connection around each hidden block whose input and output share a width. Block 0 changes width and is always excluded, so the flag needs `n_layers >= 2` to have any effect. - `forward(**kwargs)`: extra per-call context is threaded to the `_apply_layer` / `_apply_batch_norm` hooks so subclasses can branch on it. The base layers ignore it. - `_build_cov_list`: extract the continuous + one-hot categorical covariate assembly out of `forward` into an overridable method. Covered by tests in `tests/nn/test_fclayers.py`, including the two residual guards (`i > 0` and the shape match), kwargs reaching both hooks, and the covariate-list seam being the source `forward` actually uses. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The `residual` docstring and release note said "each hidden block", but the last block gets a skip too when `n_hidden == n_out`, and the first block is excluded by the `i > 0` guard whether or not it changes width. Reword both to "every block except the first, whenever its input and output widths match". `SplitFCLayers` is the only `FCLayers` subclass in the repo and overrides `_apply_layer` / `_apply_batch_norm`, so give those `**kwargs` as well; otherwise passing per-call context through a `SplitFCLayers` raises TypeError. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Pruning the added tests truncated the file two lines early and took the tail of `test_gradient_hook_preserves_categorical_grad_only` with it, so the test no longer checked that the categorical columns keep a non-zero gradient. The file is now byte-identical to main up to the tests this branch appends. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The covariate assembly moves back inline into `FCLayers.forward`: nothing overrides or calls `_build_cov_list`, in scvi-tools or downstream, so the seam was speculative. `residual` and the `**kwargs` threading stay -- both have real subclass users. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4019 +/- ##
=======================================
Coverage 89.46% 89.46%
=======================================
Files 247 247
Lines 24389 24393 +4
=======================================
+ Hits 21820 21824 +4
Misses 2569 2569
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Dear scvi-tools team,
I am making this PR to add two small, backwards-compatible extensions to
FCLayers. This allows easier extension of DRVI code without requiring to reimplement/repeat big chunks of code. Both are off/unused by default, so existing callers are unaffected.residualoption. Wraps every block except the first in a skip connection, whenever that block's input and output widths match. The first block is always excluded, so the flag needsn_layers >= 2to do anything.forward(**kwargs). Extra per-call context is threaded to the_apply_layerand_apply_batch_normhooks. The base layers ignore unknown keywords; a subclass can branch on them (e.g. to change behavior between encode/decode calls without a separate code path).SplitFCLayers(scvi.external.drvi), the oneFCLayerssubclass in the repo, picks up**kwargson its own_apply_layer/_apply_batch_normoverrides so it isn't broken by the new signature.Testing
tests/nn/test_fclayers.pyadds a residual test that checks the full forward against a hand-built reference with skip connections on same-width blocks only.