HackWeasel commited on
Commit
3e2e5dc
·
verified ·
1 Parent(s): f833dd1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +64 -0
README.md CHANGED
@@ -24,6 +24,70 @@ Ask questions about movies which have been rated on IMDB
24
 
25
  Use the code below to get started with the model.
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  ### Training Data
28
 
29
  mteb/imdb/tree/main/test.jsonl
 
24
 
25
  Use the code below to get started with the model.
26
 
27
+ ``` Python
28
+ from peft import PeftModel
29
+ from transformers import AutoModelForCausalLM, AutoTokenizer
30
+ import torch
31
+
32
+ # Set device
33
+ device = "cuda" if torch.cuda.is_available() else "cpu"
34
+
35
+ # Load tokenizer and models
36
+ print("Loading models...")
37
+ tokenizer = AutoTokenizer.from_pretrained("unsloth/llama-3.2-1b-instruct-bnb-4bit")
38
+ base_model = AutoModelForCausalLM.from_pretrained("unsloth/llama-3.2-1b-instruct-bnb-4bit").to(device)
39
+ model = PeftModel.from_pretrained(base_model, "HackWeasel/llama-3.2-1b-QLORA-IMDB").to(device)
40
+ model.eval()
41
+ print("Models loaded!")
42
+
43
+ def generate_response(prompt, max_length=4096, temperature=0.7):
44
+ with torch.no_grad():
45
+ inputs = tokenizer(prompt, return_tensors="pt").to(device) # Move inputs to GPU
46
+ outputs = model.generate(
47
+ **inputs,
48
+ max_length=max_length,
49
+ temperature=temperature,
50
+ do_sample=True,
51
+ pad_token_id=tokenizer.eos_token_id
52
+ )
53
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
54
+
55
+ def main():
56
+ conversation_history = ""
57
+ print("\nWelcome! Start chatting with the model (type 'quit' to exit)")
58
+
59
+ while True:
60
+ user_input = input("\nYou: ").strip()
61
+ if user_input.lower() == 'quit':
62
+ print("Goodbye!")
63
+ break
64
+
65
+ # Construct the prompt with conversation history
66
+ if conversation_history:
67
+ full_prompt = f"{conversation_history}\nHuman: {user_input}\nAssistant:"
68
+ else:
69
+ full_prompt = f"Human: {user_input}\nAssistant:"
70
+
71
+ try:
72
+ # Generate response
73
+ response = generate_response(full_prompt)
74
+
75
+ # Extract just the new response
76
+ new_response = response.split("Assistant:")[-1].strip()
77
+
78
+ # Update conversation history
79
+ conversation_history = f"{conversation_history}\nHuman: {user_input}\nAssistant: {new_response}"
80
+
81
+ # Print the response
82
+ print("\nAssistant:", new_response)
83
+ except Exception as e:
84
+ print(f"An error occurred: {e}")
85
+ print("Continuing conversation...")
86
+
87
+ if __name__ == "__main__":
88
+ main()
89
+ ```
90
+
91
  ### Training Data
92
 
93
  mteb/imdb/tree/main/test.jsonl