mjbuehler commited on
Commit
7fbe908
·
verified ·
1 Parent(s): 14ff717

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +14 -53
README.md CHANGED
@@ -48,65 +48,26 @@ llm = Llama.from_pretrained(
48
  ```
49
  For inference:
50
  ```
51
- def generate_response (model,tokenizer,text_input="Biology offers amazing possibilities, especially for",
52
- num_return_sequences=1,
53
- temperature=1., #the higher the temperature, the more creative the model becomes
54
- max_new_tokens=127,
55
- num_beams=1,
56
- top_k = 50,
57
- top_p =0.9,repetition_penalty=1.,eos_token_id=2,verbatim=False,
58
- exponential_decay_length_penalty_fac=None,add_special_tokens =True,
59
- ):
60
- inputs = tokenizer(text_input, add_special_tokens = add_special_tokens, return_tensors ='pt').to(device)
61
-
62
- with torch.no_grad():
63
-
64
- outputs = model.generate (input_ids = inputs["input_ids"],
65
- attention_mask = inputs["attention_mask"] , # This is usually done automatically by the tokenizer
66
- max_new_tokens=max_new_tokens,
67
- temperature=temperature, #value used to modulate the next token probabilities.
68
- num_beams=num_beams,
69
- top_k = top_k,
70
- top_p = top_p,
71
- num_return_sequences = num_return_sequences,
72
- eos_token_id=eos_token_id,
73
- pad_token_id = eos_token_id,
74
- do_sample =True,#skip_prompt=True,
75
- repetition_penalty=repetition_penalty,
76
- )
77
-
78
- return tokenizer.batch_decode(outputs[:,inputs["input_ids"].shape[1]:].detach().cpu().numpy(), skip_special_tokens=True)
79
-
80
- def generate_BioMixtral (system_prompt='You a helpful assistant. You are familiar with materials science, especially biological and bioinspired materials. ',
81
- prompt='What is spider silk in the context of bioinspired materials?',
82
- repetition_penalty=1.,
83
- top_p=0.9, top_k=256,
84
- temperature=0.5, max_tokens=512, verbatim=False, eos_token=None,
85
- prepend_response='',
86
- ):
87
-
88
- if eos_token==None:
89
- eos_token= tokenizer.eos_token_id
90
 
91
  if system_prompt==None:
92
- messages=[
93
  {"role": "user", "content": prompt},
94
  ]
95
  else:
96
- messages=[
97
- {"role": "system", "content": system_prompt},
98
- {"role": "user", "content": prompt},
99
  ]
100
- txt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True,
101
- )
102
- txt=txt+prepend_response
103
-
104
- output_text=generate_response (model,tokenizer,text_input=txt,eos_token_id=eos_token,
105
- num_return_sequences=1, repetition_penalty=repetition_penalty,
106
- top_p=top_p, top_k=top_k,
107
- temperature=temperature,max_new_tokens=max_tokens, verbatim=verbatim,
108
- )
109
- return output_text[0]
110
 
111
  start_time = time.time()
112
  result=generate_BioMixtral(system_prompt='You respond accurately.',
 
48
  ```
49
  For inference:
50
  ```
51
+ def generate_BioMixtral (system_prompt='You are an expert in biological materials, mechanics and related topics.', prompt="What is spider silk?",
52
+ temperature=0.0,
53
+ max_tokens=10000,
54
+ ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  if system_prompt==None:
57
+ messages=[
58
  {"role": "user", "content": prompt},
59
  ]
60
  else:
61
+ messages=[
62
+ {"role": "system", "content": system_prompt},
63
+ {"role": "user", "content": prompt},
64
  ]
65
+
66
+ result=llm.create_chat_completion(
67
+ messages=messages,
68
+ temperature=temperature,
69
+ max_tokens=max_tokens,
70
+ )
 
 
 
 
71
 
72
  start_time = time.time()
73
  result=generate_BioMixtral(system_prompt='You respond accurately.',