facebookresearch / facebookresearch/sam3
Eager import of `decord` during `import sam3` causes unnecessary dependency and crashes
- Dominant language
- Python
- Stars
- 11.7k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
## Problem
When importing sam3 (`import sam3`), the `decord` library is eagerly loaded even though it's only needed for video file processing.
[This line](https://github.com/facebookresearch/sam3/blob/84cc43bca4347b772f17/sam3/model/utils/sam2_utils.py#L213) indicated to me the import was intended to be deferred.
## Steps to Reproduce
```python
import sys
import sam3
print('decord loaded:', any('decord' in m for m in sys.modules))
# Output: decord loaded: True
```
## Root Cause
The import chain is:
```
import sam3
└─ sam3/model_builder.py
└─ sam3/model/sam3_image.py:17
└─ from sam3.train.data.collator import BatchedDatapoint
└─ sam3/train/data/sam3_image_dataset.py:18
└─ from decord import cpu, VideoReader # Eager import
```
## Impact
See https://github.com/dmlc/decord/pull/362 and related packaging issues https://github.com/conda-forge/staged-recipes/pull/31532
Contributor guide
Research direction
Start with the import chain in sam3/model_builder.py, sam3/model/sam3_image.py, and sam3/train/data/sam3_image_dataset.py, especially the decord import noted in the issue; compare it with the deferred-import intent in sam3/model/utils/sam2_utils.py. Run the documented `import sam3` reproduction and confirm decord is not loaded during import while video processing still has access to it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100