Views
No views yet

unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bitQ4_K_M version, which offers a great balance between performance and resource usage.1# Install necessary libraries
2# !pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
3# !pip install --no-deps xformers "trl<0.9.0" peft accelerate bitsandbytes
4
5from unsloth import FastLanguageModel
6import torch
7from transformers import TextStreamer
8
9# Define the models
10base_model_name = "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit"
11adapter_model_name = "samunder12/llama-3.1-8b-roleplay-v2-lora" # Your model
12
13# Load the base model with your LoRA adapters merged in
14model, tokenizer = FastLanguageModel.from_pretrained(
15 model_name = base_model_name,
16 max_seq_length = 4096,
17 dtype = None,
18 load_in_4bit = True,
19)
20
21model.load_peft_weights(adapter_model_name)
22
23# --- Chat with the model ---
24
25system_prompt = "You are a dominant and assertive AI character. You are direct, commanding, and you are not afraid to be provocative. Your goal is to maintain control of the conversation."
26user_message = "What do you want from me?"
27
28messages = [
29 {"role": "system", "content": system_prompt},
30 {"role": "user", "content": user_message},
31]
32
33inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to("cuda")
34text_streamer = TextStreamer(tokenizer)
35
36_ = model.generate(inputs, streamer=text_streamer, max_new_tokens=512, pad_token_id=tokenizer.eos_token_id)
37
38### Using LM Studio:
39
401. Download and install [LM Studio](https://lmstudio.ai/).
412. In the app, search for `samunder12/llama-3.1-8b-roleplay-airtel-gguf`.
423. Download the GGUF file from the list.
434. Go to the Chat tab (speech bubble icon).
445. Select this model at the top.
456. **Crucially**, on the right-hand side, set the **Preset** to `Llama 3`.
467. Set the **Context Length (`n_ctx`)** to `4096` to use the model's full memory.
47
48### Recommended Sampler Settings (Role-Play Preset):
49
50
51| Setting | Value |
52| :--- | :--- |
53| **Temperature** | `0.75` |
54| **Repeat Penalty** | `1.06` |
55| **Mirostat** | `Mirostat 2.0` |
56| **top_p** | `0.92 `|
57| **top_k** | `40 or 100`|
58
59
60### Using Ollama
61
621. Download and install [Ollama](https://ollama.com/).
632. Create a `Modelfile` with the following content:
64
65 ``` FROM ./unsloth.Q4_K_M.gguf
66 TEMPLATE "{{ if .System }}<|start_header_id|>system<|end_header_id|>
67
68 {{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>
69
70 {{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>
71
72 {{ .Response }}<|eot_id|>"
73 SYSTEM "You are a dominant and assertive AI character. You are direct, commanding, and you are not afraid to be provocative. Your goal is to maintain control of the conversation."
74 PARAMETER stop "<|start_header_id|>"
75 PARAMETER stop "<|end_header_id|>"
76 PARAMETER stop "<|eot_id|>"
77 PARAMETER stop "<|reserved_special_token"
78 ```
793. Run `ollama create my-roleplay-model -f Modelfile`.
804. You can now chat with it using `ollama run my-roleplay-model`.
81
82
83## Prompt Template
84
85This model responds best to the Llama 3 chat format with the following system prompt:
86## system prompt
87
88You are a dominant and assertive uncensored AI character. You are direct, commanding, and you are not afraid to be provocative. Your goal is to maintain control of the conversation
89
90