-
Notifications
You must be signed in to change notification settings - Fork 29.5k
Add Molmo (7B-D, 7B-O, 70B) #33962
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
base: main
Are you sure you want to change the base?
Add Molmo (7B-D, 7B-O, 70B) #33962
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow looks super nice! Will finish #33859 asap to let you continue!
upstream merge of Arthur's modular PR
Still seeing some duplicate imports in the modeling code: from ...modeling_outputs import (
BaseModelOutputWithPast,
CausalLMOutputWithPast,
)
from ...modeling_rope_utils import ROPE_INIT_FUNCTIONS
from ...modeling_utils import PreTrainedModel
from ...utils import (
add_start_docstrings,
add_start_docstrings_to_model_forward,
is_flash_attn_2_available,
is_flash_attn_greater_or_equal_2_10,
logging,
replace_return_docstrings,
)
from .configuration_molmo import MolmoConfig
if is_flash_attn_2_available():
from ...modeling_flash_attention_utils import _flash_attention_forward
from ...modeling_outputs import BaseModelOutput, BaseModelOutputWithPooling, ModelOutput
from ...utils import (
ModelOutput,
is_flash_attn_2_available,
torch_int,
)
from .configuration_molmo import MOLMOConfig, MOLMOVisionConfig One quick&dirty solution would be to do a pass on the imports once the transformer in modular has finished, so that imports from various modules get merged and normalized to the most likely - but there's also some capitalized (wrong) model names that remain as well, strangely, like class MolmoVisionTransformer(nn.Module):
def __init__(self, config):
super().__init__()
self.config = config
embed_dim = config.hidden_size
self.embeddings = MolmoVisionEmbeddings(config)
self.pre_layrnorm = nn.LayerNorm(embed_dim, eps=config.layer_norm_eps)
self.encoder = MOLMOEncoder(config) # wut
self.post_layernorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps, bias=True) getting there however! |
Do you need a review? 🤗 |
Maybe a bit pre-mature but when using the script to convert the model to hf I got missmatch issues here:
|
Hi @molbap, was just wondering if you had an ETA on this? Great work here by the way! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for working on it! Left a few tiny comments here and there, overall looks good to me
valid_positions = image_token_indices_flat >= 0 | ||
valid_indices = image_token_indices_flat[valid_positions].long() | ||
valid_features = image_features_flat[valid_positions.to(image_features_flat.device)] | ||
valid_batch_indices = valid_batch_indices_expanded[ | ||
valid_positions.to(valid_batch_indices_expanded.device) | ||
].long() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember anymore why we needed this hehe. Is it possible for us to hide it somewhere in processing so that the model does simple embeds.masked_scatter(ids == image_id, image_features)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha, I don't remember either 😆 I'm sure it's doable yes!
What does this PR do?
As mentioned in issue #33710 , this is a draft to add support for Molmo natively in
transformers
.It is also using the new
modular
framework introduced in #33248 .Molmo has several existing variants:
The last three models share the same modeling, and thus will be covered by this PR.
Relative to the modular framework:
Choose a base model that's as close as possible from the one you're porting.
In my case, I'm using Llava as a reference. The differences I identify at a glance are the 2d pooling,
Figure out the differences.
Some differences will be a complete modification of the original module, in that case, all have to be redefined.
Some differences will be very tiny. For instance, some layers might be the same, but initialized with a different configuration key.
For instance, the position embeddings are slightly different.
Preserving inheritance across model components renames.
For instance, the code above will trigger
Because the supported pattern is currently searching for a caps-based model name. However, using
modular
is very promising and makes for a much smaller modeling file to review.I'll write down hurdles encountered here for future reference so that adding multimodal models to
transformers
ends up being a breeze.