Views
No views yet
MERaLiON-Omni-MM-10B:| Dependency | Version |
|---|---|
| Python | 3.10 |
| torch | 2.6.0 |
| transformers | 4.52.0 |
| flash-attn | 2.7.4 |
| torchaudio | 2.6.0 |
| pillow | 11.1.0 |
| triton | 3.2.0 |
| CUDA | 12.7 |
pip install transformers torch pillow torchaudio flash-attn triton1import torch
2from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
3from mm_utils_mm import process_mm_info # bundled in this repository
4
5model_path = "zzlynxSG/MERaLiON-Omni-GRPO-10B"
6
7processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)
8processor.tokenizer.padding_side = "left"
9if processor.tokenizer.pad_token is None:
10 processor.tokenizer.pad_token = processor.tokenizer.eos_token
11
12model = AutoModelForSpeechSeq2Seq.from_pretrained(
13 model_path, trust_remote_code=True,
14 torch_dtype=torch.bfloat16,
15 attn_implementation="flash_attention_2",
16 use_safetensors=True,
17 device_map="auto"
18)
19
20MIN_PIX = 4 * 28 * 28
21MAX_PIX = 8192 * 28 * 28
22MAX_PIX_VIDEO = 8600 * 28 * 281chat_prompt = processor.tokenizer.apply_chat_template(
2 conversation=[[{"role": "user", "content": "Follow the text instruction based on the following image: <ImageHere> \n Describe the cultural elements in this image."}]],
3 tokenize=False, add_generation_prompt=True
4)[0]
5
6mm_input = [{"role": "user", "content": [
7 {"type": "image", "image": "your_image.jpg", "min_pixels": MIN_PIX, "max_pixels": MAX_PIX}
8]}]
9audios, images, videos = process_mm_info(mm_input)
10inputs = processor(text=[chat_prompt], audios=audios, images=images, videos=videos).to(model.device).to(model.dtype)
11
12with torch.inference_mode():
13 outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7, do_sample=True)
14print(processor.decode(outputs[0], skip_special_tokens=True))1chat_prompt = processor.tokenizer.apply_chat_template(
2 conversation=[[{"role": "user", "content": "Follow the text instruction based on the following audio: <SpeechHere> \n Transcribe this audio."}]],
3 tokenize=False, add_generation_prompt=True
4)[0]
5
6mm_input = [{"role": "user", "content": [
7 {"type": "audio", "audio": "your_audio.mp3"}
8]}]
9audios, images, videos = process_mm_info(mm_input)
10inputs = processor(text=[chat_prompt], audios=audios, images=images, videos=videos).to(model.device).to(model.dtype)
11
12with torch.inference_mode():
13 outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7, do_sample=True)
14print(processor.decode(outputs[0], skip_special_tokens=True))1chat_prompt = processor.tokenizer.apply_chat_template(
2 conversation=[[{"role": "user", "content": "Follow the text instruction based on the following video: <VideoHere> \n Summarize this video."}]],
3 tokenize=False, add_generation_prompt=True
4)[0]
5
6mm_input = [{"role": "user", "content": [
7 {"type": "video", "video": "your_video.mp4", "fps": 2, "min_frames": 32, "max_frames": 64,
8 "min_pixels": MIN_PIX, "total_pixels": MAX_PIX_VIDEO}
9]}]
10audios, images, videos = process_mm_info(mm_input, use_audio_in_video=True)
11inputs = processor(text=[chat_prompt], audios=audios, images=images, videos=videos).to(model.device).to(model.dtype)
12
13with torch.inference_mode():
14 outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7, do_sample=True)
15print(processor.decode(outputs[0], skip_special_tokens=True))