Summarization
PEFT
Safetensors
Ukrainian
dpo
SGaleshchuk commited on
Commit
b6ffd4b
1 Parent(s): 6712069

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -14
README.md CHANGED
@@ -36,33 +36,53 @@ This model is a fine-tuned version of [SGaleshchuk/Llama-2-13b-hf_uk_rank-32_ft]
36
 
37
  ## Intended uses & limitations
38
  ```python
 
 
 
 
39
  # unpatch flash attention
 
40
  from peft import AutoPeftModelForCausalLM
41
  from transformers import AutoTokenizer
42
 
 
 
43
  # load base LLM model and tokenizer
44
  model = AutoPeftModelForCausalLM.from_pretrained(
45
- "SGaleshchuk/Llama-2-13b-summarization_uk_dpo",
46
  low_cpu_mem_usage=True,
47
  torch_dtype=torch.float16,
48
  load_in_4bit=True)
49
 
50
- tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
 
 
 
51
 
52
- for instruct, summary in zip(val_instructions, tqdm(summaries)):
53
- input_ids = tokenizer(
54
- instruct, return_tensors="pt", truncation=True).input_ids.cuda()
 
 
 
 
 
55
  with torch.inference_mode():
56
- outputs = model.generate(
57
- input_ids=input_ids,
58
- max_new_tokens=128,
59
- do_sample=True,
60
- top_p=0.9,
61
- temperature=1e-2,
62
  )
63
- result = tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0]
64
- result = result[len(instruct) :]
65
- print(result)
 
 
 
 
 
66
  ```
67
 
68
  ## Training procedure
 
36
 
37
  ## Intended uses & limitations
38
  ```python
39
+ # tested with colab+A100 GPU
40
+ !pip install -q -U peft transformers==4.30
41
+ !pip install flash-attn --no-build-isolation
42
+ !pip install einops bitsandbytes accelerate
43
  # unpatch flash attention
44
+ import torch
45
  from peft import AutoPeftModelForCausalLM
46
  from transformers import AutoTokenizer
47
 
48
+ model_id = "SGaleshchuk/Llama-2-13b-summarization_uk_dpo"
49
+
50
  # load base LLM model and tokenizer
51
  model = AutoPeftModelForCausalLM.from_pretrained(
52
+ model_id,
53
  low_cpu_mem_usage=True,
54
  torch_dtype=torch.float16,
55
  load_in_4bit=True)
56
 
57
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
58
+
59
+ def prepare_instruction(text):
60
+
61
 
62
+ prompt = """The article to summarize in maximum 100 words:{text}. Summary:""" # adapt to your needs
63
+
64
+ return prompt.format(
65
+ text=text,
66
+ )
67
+ def summarization(text):
68
+ instruction = prepare_instruction(text)
69
+ input_ids = tokenizer(instruction, return_tensors="pt", truncation=True).input_ids.cuda()
70
  with torch.inference_mode():
71
+ outputs = model.generate(
72
+ input_ids=input_ids,
73
+ max_new_tokens=128,
74
+ do_sample=True,
75
+ top_p=0.9,
76
+ temperature=1e-2,
77
  )
78
+ result = tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0]
79
+ result = result[len(instruction) :]
80
+ print(result)
81
+ return result
82
+
83
+ text = """your text here to summarize"
84
+ result = summarization(text)
85
+
86
  ```
87
 
88
  ## Training procedure