This repository contains
Medusa heads trained on top of
MERaLiON/MERaLiON-2-3B.
K=4 small residual-MLP heads predict the next-next, next-next-next, …
tokens from the last-layer hidden state of the text decoder, so each
decode round produces up to 5 accepted tokens from a single batched
verifier forward pass.
† INT4 WER hit is a pre-existing bitsandbytes property, not Medusa-induced.
1import torch
2from transformers import AutoProcessor
3from modeling_medusa import MERaLiON2MedusaForASR
4
5model = MERaLiON2MedusaForASR.from_pretrained(
6 "YOUR_HF_USERNAME/MERaLiON-2-3B-Medusa",
7 torch_dtype=torch.bfloat16,
8 trust_remote_code=True,
9).to("cuda")
10
11processor = AutoProcessor.from_pretrained(
12 "MERaLiON/MERaLiON-2-3B", trust_remote_code=True,
13)
14
15# Prepare audio + prompt exactly like the base model expects
16# (see MERaLiON-2-3B model card for the full template).
17audio, sr = ... # numpy float32, target sample rate
18input_features = processor.feature_extractor(
19 audio, sampling_rate=sr, return_tensors="pt",
20).input_features.to("cuda").to(torch.bfloat16)
21
22conversation = [{
23 "role": "user",
24 "content": ("Instruction: Transcribe the speech \n"
25 "Follow the text instruction based on the "
26 "following audio: <SpeechHere>"),
27}]
28prompt = processor.tokenizer.apply_chat_template(
29 conversation, tokenize=False, add_generation_prompt=True)
30# ... see included `example_inference.py` for the full pipeline ...
31
32out_ids = model.generate_medusa(
33 input_ids=input_ids, attention_mask=attention_mask,
34 input_features=input_features, feature_attention_mask=fam,
35 max_new_tokens=128,
36)
37hyp = processor.tokenizer.decode(out_ids[0, input_ids.shape[1]:],
38 skip_special_tokens=True)