Views
No views yet
transformers and peft libraries. Below is an example of how to load and generate replies:1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3from peft import PeftModel
4
5# Load the base model, tokenizer, and LoRA adapters
6base_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
7adapter_id = "AdamDE/tinyllama-custom-youtube-replies"
8tokenizer = AutoTokenizer.from_pretrained(adapter_id)
9base_model = AutoModelForCausalLM.from_pretrained(base_id, torch_dtype=torch.float16, device_map="auto")
10model = PeftModel.from_pretrained(base_model, adapter_id)
11
12# Prepare input
13messages = [
14 {"role": "system", "content": "You are an AI/ML tutorial creator replying to YouTube comments. "
15 "Provide concise, friendly, and domain-specific help, encourage engagement, "
16 "and keep a positive tone with occasional emojis when appropriate."},
17 {"role": "user", "content": "Your enthusiasm is contagious!"}
18]
19inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
20
21# Generate reply
22with torch.no_grad():
23 out = model.generate(inputs, max_new_tokens=128, temperature=0.7, top_p=0.9, pad_token_id=tokenizer.eos_token_id)
24reply = tokenizer.decode(out[0], skip_special_tokens=True)
25print(reply)
26# Example output: "Haha, thanks! 😂 What's your favorite part?"pip install transformers peft torchmax_new_tokens, temperature, and top_p to control reply length and creativity.