Views
No views yet

1from transformers import AutoProcessor, Gemma3ForConditionalGeneration
2import torch
3
4model_id = "INSAIT-Institute/BgGPT-Gemma-3-12B-IT"
5
6processor = AutoProcessor.from_pretrained(model_id)
7model = Gemma3ForConditionalGeneration.from_pretrained(
8 model_id, device_map="auto"
9).eval()
10
11messages = [
12 {
13 "role": "user",
14 "content": [{"type": "text", "text": "Кога е основан Софийският университет?"}],
15 },
16]
17
18inputs = processor.apply_chat_template(
19 messages, add_generation_prompt=True, tokenize=True,
20 return_dict=True, return_tensors="pt"
21).to(model.device, dtype=torch.bfloat16)
22
23input_len = inputs["input_ids"].shape[-1]
24
25with torch.inference_mode():
26 generation = model.generate(**inputs, max_new_tokens=512, do_sample=True, temperature=0.2)
27 generation = generation[0][input_len:]
28
29print(processor.decode(generation, skip_special_tokens=True))1messages = [
2 {
3 "role": "user",
4 "content": [
5 {"type": "image", "image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"},
6 {"type": "text", "text": "Опиши какво виждаш на изображението."},
7 ],
8 },
9]
10
11inputs = processor.apply_chat_template(
12 messages, add_generation_prompt=True, tokenize=True,
13 return_dict=True, return_tensors="pt"
14).to(model.device, dtype=torch.bfloat16)
15
16input_len = inputs["input_ids"].shape[-1]
17
18with torch.inference_mode():
19 generation = model.generate(**inputs, max_new_tokens=512, do_sample=True, temperature=0.2)
20 generation = generation[0][input_len:]
21
22print(processor.decode(generation, skip_special_tokens=True))1from vllm import LLM, SamplingParams
2
3llm = LLM(model="INSAIT-Institute/BgGPT-Gemma-3-12B-IT")
4params = SamplingParams(max_tokens=512, temperature=0.2)
5
6messages = [
7 {
8 "role": "user",
9 "content": [{"type": "text", "text": "Кога е основан Софийският университет?"}],
10 },
11]
12
13outputs = llm.chat(messages, sampling_params=params)
14print(outputs[0].outputs[0].text)vllm serve INSAIT-Institute/BgGPT-Gemma-3-12B-IT1from vllm import LLM, SamplingParams
2
3llm = LLM(
4 model="INSAIT-Institute/BgGPT-Gemma-3-12B-IT",
5 quantization="fp8",
6)
7params = SamplingParams(max_tokens=512, temperature=0.2)
8
9messages = [
10 {
11 "role": "user",
12 "content": [{"type": "text", "text": "Кога е основан Софийският университет?"}],
13 },
14]
15
16outputs = llm.chat(messages, sampling_params=params)
17print(outputs[0].outputs[0].text)vllm serve INSAIT-Institute/BgGPT-Gemma-3-12B-IT --quantization fp8Requires a GPU with compute capability >= 8.9 (H100, H200, RTX 4090).