facebookresearch / facebookresearch/sam3

An error occurs when using the sam3_video_predictor with compile=True enabled.

Open
#488 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
11.7k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

When I use:

```
self.model = build_sam3_video_predictor(
checkpoint_path=model_path,
bpe_path=bpe_path,
gpus_to_use=gpus_to_use,
compile=use_compile
)
```
and perform compilation warm-up with:
`self.model.model.warm_up_compilation()`
I encounter errors regardless of whether I use point or text prompts.

Error message
```
/mnt/vision-gen-ks3-hd/Video_Generation/chenyuxuan7/mieraser/demo/sam3_infer/api.py", line 65, in add_prompt
resp = predictor.add_prompt(req)
/mnt/vision-gen-ks3-hd/Video_Generation/chenyuxuan7/mieraser/demo/sam3_infer/predictor.py", line 195, in add_prompt
result_need = self.model.handle_request(request=model_request)
/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
"/root/sam3/sam3/model/sam3_video_predictor.py", line 68, in handle_request
urn self.add_prompt( [7/470]
"/root/sam3/sam3/model/sam3_video_predictor.py", line 154, in add_prompt
me_idx, outputs = self.model.add_prompt(
"/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
"/root/sam3/sam3/model/sam3_video_inference.py", line 1380, in add_prompt
urn self.add_tracker_new_points(
"/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
File "/root/sam3/sam3/model/sam3_video_inference.py", line 1349, in _prepare_backbone_feats
_ = self.run_backbone_and_detection(
File "/root/sam3/sam3/model/sam3_video_base.py", line 345, in run_backbone_and_detection
sam3_image_out, _ = self.detector.forward_video_grounding_multigpu(
File "/root/sam3/sam3/model/sam3_image.py", line 727, in forward_video_grounding_multigpu
self._build_multigpu_buffer_next_chunk(
File "/root/sam3/sam3/model/sam3_image.py", line 807, in _build_multigpu_buffer_next_chunk
out_local = self.forward_grounding(
File "/root/sam3/sam3/model/sam3_image.py", line 447, in forward_grounding
prompt, prompt_mask, backbone_out = self._encode_prompt(
File "/root/sam3/sam3/model/sam3_image.py", line 182, in _encode_prompt
feat_tuple = self._get_img_feats(backbone_out, find_input.img_ids)
File "/root/sam3/sam3/model/sam3_image.py", line 160, in _get_img_feats
**self.backbone.forward_image(image),
File "/root/sam3/sam3/model/vl_combiner.py", line 82, in forward_image
return activation_ckpt_wrapper(self._forward_image_no_act_ckpt)(
File "/root/sam3/sam3/model/act_ckpt_utils.py", line 97, in act_ckpt_wrapper
ret = module(*args, **kwargs)
File "/root/sam3/sam3/model/vl_combiner.py", line 89, in _forward_image_no_act_ckpt
sam3_features, sam3_pos, sam2_features, sam2_pos = self.vision_backbone.forward(
File "/root/sam3/sam3/model/act_ckpt_utils.py", line 120, in wrapped
outputs = f(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/eval_frame.py", line 655, in _fn
return fn(*args, **kwargs)
File "/root/sam3/sam3/model/necks.py", line 101, in forward
def forward(
File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/eval_frame.py", line 838, in _fn
return fn(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_functorch/aot_autograd.py", line 1201, in forward
return compiled_fn(full_args)
File "/usr/local/lib/python3.10/dist-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 328, in runtime_wrapper
all_outs = call_func_at_runtime_with_args(
File "/usr/local/lib/python3.10/dist-packages/torch/_functorch/_aot_autograd/utils.py", line 126, in call_func_at_runtime_with_args
out = normalize_as_list(f(args))
File "/usr/local/lib/python3.10/dist-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 495, in wrapper
return compiled_fn(runtime_args)
File "/usr/local/lib/python3.10/dist-packages/torch/_inductor/output_code.py", line 460, in __call__
return self.current_callable(inputs)
File "/usr/local/lib/python3.10/dist-packages/torch/_inductor/compile_fx.py", line 1372, in run
return compiled_fn(new_inputs)
File "/usr/local/lib/python3.10/dist-packages/torch/_inductor/cudagraph_trees.py", line 387, in deferred_cudagraphify
fn, out = cudagraphify(model, inputs, new_static_input_idxs, *args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/torch/_inductor/cudagraph_trees.py", line 445, in cudagraphify
manager = get_container(device_index).get_tree_manager()
File "/usr/local/lib/python3.10/dist-packages/torch/_inductor/cudagraph_trees.py", line 330, in get_container
container_dict = get_obj(local, "tree_manager_containers")
File "/usr/local/lib/python3.10/dist-packages/torch/_inductor/cudagraph_trees.py", line 325, in get_obj
assert torch._C._is_key_in_tls(attr_name)
AssertionError
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with build_sam3_video_predictor(..., compile=True) followed by self.model.model.warm_up_compilation(). Start at sam3/model/sam3_video_predictor.py and follow the stack through sam3_video_inference.py, sam3_image.py, vl_combiner.py, and necks.py into PyTorch’s CUDAGraph code. Done means point and text prompts work after warm-up without the AssertionError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.