facebookresearch / facebookresearch/sam3

Relationship of GPU Memory and number of Classes & category_chunk_size

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

Description

When the number of classes increases, training memory usage grows significantly because SAM3 predicts masks using one query per class. Effectively, the decoder processes one class at a time within a forward pass.

For example, if you have 10 object categories, the decoder must handle 10 class queries. If you scale this to 100 classes in a single forward pass, the number of decoder queries becomes very large, which can exceed GPU memory limits—even on an 80GB GPU—due to the size of attention maps and intermediate activations.

However, there is no strict need to process all classes simultaneously. This is where category_chunk_size becomes useful.

Instead of running the decoder for all classes at once, the total set of classes is divided into smaller chunks. The model then processes one chunk per forward pass.

For instance:

Total classes = 10
category_chunk_size = 2

The classes are split into 5 chunks. As a result, each image is processed 5 times per epoch, each time paired with a different subset of 2 classes. Across those 5 passes, the model sees all 10 classes for that image.

This approach allows training with a large number of total classes (e.g., 100 or more) while keeping memory usage per forward pass bounded by the chosen chunk size. The trade-off is increased computation time, since each image must be processed multiple times to cover all classes.

But Does category_chunk_size effects the performance of training as well ?

Contributor guide

Open the contributing guide

Research direction

No file, test, or entry point is named. Locate category_chunk_size in the Python training path, then compare memory, throughput, and convergence with different chunk sizes and class counts. Done means documenting whether it changes training performance and explaining the memory-versus-computation trade-off.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.