Views
No views yet

1import torch
2from transformers import AutoModel, AutoTokenizer
3
4torch.set_grad_enabled(False)
5
6# init model and tokenizer
7model = AutoModel.from_pretrained('internlm/internlm-xcomposer2d5-ol-7b', model_dir='base', torch_dtype=torch.bfloat16, trust_remote_code=True).cuda().eval().half()
8tokenizer = AutoTokenizer.from_pretrained('internlm/internlm-xcomposer2d5-ol-7b', model_dir='base', trust_remote_code=True)
9model.tokenizer = tokenizer1import os
2os.environ['USE_HF'] = 'True'
3
4import torch
5from swift.llm import (
6 get_model_tokenizer, get_template, ModelType,
7 get_default_template_type, inference
8)
9from swift.utils import seed_everything
10
11model_type = ModelType.qwen2_audio_7b_instruct
12model_id_or_path = 'internlm/internlm-xcomposer2d5-ol-7b'
13template_type = get_default_template_type(model_type)
14print(f'template_type: {template_type}')
15
16model, tokenizer = get_model_tokenizer(model_type, torch.float16, model_id_or_path=model_id_or_path, model_dir='audio',
17 model_kwargs={'device_map': 'cuda:0'})
18model.generation_config.max_new_tokens = 256
19template = get_template(template_type, tokenizer)
20seed_everything(42)1import os
2os.environ['USE_HF'] = 'True'
3
4import torch
5from swift.llm import (
6 get_model_tokenizer, get_template, ModelType,
7 get_default_template_type, inference
8)
9from swift.utils import seed_everything
10
11model_type = ModelType.qwen2_audio_7b_instruct
12model_id_or_path = 'internlm/internlm-xcomposer2d5-ol-7b'
13template_type = get_default_template_type(model_type)
14print(f'template_type: {template_type}')
15
16model, tokenizer = get_model_tokenizer(model_type, torch.float16, model_id_or_path=model_id_or_path, model_dir='audio',
17 model_kwargs={'device_map': 'cuda:0'})
18model.generation_config.max_new_tokens = 256
19template = get_template(template_type, tokenizer)
20seed_everything(42)
21
22# Chinese ASR
23query = '<audio>Detect the language and recognize the speech.'
24response, _ = inference(model, template, query, audios='examples/audios/chinese.mp3')
25print(f'query: {query}')
26print(f'response: {response}')1import torch
2from transformers import AutoModel, AutoTokenizer
3
4torch.set_grad_enabled(False)
5
6# init model and tokenizer
7model = AutoModel.from_pretrained('internlm/internlm-xcomposer2d5-ol-7b', model_dir='base', torch_dtype=torch.bfloat16, trust_remote_code=True).cuda().eval().half()
8tokenizer = AutoTokenizer.from_pretrained('internlm/internlm-xcomposer2d5-ol-7b', model_dir='base', trust_remote_code=True)
9model.tokenizer = tokenizer
10
11query = 'Analyze the given image in a detail manner'
12image = ['examples/images/dubai.png']
13with torch.autocast(device_type='cuda', dtype=torch.float16):
14 response, _ = model.chat(tokenizer, query, image, do_sample=False, num_beams=3, use_meta=True)
15print(response)1@misc{zhang2024internlmxcomposer25omnilivecomprehensivemultimodallongterm,
2 title={InternLM-XComposer2.5-OmniLive: A Comprehensive Multimodal System for Long-term Streaming Video and Audio Interactions},
3 author={Pan Zhang and Xiaoyi Dong and Yuhang Cao and Yuhang Zang and Rui Qian and Xilin Wei and Lin Chen and Yifei Li and Junbo Niu and Shuangrui Ding and Qipeng Guo and Haodong Duan and Xin Chen and Han Lv and Zheng Nie and Min Zhang and Bin Wang and Wenwei Zhang and Xinyue Zhang and Jiaye Ge and Wei Li and Jingwen Li and Zhongying Tu and Conghui He and Xingcheng Zhang and Kai Chen and Yu Qiao and Dahua Lin and Jiaqi Wang},
4 year={2024},
5 archivePrefix={arXiv},
6 primaryClass={cs.CV},
7 url={https://arxiv.org/abs/2412.09596},
8}