Skip to content

Eager import of decord during import sam3 causes unnecessary dependency and crashes #191

@claydugo

Description

@claydugo

Problem

When importing sam3 (import sam3), the decord library is eagerly loaded even though it's only needed for video file processing.

This line indicated to me the import was intended to be deferred.

Steps to Reproduce

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 dmlc/decord#362 and related packaging issues conda-forge/staged-recipes#31532

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions