Skip to content

Remove PyTorch dependencies#2959

Open
adamtheturtle wants to merge 2 commits intomainfrom
adamtheturtle/smaller-torch
Open

Remove PyTorch dependencies#2959
adamtheturtle wants to merge 2 commits intomainfrom
adamtheturtle/smaller-torch

Conversation

@adamtheturtle
Copy link
Member

@adamtheturtle adamtheturtle commented Feb 18, 2026

Summary

Replace PyTorch and torchmetrics with lighter-weight alternatives:

  • Replaced torchmetrics.image.StructuralSimilarityIndexMeasure with skimage.metrics.structural_similarity
  • Replaced piq BRISQUE implementation with brisque package wrapper
  • Removed torch, torchvision, torchmetrics, piq from dependencies (~3.5GB of binaries removed)
  • Added brisque, scikit-image, scipy as replacements

Changes

  • image_matchers.py: Use scikit-image for SSIM calculation instead of torch
  • target_raters.py: Use brisque package wrapper instead of piq/torch
  • pyproject.toml: Update dependencies and remove PyTorch index configuration
  • _brisque.py: New wrapper module around brisque package

🤖 Generated with Claude Code


Note

Medium Risk
Replaces SSIM/BRISQUE implementations and swaps major dependencies, which may slightly change image matching/target rating behavior and introduces native build requirements in Docker.

Overview
Removes the PyTorch-based image-quality stack by dropping torch, torchvision, torchmetrics, and piq, and adding brisque, scikit-image, and scipy (plus deleting the custom uv PyTorch CPU index config).

Updates StructuralSimilarityMatcher to compute SSIM via skimage.metrics.structural_similarity on normalized NumPy arrays, and rewires target tracking ratings to use a new mock_vws._brisque.brisque_score wrapper around the brisque package.

Adjusts the Flask server Docker image to install g++ so native extensions needed by the new dependency chain can compile, and updates lint/dep tooling config and spelling dictionary accordingly.

Written by Cursor Bugbot for commit 259c63b. This will update automatically on new commits. Configure here.

Replace torch/torchvision/torchmetrics with scikit-image and numpy/scipy implementations:
- Use skimage.metrics.structural_similarity instead of torchmetrics SSIM
- Replace piq BRISQUE with brisque package wrapper
- Removes torch, torchvision, torchmetrics, piq dependencies (~3.5GB less)
- Add brisque, scipy, scikit-image as replacements

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

)
second_image_tensor = torch.tensor(data=second_image_np).float() / 255
second_image_tensor = second_image_tensor.view(
second_image_resized.size[1],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSIM fails on grayscale images missing channel dimension

High Severity

The structural_similarity call unconditionally passes channel_axis=2, but grayscale ("L" mode) images produce 2D numpy arrays with shape (H, W) — no axis 2 exists. The image validator explicitly allows grayscale images, so they can reach this code path. The old torch-based code handled this correctly via getbands() and .view(). The _brisque.py wrapper avoids this by calling .convert(mode="RGB"), but image_matchers.py does not convert images before creating numpy arrays.

Fix in Cursor Fix in Web

- Dockerfile: install g++ so libsvm-official (brisque dep) can compile
- Add 'brisque' to spelling private dictionary for pylint
- Disable pylint no-name-in-module for skimage.metrics import

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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

Comments