zhenggq commited on
Commit
7be09ca
1 Parent(s): 2c096fd

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +37 -0
README.md CHANGED
@@ -98,6 +98,43 @@ analysis is needed to assess potential harm or bias in the proposed application.
98
 
99
  ## Getting started with Orca 2
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  **Safe inference with Azure AI Content Safety**
102
 
103
  The usage of [Azure AI Content Safety](https://azure.microsoft.com/en-us/products/ai-services/ai-content-safety/) on top of model prediction is strongly encouraged
 
98
 
99
  ## Getting started with Orca 2
100
 
101
+ **Inference with Hugging Face library**
102
+
103
+ ```python
104
+ import transformers
105
+ import torch
106
+
107
+ model_path = 'microsoft/Orca-2-13b'
108
+ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
109
+ model = transformers.AutoModelForCausalLM.from_pretrained(model_path)
110
+ model.to(device)
111
+
112
+ tokenizer = transformers.AutoTokenizer.from_pretrained(
113
+ model_path,
114
+ model_max_length=4096,
115
+ padding_side="right",
116
+ use_fast=False,
117
+ add_special_tokens=False,
118
+ )
119
+
120
+ system_message = "You are Orca, an AI language model created by Microsoft. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior."
121
+ user_message = "\" \n :You can't just say, \"\"that's crap\"\" and remove it without gaining a consensus. You already know this, based on your block history. —/ \" \nIs the comment obscene? \nOptions : Yes, No."
122
+
123
+ # We use Chat Markup Language https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/ai-services/openai/includes/chat-markup-language.md#working-with-chat-markup-language-chatml
124
+ prompt = f"<|im_start|>system\n{system_message}<|im_end|>\n<|im_start|>user\n{user_message}<|im_end|>\n<|im_start|>assistant"
125
+
126
+ inputs = tokenizer(prompt, return_tensors='pt')
127
+ inputs = inputs.to(device)
128
+
129
+ output_ids = model.generate(inputs["input_ids"], max_length=4096, do_sample=False, temperature=0.0, use_cache=True)
130
+ sequence_length = inputs["input_ids"].shape[1]
131
+ new_output_ids = output_ids[:, sequence_length:]
132
+ answers = tokenizer.batch_decode(new_output_ids, skip_special_tokens=True)
133
+
134
+ print(answers)
135
+ ```
136
+
137
+
138
  **Safe inference with Azure AI Content Safety**
139
 
140
  The usage of [Azure AI Content Safety](https://azure.microsoft.com/en-us/products/ai-services/ai-content-safety/) on top of model prediction is strongly encouraged