Run this model with HF Jobs

Run UCSC-VLAA/OpenEmbed-9B on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/UCSC-VLAA/OpenEmbed-9B. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/UCSC-VLAA/OpenEmbed-9B on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
OpenEmbed-9B / modeling_wemm_embedding.py
Yanqing0327's picture
OpenEmbed-9B: weights, model card, model code and licenses (private upload)
5742ab8 verified
Raw History Blame Contribute Delete
1.21 kB
import torch
import torch.nn.functional as F
from transformers import Qwen3_5ForConditionalGeneration
class WeMMEmbedding(Qwen3_5ForConditionalGeneration):
def embedding(self, input_ids=None, attention_mask=None, **kwargs):
# transformers < 5.15 reuses the rope_deltas cached by the previous multimodal
# forward for a text-only one, which shifts its position ids.
self.model.rope_deltas = None
outputs = self.model(
input_ids=input_ids,
attention_mask=attention_mask,
**kwargs
)
last_hidden_state = outputs.last_hidden_state
if attention_mask is not None:
eos_positions = attention_mask.sum(dim=1) - 1
else:
eos_positions = torch.full((last_hidden_state.shape[0],), last_hidden_state.shape[1] - 1, device=last_hidden_state.device)
eos_positions = eos_positions.clamp(min=0)
batch_indices = torch.arange(last_hidden_state.size(0), device=last_hidden_state.device)
embeddings = last_hidden_state[batch_indices, eos_positions]
embeddings = F.normalize(embeddings, dim=-1)
return embeddings