checkiejan commited on
Commit
bf44938
1 Parent(s): e989aa6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +37 -1
README.md CHANGED
@@ -8,7 +8,43 @@ tags: []
8
  <!-- Provide a quick summary of what the model is/does. -->
9
 
10
 
11
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ## Model Details
13
 
14
  ### Model Description
 
8
  <!-- Provide a quick summary of what the model is/does. -->
9
 
10
 
11
+ # How to Get Started with the Model
12
+ To load and use this model with the Transformers library by Hugging Face, follow the steps outlined in the code snippet below. This code demonstrates how to configure the model, load it along with its tokenizer, and perform inference to generate text based on a given prompt.
13
+
14
+ ## Code Format:
15
+ ```python
16
+ from peft import PeftModel, PeftConfig
17
+
18
+ test_config = PeftConfig.from_pretrained("checkiejan/phi2-marking-test-full")
19
+ model_base = AutoModelForCausalLM.from_pretrained(
20
+ test_config.base_model_name_or_path,
21
+ device_map="auto",
22
+ quantization_config=BitsAndBytesConfig(
23
+ load_in_4bit=True,
24
+ bnb_4bit_compute_dtype=torch.bfloat16,
25
+ bnb_4bit_quant_type="nf4",
26
+ ),
27
+ torch_dtype=torch.bfloat16,
28
+ trust_remote_code=True,
29
+ )
30
+ tokenizer = AutoTokenizer.from_pretrained(test_config.base_model_name_or_path)
31
+
32
+ # Add/set tokens same tokens to base model before merging, like we did before starting training
33
+ tokenizer.add_tokens(["<|im_start|>", "<PAD>"])
34
+ tokenizer.pad_token = "<PAD>"
35
+ tokenizer.add_special_tokens(dict(eos_token="<|im_end|>"))
36
+ model_base.resize_token_embeddings(
37
+ new_num_tokens=len(tokenizer),
38
+ pad_to_multiple_of=64) # phi2 default is 64, see configuration_phi.py
39
+ model_base.config.eos_token_id = tokenizer.eos_token_id
40
+ lora_model = PeftModel.from_pretrained(model_base, "checkiejan/phi2-marking-test-full")
41
+
42
+ inputs = tokenizer(prompt, return_tensors="pt", return_attention_mask=True)
43
+ outputs = lora_model.generate(**inputs)
44
+ text = tokenizer.batch_decode(outputs, skip_special_tokens=True)
45
+ print(''.join(text))
46
+ ```
47
+ This code snippet sets up the model and tokenizer, configures the necessary parameters, and demonstrates how to generate text based on a given prompt. Ensure to replace "Your prompt here" with your actual input text.
48
  ## Model Details
49
 
50
  ### Model Description