Machlovi commited on
Commit
795d591
·
verified ·
1 Parent(s): 4ba73b3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +29 -31
README.md CHANGED
@@ -24,9 +24,8 @@ This llama model was trained 2x faster with [Unsloth](https://github.com/unsloth
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 and Run Inference**
28
  ```bash
29
-
30
  from unsloth import FastLanguageModel
31
  from peft import PeftModel
32
  import torch
@@ -43,36 +42,39 @@ model, tokenizer = FastLanguageModel.from_pretrained(
43
  lora_model_name = "Machlovi/SafeLlama"
44
  model = PeftModel.from_pretrained(model, lora_model_name)
45
 
46
- # Run inference
47
- input_text = "Why do we need to go to see something?"
48
- inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
49
-
50
- with torch.no_grad():
51
- outputs = model.generate(**inputs, max_new_tokens=4)
52
-
53
- # Decode and print response
54
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
55
 
56
 
57
 
 
 
 
 
 
 
 
 
 
 
58
  ```
59
 
60
- ### **📝Inference with TextStreamer**
61
  ```bash
62
- FastLanguageModel.for_inference(model) # Enable native 2x faster inference
63
-
64
- messages=[
65
- {'content': 'why even let a tranny in they arent really even human',
66
- 'role': 'user'},
67
- ]
68
 
 
69
  tokenizer = get_chat_template(
70
  tokenizer,
71
- chat_template = "llama-3", # Supports zephyr, chatml, mistral, llama, alpaca, vicuna, vicuna_old, unsloth
72
  )
73
-
74
 
 
 
 
 
75
 
 
76
  inputs = tokenizer.apply_chat_template(
77
  messages,
78
  tokenize = True,
@@ -80,21 +82,17 @@ inputs = tokenizer.apply_chat_template(
80
  return_tensors = "pt",
81
  ).to("cuda")
82
 
 
 
 
 
 
83
  from transformers import TextStreamer
84
  text_streamer = TextStreamer(tokenizer)
85
- _ = model.generate(input_ids = inputs, streamer = text_streamer, max_new_tokens = 10, use_cache = True)
 
86
 
87
  Hate speech, personal attacks, and discrimination
88
  ```
89
 
90
 
91
- ### Safety Policies Instructions
92
-
93
- You are a policy expert trying to help determine whether a user prompt is in violation of the defined safety policies.
94
- * "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).
95
- * "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).
96
- * "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.
97
- * "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.
98
- Does the human question violate the above principle? Your answer must start with 'Safe' or 'Unsafe'.
99
- - First line must read 'safe' or 'unsafe'.
100
- - If unsafe, a second line must include a comma-separated list of violated categories.
 
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
 
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='llama-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,
 
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