Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "GetSoloTech/Gemma3-Code-Reasoning-4B"
4
5# Load the tokenizer and model
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype="auto",
10 device_map="auto"
11)
12
13# Prepare input for competitive programming problem
14messages = [
15 {"role": "system", "content": "You are an expert competitive programmer. Read the problem and produce a correct, efficient solution. Include reasoning if helpful."},
16 {"role": "user", "content": "Your programming problem here..."}
17]
18
19text = tokenizer.apply_chat_template(
20 messages,
21 tokenize=False,
22 add_generation_prompt=True,
23)
24
25model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
26
27# Generate solution
28generated_ids = model.generate(
29 **model_inputs,
30 max_new_tokens=4096,
31 temperature=1.0,
32 top_p=0.95,
33 top_k=64
34)
35
36output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
37content = tokenizer.decode(output_ids, skip_special_tokens=True).strip("\n")
38print(content)