Skip to content

Fix: apply inspect-based kwarg filtering to start_session() to fix multiplex predictor TypeError#543

Open
kuihao wants to merge 1 commit into
facebookresearch:mainfrom
kuihao:main
Open

Fix: apply inspect-based kwarg filtering to start_session() to fix multiplex predictor TypeError#543
kuihao wants to merge 1 commit into
facebookresearch:mainfrom
kuihao:main

Conversation

@kuihao

@kuihao kuihao commented May 7, 2026

Copy link
Copy Markdown

Problem

When using SAM 3.1 with build_sam3_multiplex_video_predictor, calling handle_request(request=dict(type="start_session", ...)) raises:

TypeError: Sam3MultiplexTrackingWithInteractivity.init_state() 
got an unexpected keyword argument 'offload_state_to_cpu'

This happens because start_session() unconditionally passes
offload_state_to_cpu to self.model.init_state(), but
Sam3MultiplexTrackingWithInteractivity.init_state() does not accept
this parameter.

Root Cause

sam3_base_predictor.py already uses inspect.signature to filter
kwargs in add_prompt() and propagate_in_video(), but start_session()
was missing the same guard.

Fix

Apply the same inspect-based filtering pattern already used in this
file to start_session(), so only parameters accepted by the underlying
model's init_state() are forwarded.

Reproduction

Run the official sam3.1_video_predictor_example.ipynb with a
multiplex predictor — the start_session call on cell [11] raises
the TypeError above.

Testing

Ran the existing test suite to confirm no regressions:

$ python -m pytest test/test_io_utils.py -v
============================================================== test session starts ==============================================================
platform linux -- Python 3.12.3, pytest-8.1.1, pluggy-1.6.0
rootdir: /home/kuihao/Git/sam3
configfile: pyproject.toml
plugins: cov-7.1.0, hydra-core-1.3.2, anyio-4.9.0, flakefinder-1.1.0, xdoctest-1.0.2, shard-0.1.2, xdist-3.6.1, hypothesis-6.130.8, rerunfailures-15.1, typeguard-4.3.0
collected 8 items                                                                                                                               
Running 8 items in this shard

test/test_io_utils.py ........                                                                                                            [100%]

=============================================================== warnings summary ================================================================
sam3/model_builder.py:8
  /home/kuihao/Git/sam3/sam3/model_builder.py:8: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
    import pkg_resources

../../../../usr/local/lib/python3.12/dist-packages/timm/models/layers/__init__.py:49
  /usr/local/lib/python3.12/dist-packages/timm/models/layers/__init__.py:49: FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
    warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================= 8 passed, 2 warnings in 1.64s =========================================================

No existing unit test covers start_session() kwarg filtering.
The fix was verified end-to-end via sam3.1_video_predictor_example.ipynb
with a multiplex predictor — cell [11] no longer raises TypeError.

Happy to add a dedicated unit test if maintainers can point to
the preferred location for predictor-layer test coverage.

Fixes #544

…rt_session()

Sam3MultiplexTrackingWithInteractivity.init_state() does not accept
`offload_state_to_cpu`, causing a TypeError when start_session() is
called via the multiplex video predictor build_sam3_multiplex_video_predictor() (e.g. from the official
sam3.1_video_predictor_example.ipynb).

start_session() was unconditionally forwarding all kwargs to
self.model.init_state(), unlike add_prompt() and propagate_in_video()
which already guard against this using inspect.signature().

Apply the same inspect-based filtering pattern to start_session() so
that only parameters supported by the underlying model's init_state()
are forwarded, making the base class consistent and compatible across
SAM 3 and SAM 3.1 model variants.

Fixes: TypeError: Sam3MultiplexTrackingWithInteractivity.init_state()
       got an unexpected keyword argument 'offload_state_to_cpu'
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 7, 2026
@kuihao kuihao changed the title fix: apply inspect-based kwarg filtering to start_session() to fix multiplex predictor TypeError Fix: apply inspect-based kwarg filtering to start_session() to fix multiplex predictor TypeError May 7, 2026
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.

Bug: start_session() raises TypeError with multiplex predictor (SAM 3.1)

1 participant