Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Model repo ID
5model_id = "Abigail45/Roleplay-RP-Sandbox"
6
7# Load tokenizer and model
8tokenizer = AutoTokenizer.from_pretrained(model_id)
9model = AutoModelForCausalLM.from_pretrained(
10 model_id,
11 device_map="auto", # Auto-assign to GPU if available
12 torch_dtype=torch.bfloat16 # Efficient for GPU
13)
14
15# Example prompt with chain-of-thought reasoning
16prompt = (
17 "You are a Roleplay-based bot that allows all types of roleplay.
18)
19
20# Tokenize input with max context length
21inputs = tokenizer(
22 prompt,
23 return_tensors="pt",
24 truncation=True,
25 max_length=39997 # Context length
26).to(model.device)
27
28# Generate output with max new tokens
29outputs = model.generate(
30 **inputs,
31 max_new_tokens=256, # Max tokens for generation
32 temperature=0.3, # Low temperature for accurate reasoning
33 top_p=0.9, # Sampling for natural output
34 do_sample=True, # Enable creative reasoning paths
35 repetition_penalty=1.1, # Avoid repeated phrases
36 eos_token_id=tokenizer.eos_token_id
37)
38
39# Decode and print output
40answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
41print("=== Model Output ===")
42print(answer)