Skip to content

[WIP] Lazy projection#43

Draft
PierreGtch wants to merge 2 commits into
mainfrom
lazy-projection
Draft

[WIP] Lazy projection#43
PierreGtch wants to merge 2 commits into
mainfrom
lazy-projection

Conversation

@PierreGtch

Copy link
Copy Markdown
Contributor

No description provided.

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.
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.

1 participant