Skip to content

fix: add NumPy 2 compatibility - #629

Closed
codingbutstillalive wants to merge 7 commits into
facebookresearch:mainfrom
codingbutstillalive:experiment/numpy-2-compatibility
Closed

codingbutstillalive wants to merge 7 commits into
facebookresearch:mainfrom
codingbutstillalive:experiment/numpy-2-compatibility

Conversation

@codingbutstillalive

Copy link
Copy Markdown

Summary

Add NumPy 2 compatibility to the SAM3 fork.

Changes

  • Relax the NumPy dependency from numpy>=1.26,<2 to numpy>=1.26.
  • Replace deprecated np.bool usages with np.bool_ in the panoptic visualizer.

Validation

Tested with NumPy 2.5.3:

  • build_sam3_image_model succeeds.
  • build_sam3_video_predictor succeeds.
  • SAM3 Basic Usage notebook completes successfully.

The changes are based on the NumPy 2 compatibility work from upstream SAM3 PR #403.

Restrict the supported Python version to Python 3.12 to match the currently resolvable NumPy dependency range and the validated runtime environment.

Update development dependencies with known vulnerable versions:
- upgrade Black from 24.2.0 to 26.3.1
- upgrade GitPython from 3.1.31 to 3.1.60

Regenerate uv.lock from the updated dependency specification.

The resulting dependency set was verified with `uv audit --locked` and reports no known vulnerabilities across the resolved packages.
SAM3 imports einops from sam3.sam.rope during normal package import, so einops must be installed as a core dependency rather than only with the notebooks extra.

Move einops from the notebooks optional dependency set to the project's runtime dependencies and regenerate uv.lock.
Replace the deprecated pkg_resources resource_filename API with importlib.resources.

Resolve the bundled SAM3 BPE vocabulary through the current package resources API without pinning an older setuptools version.

Update all three model builder code paths that resolve the default BPE vocabulary.
Move pycocotools from the development and notebook extras into the core runtime dependencies.

The normal sam3 import path loads training data modules that require pycocotools, so keeping it optional makes a clean runtime installation incomplete.
Add psutil to the core runtime dependencies because the normal sam3 import path loads Sam3VideoPredictor, which uses psutil for parent-process checks.

Regenerate uv.lock from the updated dependency specification.
Add a reproducible image inference test and document the BF16 autocast requirement observed with the current SAM3 image path. Verified that the video path already provides the required autocast context, while the image path fails with dtype mismatches unless image and text inference are executed under CUDA BF16 autocast.
Apply the relevant compatibility changes from upstream SAM3 PR facebookresearch#403.

- relax the NumPy dependency from numpy>=1.26,<2 to numpy>=1.26
- replace deprecated np.bool aliases with np.bool_ in the panoptic visualizer
- preserve the upstream SAM3 implementation otherwise unchanged

The compatibility changes were validated on an NVIDIA L4 with NumPy 2.5.3, PyTorch 2.14.0+cu130, and CUDA enabled. The SAM3 Basic Usage notebook completed successfully, including image-model and video-predictor initialization.
@meta-cla

meta-cla Bot commented Sep 28, 2026

Copy link
Copy Markdown

Hi @codingbutstillalive!

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!

@codingbutstillalive
codingbutstillalive deleted the experiment/numpy-2-compatibility branch September 28, 2026 10:15
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