Laurie commited on
Commit
167fced
·
1 Parent(s): 3f2394e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +15 -2
README.md CHANGED
@@ -4,7 +4,9 @@ I use the 50k [Chinese data](https://huggingface.co/datasets/Chinese-Vicuna/inst
4
 
5
  from transformers import LlamaForCausalLM, LlamaTokenizer
6
  from peft import PeftModel
7
-
 
 
8
  tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
9
 
10
  model = LlamaForCausalLM.from_pretrained(
@@ -15,7 +17,18 @@ I use the 50k [Chinese data](https://huggingface.co/datasets/Chinese-Vicuna/inst
15
  )
16
  model = PeftModel.from_pretrained(
17
  model,
18
- "Laurie/lora-instruct-chat-50k-cn-en"
19
  torch_dtype=torch.float16,
20
  device_map={'': 0}
21
  )
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  from transformers import LlamaForCausalLM, LlamaTokenizer
6
  from peft import PeftModel
7
+ import torch
8
+
9
+
10
  tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
11
 
12
  model = LlamaForCausalLM.from_pretrained(
 
17
  )
18
  model = PeftModel.from_pretrained(
19
  model,
20
+ "Laurie/lora-instruct-chat-50k-cn-en",
21
  torch_dtype=torch.float16,
22
  device_map={'': 0}
23
  )
24
+
25
+ device = "cuda" if torch.cuda.is_available() else "cpu"
26
+
27
+ inputs = tokenizer("什么是自然语言处理?",return_tensors="pt" )
28
+
29
+ model.to(device)
30
+
31
+ with torch.no_grad():
32
+ inputs = {k: v.to(device) for k, v in inputs.items()}
33
+ outputs = model.generate(input_ids=inputs["input_ids"], max_new_tokens=129)
34
+ print(tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True))