yujiepan commited on
Commit
5bcb322
·
verified ·
1 Parent(s): 54ec24f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -0
README.md CHANGED
@@ -10,6 +10,40 @@ widget:
10
 
11
  This model is for debugging. It is randomly initialized with the config from [deepseek-ai/DeepSeek-V3](https://huggingface.co/deepseek-ai/DeepSeek-V3) but is of smaller size.
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  Codes:
14
  ```python
15
  import os
 
10
 
11
  This model is for debugging. It is randomly initialized with the config from [deepseek-ai/DeepSeek-V3](https://huggingface.co/deepseek-ai/DeepSeek-V3) but is of smaller size.
12
 
13
+ Usage:
14
+ ```python
15
+ import torch
16
+ from transformers import AutoModelForCausalLM, AutoTokenizer
17
+
18
+ model_id = "yujiepan/deepseek-v3-tiny-random"
19
+ device = torch.device("cuda")
20
+
21
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
22
+ model = AutoModelForCausalLM.from_pretrained(
23
+ model_id, trust_remote_code=True,
24
+ ).eval().to(device)
25
+
26
+ prompt = 'Hello!'
27
+ messages = [
28
+ {"role": "system", "content": "You are a helpful assistant."},
29
+ {"role": "user", "content": prompt}
30
+ ]
31
+
32
+ inputs = tokenizer.apply_chat_template(
33
+ messages, tokenize=True, add_generation_prompt=True, return_tensors="pt"
34
+ ).to(device)
35
+
36
+ with torch.inference_mode():
37
+ outputs = model.generate(
38
+ inputs,
39
+ max_new_tokens=16,
40
+ do_sample=False,
41
+ use_cache=True,
42
+ )
43
+ string = tokenizer.decode(outputs[0])
44
+ print(string)
45
+ ```
46
+
47
  Codes:
48
  ```python
49
  import os