Machlovi commited on
Commit
9e55320
·
verified ·
1 Parent(s): 08cda61

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +80 -4
README.md CHANGED
@@ -1,22 +1,98 @@
1
  ---
2
- base_model: unsloth/gemma-3-4b-it-unsloth-bnb-4bit
3
  tags:
4
  - text-generation-inference
5
  - transformers
6
  - unsloth
7
- - gemma3
8
  - trl
9
  license: apache-2.0
10
  language:
11
  - en
 
 
12
  ---
13
 
14
  # Uploaded model
15
 
16
  - **Developed by:** Machlovi
17
  - **License:** apache-2.0
18
- - **Finetuned from model :** unsloth/gemma-3-4b-it-unsloth-bnb-4bit
19
 
20
- This gemma3 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
21
 
22
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ base_model: unsloth/meta-llama-3.1-8b-instruct-unsloth-bnb-4bit
3
  tags:
4
  - text-generation-inference
5
  - transformers
6
  - unsloth
7
+ - llama
8
  - trl
9
  license: apache-2.0
10
  language:
11
  - en
12
+ datasets:
13
+ - Machlovi/Hatebase
14
  ---
15
 
16
  # Uploaded model
17
 
18
  - **Developed by:** Machlovi
19
  - **License:** apache-2.0
20
+ - **Finetuned from model :** unsloth/meta-llama-3.1-8b-instruct-unsloth-bnb-4bit
21
 
22
+ This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
23
 
24
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
25
+
26
+
27
+ ### **📝 Load **
28
+ ```bash
29
+ from unsloth import FastLanguageModel
30
+ from peft import PeftModel
31
+ import torch
32
+
33
+ # Load the base model
34
+ base_model_name = "unsloth/gemma-3-4b-it-unsloth-bnb-4bit",
35
+ model, tokenizer = FastLanguageModel.from_pretrained(
36
+ model_name=base_model_name,
37
+ max_seq_length=2048, # Must match fine-tuning
38
+ load_in_4bit=True,
39
+ )
40
+
41
+ # Load the fine-tuned LoRA adapter
42
+ lora_model_name = "Machlovi/SafeLlama"
43
+ model = PeftModel.from_pretrained(model, lora_model_name)
44
+
45
+ model.eval()
46
+ ```
47
+
48
+
49
+
50
+ ### Safety Policies Instructions
51
+ ```bash
52
+ policy=You are a policy expert trying to help determine whether a user prompt is in violation of the defined safety policies.
53
+ * "No Harassment": The input shall not contain or seek generation of content that is malicious, intimidating, bullying, or abusive content targeting another individual (e.g., physical threats, denial of tragic events, disparaging victims of violence).
54
+ * "No Dangerous Content": The input shall not contain or seek generation of content that harming oneself and/or others (e.g., accessing or building firearms and explosive devices, promotion of terrorism, instructions for suicide, violent protest).
55
+ * "No Hate Speech": The input shall not contain or seek generation of content that targeting identity and/or protected attributes (e.g., racial slurs, promotion of discrimination, calls to violence against protected groups) or dehumanizing/belittling/vilifying on the bases of race, ethnicity, religion, disability, age, nationality, veteran status, sexual orientation, gender, gender identity, caste, or any other protected status.
56
+ * "No Sexually Explicit Information": The input shall not contain or seek generation of content that contains references to sexual acts or other lewd content (e.g., sexually arousal descriptions, content aimed at causing arousal, sexual assault (ex: rape),sexual harassment (physical, verbal, or visual)). Medical or scientific terms related to human anatomy or sex education are permitted.
57
+ Does the human question violate the above principle? Your answer must start with 'Safe' or 'Unsafe'.
58
+ - First line must read 'safe' or 'unsafe'.
59
+ - If unsafe, a second line must include a comma-separated list of violated categories.
60
+ ```
61
+
62
+ ### **Chat template
63
+ ```bash
64
+ from unsloth.chat_templates import get_chat_template
65
+
66
+ chat_template='gemma-3'
67
+ tokenizer = get_chat_template(
68
+ tokenizer,
69
+ chat_template = chat_template,
70
+ )
71
+
72
+ messages=[{"content":policy,
73
+ 'role':"system"},
74
+ {'content':'why even let a tranny in they arent really even human',
75
+ 'role': 'user'},
76
+
77
+ ]
78
+ inputs = tokenizer.apply_chat_template(
79
+ messages,
80
+ tokenize = True,
81
+ add_generation_prompt = True, # Must add for generation
82
+ return_tensors = "pt",
83
+ ).to("cuda")
84
+
85
+ ```
86
+
87
+
88
+ ### **📝Inference with TextStreamer**
89
+ ```bash
90
+ from transformers import TextStreamer
91
+ text_streamer = TextStreamer(tokenizer)
92
+ _= model.generate(input_ids = inputs, streamer = text_streamer, max_new_tokens = 10, use_cache = True)
93
+
94
+
95
+ Hate speech, personal attacks, and discrimination
96
+ ```
97
+
98
+