Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate mock vision backbone into model #441

Open
wants to merge 14 commits into
base: mm-dev
Choose a base branch
from

Conversation

epwalsh
Copy link
Member

@epwalsh epwalsh commented Feb 8, 2024

Adds an abstraction for vision backbones, along with a mock dataset to test it. You can run a test training job on 2 GPUs with the mock dataset like so:

torchrun --nproc-per-node=2 scripts/train.py configs/mm-tiny.yaml

olmo/model.py Outdated
Comment on lines 1251 to 1255
# Inject image patch embeddings into input embeddings.
assert image_offsets is not None
image_offsets_mask = image_offsets > 0
batch_idx = torch.arange(0, batch_size).repeat_interleave(image_offsets_mask.sum(dim=-1))
x.index_put_((batch_idx, image_offsets[image_offsets_mask]), img_emb[image_offsets_mask])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This took some thinking, but you can validate it with this little example:

import torch

B = 2
S = 8
D = 16
P = 3  # num patches (max across instances)
x = torch.zeros(B, S, D)

img_emb = torch.rand(B, P, D)

# use -1 for padding
image_offsets = torch.tensor([[1, 5, 6], [3, -1, -1]])
assert image_offsets.shape == (B, P)

image_offsets_mask = image_offsets > 0
batch_idx = torch.arange(0, B).repeat_interleave(image_offsets_mask.sum(dim=-1))
x.index_put_((batch_idx, image_offsets[image_offsets_mask]), img_emb[image_offsets_mask])

Copy link

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant