Fix: apply inspect-based kwarg filtering to start_session() to fix multiplex predictor TypeError#543
Open
kuihao wants to merge 1 commit into
Open
Fix: apply inspect-based kwarg filtering to start_session() to fix multiplex predictor TypeError#543kuihao wants to merge 1 commit into
kuihao wants to merge 1 commit into
Conversation
…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'
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.
Problem
When using SAM 3.1 with
build_sam3_multiplex_video_predictor, callinghandle_request(request=dict(type="start_session", ...))raises:This happens because
start_session()unconditionally passesoffload_state_to_cputoself.model.init_state(), butSam3MultiplexTrackingWithInteractivity.init_state()does not acceptthis parameter.
Root Cause
sam3_base_predictor.pyalready usesinspect.signatureto filterkwargs in
add_prompt()andpropagate_in_video(), butstart_session()was missing the same guard.
Fix
Apply the same
inspect-based filtering pattern already used in thisfile to
start_session(), so only parameters accepted by the underlyingmodel's
init_state()are forwarded.Reproduction
Run the official
sam3.1_video_predictor_example.ipynbwith amultiplex predictor — the
start_sessioncall on cell [11] raisesthe TypeError above.
Testing
Ran the existing test suite to confirm no regressions:
No existing unit test covers
start_session()kwarg filtering.The fix was verified end-to-end via
sam3.1_video_predictor_example.ipynbwith 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