{"id":42056165,"url":"https://github.com/ndgigliotti/torch-ipca","last_synced_at":"2026-01-26T07:13:51.341Z","repository":{"id":334158404,"uuid":"1140273508","full_name":"ndgigliotti/torch-ipca","owner":"ndgigliotti","description":"GPU-accelerated Incremental PCA for PyTorch","archived":false,"fork":false,"pushed_at":"2026-01-23T20:16:58.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-23T22:21:40.496Z","etag":null,"topics":["cuda","dimensionality-reduction","gpu","incremental-pca","machine-learning","pca","pytorch"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ndgigliotti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":"NOTICE","maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-23T03:47:08.000Z","updated_at":"2026-01-23T04:55:26.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ndgigliotti/torch-ipca","commit_stats":null,"previous_names":["ndgigliotti/torch-ipca"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ndgigliotti/torch-ipca","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndgigliotti%2Ftorch-ipca","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndgigliotti%2Ftorch-ipca/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndgigliotti%2Ftorch-ipca/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndgigliotti%2Ftorch-ipca/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndgigliotti","download_url":"https://codeload.github.com/ndgigliotti/torch-ipca/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndgigliotti%2Ftorch-ipca/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28769507,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T06:37:25.426Z","status":"ssl_error","status_checked_at":"2026-01-26T06:37:23.039Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cuda","dimensionality-reduction","gpu","incremental-pca","machine-learning","pca","pytorch"],"created_at":"2026-01-26T07:13:50.709Z","updated_at":"2026-01-26T07:13:51.334Z","avatar_url":"https://github.com/ndgigliotti.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# torch-ipca\n\nGPU-accelerated Incremental PCA for PyTorch.\n\nA PyTorch implementation of Incremental PCA adapted from scikit-learn, with full GPU support for fitting and transforming large datasets that don't fit in memory.\n\n## Features\n\n- **GPU-accelerated**: All operations run on CUDA when available\n- **Incremental fitting**: Process data in batches with constant memory complexity\n- **scikit-learn compatible API**: Drop-in replacement for `sklearn.decomposition.IncrementalPCA`\n- **Save/load support**: Persist fitted models with `save()` and `load()`\n\n## Installation\n\n```bash\npip install git+https://github.com/ndgigliotti/torch-ipca.git\n```\n\n## Usage\n\n```python\nimport torch\nfrom torch_ipca import IncrementalPCA\n\n# Create some data\nX = torch.randn(10000, 768, device=\"cuda\")\n\n# Fit incrementally\nipca = IncrementalPCA(n_components=128, device=\"cuda\")\nfor batch in X.split(1000):\n    ipca.partial_fit(batch)\n\n# Transform\nX_reduced = ipca.transform(X)  # Shape: (10000, 128)\n```\n\n### Full fit\n\n```python\nipca = IncrementalPCA(n_components=128, device=\"cuda\")\nX_reduced = ipca.fit_transform(X)\n```\n\n### Save and load\n\n```python\n# Save fitted model\nipca.save(\"pca_model.pt\")\n\n# Load later\nipca = IncrementalPCA.load(\"pca_model.pt\", device=\"cuda\")\nX_reduced = ipca.transform(new_data)\n```\n\n## API\n\n### `IncrementalPCA(n_components=None, whiten=False, device=\"cuda\")`\n\n**Parameters:**\n- `n_components`: Number of components to keep. If None, keeps `min(n_samples, n_features)`.\n- `whiten`: If True, whitens the output to have unit variance.\n- `device`: PyTorch device (\"cuda\" or \"cpu\").\n\n**Methods:**\n- `fit(X)`: Fit the model with X using minibatches.\n- `partial_fit(X)`: Incremental fit on a batch X.\n- `transform(X)`: Apply dimensionality reduction to X.\n- `inverse_transform(X)`: Transform reduced data back to original space.\n- `fit_transform(X)`: Fit and transform in one call.\n- `save(path)`: Save fitted model to file.\n- `load(path, device)`: Load fitted model from file (classmethod).\n\n**Attributes (after fitting):**\n- `components_`: Principal axes (n_components, n_features).\n- `explained_variance_`: Variance explained by each component.\n- `explained_variance_ratio_`: Percentage of variance explained.\n- `mean_`: Per-feature mean.\n- `n_samples_seen_`: Number of samples processed.\n\n## When to Use\n\n- **Large datasets**: When data doesn't fit in GPU memory, use `partial_fit()` to process in batches.\n- **Streaming data**: Continuously update PCA as new data arrives.\n- **Non-MRL models**: For embedding models without Matryoshka training, PCA provides dimension reduction.\n\nFor models trained with Matryoshka Representation Learning (nomic-embed, jina-v3, OpenAI v3), simple truncation is preferred over PCA.\n\n## License\n\nApache 2.0. Portions derived from scikit-learn (BSD 3-Clause License).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndgigliotti%2Ftorch-ipca","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndgigliotti%2Ftorch-ipca","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndgigliotti%2Ftorch-ipca/lists"}