LoRA adapter for
sound event detection with timestamps, fine-tuned on top of
OpenMOSS-Team/MOSS-Audio-8B-Instruct.
Trained on
laion/in-the-wild-soundscapes-gemini2.5-pro — 10,998 real-world soundscape recordings annotated by Gemini 2.5 Pro with timestamped sound event captions.
1import torch
2from peft import PeftModel
3
4# You need the MOSS-Audio source code:
5# git clone https://github.com/OpenMOSS/MOSS-Audio
6import sys; sys.path.insert(0, "MOSS-Audio")
7from src.modeling_moss_audio import MossAudioModel
8from src.processing_moss_audio import MossAudioProcessor
9from src.audio_io import load_audio
10
11BASE_MODEL = "OpenMOSS-Team/MOSS-Audio-8B-Instruct"
12LORA_REPO = "laion/moss-audio-sfx-lora-v4"
13
14# Load base model + LoRA
15processor = MossAudioProcessor.from_pretrained(BASE_MODEL, trust_remote_code=True)
16model = MossAudioModel.from_pretrained(
17 BASE_MODEL, trust_remote_code=True,
18 dtype=torch.bfloat16, device_map="cuda:0",
19)
20model = PeftModel.from_pretrained(model, LORA_REPO)
21model = model.merge_and_unload()
22model.eval()
23
24# Run inference
25prompt = "Please describe all audio events in this audio together with start time, end time, and caption for medium segments that are overlapping."
26audio = load_audio("your_audio.wav", sample_rate=processor.config.mel_sr)
27
28inputs = processor(text=prompt, audios=[audio], return_tensors="pt").to("cuda:0")
29if inputs.get("audio_data") is not None:
30 inputs["audio_data"] = inputs["audio_data"].to(torch.bfloat16)
31inputs["audio_input_mask"] = inputs["input_ids"] == processor.audio_token_id
32
33with torch.no_grad():
34 gen = model.generate(**inputs, max_new_tokens=4096, do_sample=False, use_cache=True)
35
36output = processor.decode(gen[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
37print(output)
1[
2 {"caption": "Birds chirping and singing in a forest setting", "start_time": 0.0, "end_time": 8.5},
3 {"caption": "Wind rustling through leaves and branches", "start_time": 2.3, "end_time": 12.0},
4 {"caption": "A dog barking twice in the distance", "start_time": 6.1, "end_time": 7.8},
5 {"caption": "Car engine passing on a nearby road", "start_time": 9.0, "end_time": 13.2}
6]
1accelerate launch \
2 --num_processes 8 \
3 --use_deepspeed \
4 --deepspeed_config_file ds_config_zero2.json \
5 train.py \
6 --model_dir OpenMOSS-Team/MOSS-Audio-8B-Instruct \
7 --data_path soundscapes_train/train.jsonl \
8 --output_dir ./lora_output \
9 --use_lora True \
10 --lora_rank 128 \
11 --lora_alpha 256 \
12 --num_train_epochs 2 \
13 --per_device_train_batch_size 1 \
14 --gradient_accumulation_steps 1 \
15 --learning_rate 5e-5 \
16 --lr_scheduler_type cosine \
17 --warmup_ratio 0.05 \
18 --bf16 True \
19 --gradient_checkpointing True \
20 --max_len 8192
This LoRA adapter is a component of the
Universal Audio Annotation Pipeline. In the full pipeline:
1@misc{moss-audio-sfx-lora-v4,
2 title={MOSS-Audio SFX LoRA v4: Sound Event Detection Adapter},
3 author={LAION},
4 year={2025},
5 url={https://huggingface.co/laion/moss-audio-sfx-lora-v4},
6}