Skip to content

Conversation

@provos
Copy link

@provos provos commented Nov 29, 2025

This PR enables SAM3 to run on Apple and CPU-only systems. It does not enable MPS but may make MPS support easier in the future.

Changes:

  • Add _get_float_dtype() helper to use float32 on CPU and float16 on GPU
  • Add device parameter to video/image loading functions instead of hardcoding CUDA
  • Replace .cuda() calls with .to(device) throughout the codebase
  • Make non_blocking=True conditional on CUDA availability
  • Add tensor_to_device() utility that uses pin_memory() optimization only on CUDA
  • Make bfloat16 conversion conditional on CUDA availability
  • Handle empty batch case in connected_components_cpu()
  • Update always_interpolate_masks_on_gpu to warn and fallback when data is on CPU
  • Generalize device assertions to allow MPS in addition to CUDA
  • Use single-device Sam3VideoPredictor when CUDA unavailable
  • Use decord2 as an API compatible replacement for decord as it has prebuilt wheels

These changes allow the example notebooks to run on a mac.

this has prebuilt wheels for apple silicon. bump numpy from 1.26 to 1.26.4 to meet dependency requirements for decord2
Allows systems without CUDA to fallback to CPU.
The pin_memory() optimization is only available for CUDA backends.
CUDA handles this internally but we need to handle it directly for CPU
@meta-cla
Copy link

meta-cla bot commented Nov 29, 2025

Hi @provos!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 29, 2025
@meta-cla
Copy link

meta-cla bot commented Nov 29, 2025

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants