Feature Extraction
Transformers
English
qwen2_5_omni_thinker
text-generation
multimodal-embedding
any-to-any-retrieval
text-image-retrieval
video-retrieval
audio-retrieval
qwen2.5-omni
Instructions to use Sony/OmniUE-3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Sony/OmniUE-3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="Sony/OmniUE-3B")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("Sony/OmniUE-3B") model = AutoModelForSeq2SeqLM.from_pretrained("Sony/OmniUE-3B", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 1,179 Bytes
5fe8ec0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # Copyright (c) Meta Platforms, Inc. and affiliates. All Rights Reserved\n
from typing import Tuple
import torch
import transformers
from .config import T5EncoderConfig
class T5TextEncoder(torch.nn.Module):
def __init__(self, cfg: T5EncoderConfig):
super().__init__()
self.model = transformers.T5EncoderModel.from_pretrained(cfg.name)
self.tokenizer = transformers.AutoTokenizer.from_pretrained(cfg.name)
self.pad_mode = cfg.pad_mode
self.max_length = cfg.max_length
def forward(self, texts: list[str]) -> Tuple[torch.Tensor, torch.Tensor]:
device = next(self.model.parameters()).device
encoded = self.tokenizer(
texts,
truncation=True,
max_length=self.max_length,
padding=self.pad_mode,
return_tensors="pt",
)
input_ids = encoded["input_ids"].to(device)
attention_mask = encoded["attention_mask"].to(device)
res = self.model(
input_ids=input_ids,
attention_mask=attention_mask,
output_hidden_states=True,
)["last_hidden_state"]
return res, attention_mask.bool()
|