Zigeng commited on
Commit
7a63a4b
·
verified ·
1 Parent(s): 7902b26

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +52 -19
README.md CHANGED
@@ -73,26 +73,59 @@ dParallel-Dream-Distill Dataset</a></td>
73
 
74
  ## 🚀 Quick Start:
75
  ```python
76
- from transformers import AutoTokenizer
77
- from model.modeling_llada import LLaDAModelLM
78
- from generate import generate
79
  import torch
80
-
81
- device = 'cuda'
82
- model = LLaDAModelLM.from_pretrained('Zigeng/dParallel-LLaDA-8B-instruct', trust_remote_code=True, torch_dtype=torch.bfloat16).to(device).eval()
83
- tokenizer = AutoTokenizer.from_pretrained('Zigeng/dParallel-LLaDA-8B-instruct', trust_remote_code=True)
84
-
85
- prompt = "Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May? Please reason step by step, and put your final answer within \\boxed{}."
86
-
87
- m = [{"role": "user", "content": prompt}, ]
88
- prompt = tokenizer.apply_chat_template(m, add_generation_prompt=True, tokenize=False)
89
-
90
- input_ids = tokenizer(prompt)['input_ids']
91
- input_ids = torch.tensor(input_ids).to(device).unsqueeze(0)
92
-
93
- out = generate(model, input_ids, steps=256, gen_length=256, block_length=32, temperature=0., threshold=0.5,remasking='low_confidence')
94
- print("Response:",tokenizer.batch_decode(out[0][:, input_ids.shape[1]:], skip_special_tokens=True)[0])
95
- print("NFE:",out[1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  ```
97
 
98
 
 
73
 
74
  ## 🚀 Quick Start:
75
  ```python
 
 
 
76
  import torch
77
+ from transformers import AutoModel, AutoTokenizer
78
+ import types
79
+
80
+ model_path = "Zigeng/dParallel_Dream_7B_Instruct"
81
+ model = AutoModel.from_pretrained(model_path, torch_dtype=torch.bfloat16, trust_remote_code=True)
82
+ tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
83
+ model = model.to("cuda").eval()
84
+
85
+ from model.generation_utils_semiar import DreamGenerationMixin
86
+ model.diffusion_generate = types.MethodType(DreamGenerationMixin.diffusion_generate, model)
87
+ model._sample = types.MethodType(DreamGenerationMixin._sample, model)
88
+
89
+
90
+ messages = [
91
+ {"role": "user", "content": "Toulouse has twice as many sheep as Charleston. Charleston has 4 times as many sheep as Seattle. How many sheep do Toulouse, Charleston, and Seattle have together if Seattle has 20 sheep? Let's think step by step."}
92
+ ]
93
+
94
+ inputs = tokenizer.apply_chat_template(
95
+ messages,
96
+ tokenize=False,
97
+ add_generation_prompt=True
98
+ )
99
+
100
+ inputs = tokenizer.apply_chat_template(
101
+ messages, return_tensors="pt", return_dict=True, add_generation_prompt=True
102
+ )
103
+ input_ids = inputs.input_ids.to(device="cuda")
104
+ attention_mask = inputs.attention_mask.to(device="cuda")
105
+
106
+ output, nfe = model.diffusion_generate(
107
+ input_ids,
108
+ attention_mask=attention_mask,
109
+ max_new_tokens=256,
110
+ output_history=False,
111
+ return_dict_in_generate=True,
112
+ steps=256,
113
+ temperature=0.,
114
+ top_p=None,
115
+ alg="entropy_threshold",
116
+ alg_temp=0.1,
117
+ top_k=None,
118
+ block_length=32,
119
+ threshold=0.5,
120
+ )
121
+
122
+ generations = [
123
+ tokenizer.decode(g[0:].tolist())
124
+ for p, g in zip(input_ids, output.sequences)
125
+ ]
126
+
127
+ print(generations[0].split(tokenizer.eos_token)[0])
128
+ print("NFE:", nfe)
129
  ```
130
 
131