multimodalart HF Staff commited on
Commit
68cf224
·
verified ·
1 Parent(s): 6aa8fa0

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. train/models/encoder.py +7 -3
train/models/encoder.py CHANGED
@@ -252,13 +252,17 @@ class VBertEncoder(BaseEncoder):
252
 
253
  # Replace text model embeddings with DecoupledEmbedding to match the
254
  # V-SPLADE weight layout (tok_embeddings.weight + additional_embedding.weight).
 
 
255
  text_model = instance.encoder.model.text_model
256
  old_emb = text_model.get_input_embeddings()
 
 
257
  new_emb = DecoupledEmbedding(
258
- num_embeddings=old_emb.num_embeddings,
259
- num_additional_embeddings=getattr(config, "additional_vocab_size", 40),
260
  embedding_dim=old_emb.embedding_dim,
261
- padding_idx=old_emb.padding_idx,
262
  ).to(dtype=dtype)
263
  text_model.set_input_embeddings(new_emb)
264
 
 
252
 
253
  # Replace text model embeddings with DecoupledEmbedding to match the
254
  # V-SPLADE weight layout (tok_embeddings.weight + additional_embedding.weight).
255
+ # The native ModernBertModel uses a plain nn.Embedding with the FULL vocab
256
+ # (50408). V-SPLADE splits this into main (50368) + additional (40).
257
  text_model = instance.encoder.model.text_model
258
  old_emb = text_model.get_input_embeddings()
259
+ additional_vocab = getattr(config, "additional_vocab_size", 40)
260
+ main_vocab = old_emb.num_embeddings - additional_vocab # 50408 - 40 = 50368
261
  new_emb = DecoupledEmbedding(
262
+ num_embeddings=main_vocab,
263
+ num_additional_embeddings=additional_vocab,
264
  embedding_dim=old_emb.embedding_dim,
265
+ padding_idx=old_emb.padding_idx if old_emb.padding_idx is not None and old_emb.padding_idx < main_vocab else None,
266
  ).to(dtype=dtype)
267
  text_model.set_input_embeddings(new_emb)
268