Views
No views yet
google/gemma-3-4b-it1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_id = "QuietImpostor/Gemma-3-4b-it-Opusfied"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.bfloat16,
10 device_map="auto",
11 attn_implementation="flash_attention_2"
12)
13
14messages = [
15 {"role": "user", "content": "Explain the concept of entropy in the style of a weary time traveler."},
16]
17
18input_ids = tokenizer.apply_chat_template(
19 messages,
20 add_generation_prompt=True,
21 return_tensors="pt"
22).to(model.device)
23
24outputs = model.generate(
25 input_ids,
26 max_new_tokens=512,
27 temperature=0.7,
28 do_sample=True
29)
30
31print(tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True))
32