File size: 1,002 Bytes
27dc10f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from vllm import SamplingParams
from vllm.sampling_params import GuidedDecodingParams
import torch
import vllm
import re 
import torch.nn as nn
import torch.optim as optim

def setup_llm():
    model_name = "google/gemma-3-27b-it"
    output_regex = r"[\s\S]*Output:\s*[01]" # Regex remains the same
    guide_params = GuidedDecodingParams(regex=output_regex)

    sampling_params = SamplingParams(
        n=1,
        max_tokens=1024, # Adjust if reasoning gets truncated; Guided decoding adds overhead
        temperature=0.1, # Low temp for deterministic choice based on reasoning
        stop=["<end_of_turn>"], # Gemma's end-of-turn token
        guided_decoding=guide_params
    )
    llm = vllm.LLM(model=model_name,
            trust_remote_code=True,
            dtype=torch.bfloat16,
            max_model_len=4096,
            tensor_parallel_size=1,
            gpu_memory_utilization=0.90) # Adjust if needed
    return llm, sampling_params


llm, sampling_params = setup_llm()
print(llm)