Skip to content

FIX Run IncrementalPCA, and thus EVA initialization, on MPS - #4045

Closed
Alex-Wengg wants to merge 1 commit into
huggingface:mainfrom
Alex-Wengg:fix/incremental-pca-mps
Closed

Alex-Wengg wants to merge 1 commit into
huggingface:mainfrom
Alex-Wengg:fix/incremental-pca-mps

Conversation

@Alex-Wengg

Copy link
Copy Markdown
Contributor

Fixes #4043.

IncrementalPCA accumulated its running statistics in float64 on the input's device, which fails on MPS because MPS has no float64. That broke LoRA's EVA initialization on MPS. This adds a small _accumulation_dtype helper that returns float32 on MPS and float64 everywhere else, so CPU and CUDA behavior is unchanged.

Added test_incremental_pca_on_mps_matches_cpu, which only runs on MPS and compares the fitted components and the projection with CPU. It fails on main with the float64 TypeError and passes with this change. test_incremental_pca.py passes, and the EVA tests in test_gpu_examples.py now pass on MPS (they're slow there, since torch.svd_lowrank falls back to CPU for these sizes).

IncrementalPCA accumulated its running statistics in float64 on the
input's device. MPS has no float64, so EVA initialization failed there.
Accumulate in float32 on MPS and keep float64 everywhere else.
@github-actions

Copy link
Copy Markdown

Thank you for your interest in contributing to PEFT. This PR is being closed because its description does not reference an accepted PEFT discussion or an open PEFT issue with explicit approval from a maintainer or public Hugging Face organization member that applies to this PR's author.

Please open or find an issue, discuss the proposed contribution, and wait for an authorized person to comment /peft-triage approved before opening a PR. To limit approval to one contributor, the commenter can add that person's username after approved. Once approved, reference it in this PR's description (for example, Fixes #123) and reopen the PR; there is no need to create another PR.

If you believe this PR was closed incorrectly, please ping the maintainers here.

See the contribution guidelines.

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.

EVA initialization fails on MPS: IncrementalPCA accumulates in float64

1 participant