feat: add pyproject.toml (uv) and Apple Silicon MPS support#47
Open
Micuks wants to merge 3 commits intoBIT-DataLab:mainfrom
Open
feat: add pyproject.toml (uv) and Apple Silicon MPS support#47Micuks wants to merge 3 commits intoBIT-DataLab:mainfrom
Micuks wants to merge 3 commits intoBIT-DataLab:mainfrom
Conversation
Migrate from requirements.txt to pyproject.toml for modern Python packaging. Add optional dependency groups: paddleocr, formula, rmbg, torch, sam3. Configure uv sources for local sam3_src editable install. Also update .gitignore to exclude uv.lock and *.egg-info/.
Auto-detect MPS backend in SAM3Model when no device is specified (cuda > mps > cpu). Update config.yaml.example to document the "mps" option and the PYTORCH_ENABLE_MPS_FALLBACK=1 env var. Tested on M-series MacBook with PyTorch 2.11 + MPS backend. Upstream SAM3 MPS patches tracked in facebookresearch/sam3#173.
MPS backend lacks a few ops (e.g. aten::_assert_async). Setting PYTORCH_ENABLE_MPS_FALLBACK=1 in main.py before any torch import lets PyTorch silently fall back to CPU for unsupported ops, so users don't need to remember the env var.
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.
Background
I was trying to set up Edit Banana on my MacBook (Apple Silicon) and ran into a few issues:
pyproject.toml— had to manuallypip install -r requirements.txt, and optional deps like torch/sam3 weren't structured, making it hard to manage with modern tools likeuv.Changes
1. Add
pyproject.tomlrequirements.txtinto a standardpyproject.tomlpip install -e ".[torch]"— PyTorch + torchvisionpip install -e ".[sam3]"— SAM3 + torch + missing upstream deps (einops, pycocotools, psutil)pip install -e ".[paddleocr]"/.[formula]/.[rmbg]— same as before[tool.uv.sources]for localsam3_src/editable install.gitignoreto excludeuv.lockand*.egg-info/2. MPS device support
SAM3Model.__init__: auto-detect MPS when no device is specified (cuda > mps > cpu)config.yaml.example: document the"mps"device option andPYTORCH_ENABLE_MPS_FALLBACK=1env varTest
Tested on MacBook Pro (M-series) with Python 3.10, PyTorch 2.11,
uv 0.6:Compatibility
requirements.txtis kept as-is for users who don't usepyproject.tomlscripts/setup_sam3.shworkflow is unchanged