[WIP] Lazy projection#43
Draft
PierreGtch wants to merge 2 commits into
Draft
Conversation
Lazy nn.Module mirroring sklearn's GaussianRandomProjection: the input dimension is inferred from the first forward (like LazyLinear) and the non-trainable projection matrix is materialized into a persistent buffer. Reuses _make_projection_matrix for bit-identical sklearn scaling and widens its type hints (seed: int | None, device: str | torch.device) to match the new call site.
Add a `max_features: int | None = 5000` field to LinearHead, MLPHead and FlattenHead (not OriginalHead): when set, apply() inserts a LazyGaussianRandomProjection right after nn.Flatten(1), capping the flattened feature dimension. head.apply() gains a `seed` argument and Experiment passes its seed so the projection is reproducible from Experiment.seed. LazyGaussianRandomProjection now does an identity passthrough when the input already has <= n_components features (replacing the warn-and-expand behavior), matching the ridge probe's old "skip when D <= max_features". The streaming ridge probe loses all projection responsibility: max_features / projection_seed parameters, the 'projection' result key and the predict-time re-projection are gone, and _make_projection_matrix now lives in head_utils. RidgeProbingTraining drops its max_features field accordingly. Also fix _initialize_lazy_modules to materialize lazy buffers (not just lazy parameters), so a FlattenHead projection with no trailing LazyLinear is initialized by the dummy forward.
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.
No description provided.