Views
No views yet
1# setup [autoawq](https://github.com/casper-hansen/AutoAWQ)
2from awq import AutoAWQForCausalLM
3from transformers import AutoTokenizer, TextStreamer
4
5quant_path = "aari1995/germeo-7b-awq"
6
7# Load model
8model = AutoAWQForCausalLM.from_quantized(quant_path, fuse_layers=True)
9tokenizer = AutoTokenizer.from_pretrained(quant_path, trust_remote_code=True)1# pip install [autoawq](https://github.com/casper-hansen/AutoAWQ) and pip install --upgrade transformers
2from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
3
4quant_path = "aari1995/germeo-7b-awq"
5
6# Load model
7model = AutoModelForCausalLM.from_pretrained(quant_path, device_map="auto")
8tokenizer = AutoTokenizer.from_pretrained(quant_path, trust_remote_code=True)1streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
2
3# Convert prompt to tokens
4prompt_template = """<|im_start|>system
5Du bist ein hilfreicher Assistent.<|im_end|>
6<|im_start|>user
7{prompt}<|im_end|>
8<|im_start|>assistant"""
9
10prompt = "Schreibe eine Stellenanzeige für Data Scientist bei AXA!"
11
12tokens = tokenizer(
13 prompt_template.format(prompt=prompt),
14 return_tensors='pt'
15).input_ids.cuda()
16
17# Generate output
18generation_output = model.generate(
19 tokens,
20 streamer=streamer,
21 max_new_tokens=1012
22)
23# tokenizer.decode(generation_output.flatten())1from transformers import StoppingCriteria
2class GermeoStoppingCriteria(StoppingCriteria):
3 def __init__(self, target_sequence, prompt):
4 self.target_sequence = target_sequence
5 self.prompt=prompt
6
7 def __call__(self, input_ids, scores, **kwargs):
8 # Get the generated text as a string
9 generated_text = tokenizer.decode(input_ids[0])
10 generated_text = generated_text.replace(self.prompt,'')
11 # Check if the target sequence appears in the generated text
12 if self.target_sequence in generated_text:
13 return True # Stop generation
14
15 return False # Continue generation
16
17 def __len__(self):
18 return 1
19
20 def __iter__(self):
21 yield self1generation_output = model.generate(
2 tokens,
3 streamer=streamer,
4 max_new_tokens=1012,
5 stopping_criteria=GermeoStoppingCriteria("<|im_end|>", prompt_template.format(prompt=prompt))
6)| German tasks: | MMLU-DE | Hellaswag-DE | ARC-DE | Average |
|---|---|---|---|---|
| Models / Few-shots: | (5 shots) | (10 shots) | (24 shots) | |
| 7B parameters | ||||
| llama-2-7b | 0.400 | 0.513 | 0.381 | 0.431 |
| leo-hessianai-7b | 0.400 | 0.609 | 0.429 | 0.479 |
| bloom-6b4-clp-german | 0.274 | 0.550 | 0.351 | 0.392 |
| mistral-7b | 0.524 | 0.588 | 0.473 | 0.528 |
| leo-mistral-hessianai-7b | 0.481 | 0.663 | 0.485 | 0.543 |
| leo-mistral-hessianai-7b-chat | 0.458 | 0.617 | 0.465 | 0.513 |
| DPOpenHermes-7B-v2 | 0.517 | 0.603 | 0.515 | 0.545 |
| hermeo-7b | 0.511 | 0.668 | 0.528 | 0.569 |
| germeo-7b-awq (this model) | 0.522 | 0.651 | 0.514 | 0.563 |
| 13B parameters | ||||
| llama-2-13b | 0.469 | 0.581 | 0.468 | 0.506 |
| leo-hessianai-13b | 0.486 | 0.658 | 0.509 | 0.551 |
| 70B parameters | ||||
| llama-2-70b | 0.597 | 0.674 | 0.561 | 0.611 |
| leo-hessianai-70b | 0.653 | 0.721 | 0.600 | 0.658 |
| Models: | German Response Rate |
|---|---|
| hermeo-7b | tba |
| germeo-7b-awq (this model) | tba |