Views
No views yet


Transformers 🤗: See heretemperature=0.2 and top_p=0.95 for chat completion (e.g. Audio Understanding) and temperature=0.0 for transcriptionpip install git+https://github.com/huggingface/transformers1from transformers import VoxtralForConditionalGeneration, AutoProcessor
2import torch
3
4device = "cuda"
5repo_id = "MohamedRashad/Voxtral-Small-24B-2507-tranbsformers"
6
7processor = AutoProcessor.from_pretrained(repo_id)
8model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
9
10conversation = [
11 {
12 "role": "user",
13 "content": [
14 {
15 "type": "audio",
16 "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/mary_had_lamb.mp3",
17 },
18 {
19 "type": "audio",
20 "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/winning_call.mp3",
21 },
22 {"type": "text", "text": "What sport and what nursery rhyme are referenced?"},
23 ],
24 }
25]
26
27inputs = processor.apply_chat_template(conversation)
28inputs = inputs.to(device, dtype=torch.bfloat16)
29
30outputs = model.generate(**inputs, max_new_tokens=500)
31decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
32
33print("\nGenerated response:")
34print("=" * 80)
35print(decoded_outputs[0])
36print("=" * 80)1from transformers import VoxtralForConditionalGeneration, AutoProcessor
2import torch
3
4device = "cuda"
5repo_id = "MohamedRashad/Voxtral-Small-24B-2507-tranbsformers"
6
7processor = AutoProcessor.from_pretrained(repo_id)
8model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
9
10conversation = [
11 {
12 "role": "user",
13 "content": [
14 {
15 "type": "audio",
16 "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/obama.mp3",
17 },
18 {
19 "type": "audio",
20 "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/bcn_weather.mp3",
21 },
22 {"type": "text", "text": "Describe briefly what you can hear."},
23 ],
24 },
25 {
26 "role": "assistant",
27 "content": "The audio begins with the speaker delivering a farewell address in Chicago, reflecting on his eight years as president and expressing gratitude to the American people. The audio then transitions to a weather report, stating that it was 35 degrees in Barcelona the previous day, but the temperature would drop to minus 20 degrees the following day.",
28 },
29 {
30 "role": "user",
31 "content": [
32 {
33 "type": "audio",
34 "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/winning_call.mp3",
35 },
36 {"type": "text", "text": "Ok, now compare this new audio with the previous one."},
37 ],
38 },
39]
40
41inputs = processor.apply_chat_template(conversation)
42inputs = inputs.to(device, dtype=torch.bfloat16)
43
44outputs = model.generate(**inputs, max_new_tokens=500)
45decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
46
47print("\nGenerated response:")
48print("=" * 80)
49print(decoded_outputs[0])
50print("=" * 80)1from transformers import VoxtralForConditionalGeneration, AutoProcessor
2import torch
3
4device = "cuda"
5repo_id = "MohamedRashad/Voxtral-Small-24B-2507-tranbsformers"
6
7processor = AutoProcessor.from_pretrained(repo_id)
8model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
9
10conversation = [
11 {
12 "role": "user",
13 "content": [
14 {
15 "type": "text",
16 "text": "Why should AI models be open-sourced?",
17 },
18 ],
19 }
20]
21
22inputs = processor.apply_chat_template(conversation)
23inputs = inputs.to(device, dtype=torch.bfloat16)
24
25outputs = model.generate(**inputs, max_new_tokens=500)
26decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
27
28print("\nGenerated response:")
29print("=" * 80)
30print(decoded_outputs[0])
31print("=" * 80)1from transformers import VoxtralForConditionalGeneration, AutoProcessor
2import torch
3
4device = "cuda"
5repo_id = "MohamedRashad/Voxtral-Small-24B-2507-tranbsformers"
6
7processor = AutoProcessor.from_pretrained(repo_id)
8model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
9
10conversation = [
11 {
12 "role": "user",
13 "content": [
14 {
15 "type": "audio",
16 "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/winning_call.mp3",
17 },
18 ],
19 }
20]
21
22inputs = processor.apply_chat_template(conversation)
23inputs = inputs.to(device, dtype=torch.bfloat16)
24
25outputs = model.generate(**inputs, max_new_tokens=500)
26decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
27
28print("\nGenerated response:")
29print("=" * 80)
30print(decoded_outputs[0])
31print("=" * 80)1from transformers import VoxtralForConditionalGeneration, AutoProcessor
2import torch
3
4device = "cuda"
5repo_id = "MohamedRashad/Voxtral-Small-24B-2507-tranbsformers"
6
7processor = AutoProcessor.from_pretrained(repo_id)
8model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
9
10conversations = [
11 [
12 {
13 "role": "user",
14 "content": [
15 {
16 "type": "audio",
17 "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/obama.mp3",
18 },
19 {
20 "type": "audio",
21 "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/bcn_weather.mp3",
22 },
23 {
24 "type": "text",
25 "text": "Who's speaking in the speach and what city's weather is being discussed?",
26 },
27 ],
28 }
29 ],
30 [
31 {
32 "role": "user",
33 "content": [
34 {
35 "type": "audio",
36 "path": "https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/winning_call.mp3",
37 },
38 {"type": "text", "text": "What can you tell me about this audio?"},
39 ],
40 }
41 ],
42]
43
44inputs = processor.apply_chat_template(conversations)
45inputs = inputs.to(device, dtype=torch.bfloat16)
46
47outputs = model.generate(**inputs, max_new_tokens=500)
48decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
49
50print("\nGenerated responses:")
51print("=" * 80)
52for decoded_output in decoded_outputs:
53 print(decoded_output)
54 print("=" * 80)1from transformers import VoxtralForConditionalGeneration, AutoProcessor
2import torch
3
4device = "cuda"
5repo_id = "MohamedRashad/Voxtral-Small-24B-2507-tranbsformers"
6
7processor = AutoProcessor.from_pretrained(repo_id)
8model = VoxtralForConditionalGeneration.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map=device)
9
10inputs = processor.apply_transcrition_request(language="en", audio="https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/obama.mp3", model_id=repo_id)
11inputs = inputs.to(device, dtype=torch.bfloat16)
12
13outputs = model.generate(**inputs, max_new_tokens=500)
14decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)
15
16print("\nGenerated responses:")
17print("=" * 80)
18for decoded_output in decoded_outputs:
19 print(decoded_output)
20 print("=" * 80)