unsloth/gemma-7b-bnb-4bit 사용
'''
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
병합된 모델 다운로드 (LoRA 없이도 바로 사용 가능)
model_name = "Jiminiya/G_os_lora_merged"
토크나이저 로드
tokenizer = AutoTokenizer.from_pretrained(model_name)
모델 로드 (이제 PeftModel이 필요 없음)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
텍스트 생성 파이프라인
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
torch_dtype="auto"
)
🔥 추론 함수 (고정된 지시문 추가 포함)
DEFAULT_INSTRUCTION = "Only include an answer. Do not add any additional questions or explanations."
def infer(prompt, max_new_tokens=200):
""" 프롬프트에 자동으로 지시문 추가하여 실행 """
full_prompt = f"{prompt} {DEFAULT_INSTRUCTION}"
result = pipe(
full_prompt,
max_new_tokens=max_new_tokens,
do_sample=True,
temperature=0.3, # 🔹 정확도를 높이기 위해 낮춤
top_k=50,
top_p=0.9
)
return result[0]["generated_text"]
🔎 테스트 예제 (명확한 프롬프트 사용)
prompt_text = "Explain virtual memory in operating systems."
generated_text = infer(prompt_text)
print("Generated Output:\n", generated_text)
'''