Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2hf_path = 'Yi3852/MuFun-Instruct'
3tokenizer = AutoTokenizer.from_pretrained(hf_path, use_fast=False)
4device='cuda'
5model = AutoModelForCausalLM.from_pretrained(hf_path, trust_remote_code=True, torch_dtype="bfloat16")
6model.to(device)
7
8# single audio
9# during inference the audio(converted to a sequence of embeddings) will be placed in the position of <audio> tag in the prompt
10aud="/path/to/your/song.mp3"
11inp="\n<audio>Can you listen to this song and tell me its lyrics?"
12res=model.chat(prompt=inp, audio_files=aud, tokenizer=tokenizer)
13print(res)
14
15# multiple audios
16# for multiple songs each will be placed in the coresponding <audio> tag in the prompt
17aud=["/path/to/your/song1.mp3", '/path/to/your/song2.mp3']
18inp="\n<audio> This is song1. <audio> This is song2. Which song do you like more? Tell me the reason."
19res=model.chat(prompt=inp, audio_files=aud, tokenizer=tokenizer)
20print(res)
21
22# analyze only a specific segment of audio using the segs parameter
23# format is [start_time, end_time](in seconds), for multiple audios segs can be passed like [[0,30],[60,90]], [None,[0,30.0]]
24aud="/path/to/your/song.mp3"
25inp="\n<audio>How is the rhythm of this music clip?"
26res=model.chat(prompt=inp, audio_files=aud, segs=[0,30.0], tokenizer=tokenizer)
27print(res)
28
29# set audio_files=None will work, however it is not recommended to use it as a text model1@misc{jiang2025advancingfoundationmodelmusic,
2 title={Advancing the Foundation Model for Music Understanding},
3 author={Yi Jiang and Wei Wang and Xianwen Guo and Huiyun Liu and Hanrui Wang and Youri Xu and Haoqi Gu and Zhongqian Xie and Chuanjiang Luo},
4 year={2025},
5 eprint={2508.01178},
6 archivePrefix={arXiv},
7 primaryClass={cs.SD},
8 url={https://arxiv.org/abs/2508.01178},
9}