Jay24-AI commited on
Commit
df3fcee
·
verified ·
1 Parent(s): a60f2a8

updating the inference example

Browse files
Files changed (1) hide show
  1. README.md +14 -16
README.md CHANGED
@@ -56,26 +56,24 @@ Users should:
56
  ## How to Get Started with the Model
57
 
58
  ```python
59
- from transformers import AutoTokenizer, AutoModelForCausalLM
60
- from peft import PeftModel
61
  import torch
 
 
62
 
63
  peft_model_id = "Jay24-AI/bloom-7b1-lora-tagger"
64
- tokenizer = AutoTokenizer.from_pretrained("bigscience/bloom-7b1")
65
- base_model = AutoModelForCausalLM.from_pretrained(
66
- "bigscience/bloom-7b1",
67
- load_in_8bit=True,
68
- device_map="auto"
69
- )
70
-
71
- # Load LoRA adapters
72
- model = PeftModel.from_pretrained(base_model, peft_model_id)
73
-
74
- prompt = "“Training models with PEFT and LoRa is cool” ->: "
75
- inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
76
  with torch.cuda.amp.autocast():
77
- outputs = model.generate(**inputs, max_new_tokens=50)
78
- print(tokenizer.decode(outputs[0], skip_special_tokens=True))
 
79
  ```
80
 
81
  ## Training Details
 
56
  ## How to Get Started with the Model
57
 
58
  ```python
 
 
59
  import torch
60
+ from peft import PeftModel, PeftConfig
61
+ from transformers import AutoModelForCausalLM, AutoTokenizer
62
 
63
  peft_model_id = "Jay24-AI/bloom-7b1-lora-tagger"
64
+ config = PeftConfig.from_pretrained(peft_model_id)
65
+ model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=True, device_map='auto')
66
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
67
+
68
+ # Load the Lora model
69
+ model = PeftModel.from_pretrained(model, peft_model_id)
70
+
71
+ batch = tokenizer("“The only way to do great work is to love what you do.” ->: ", return_tensors='pt')
72
+
 
 
 
73
  with torch.cuda.amp.autocast():
74
+ output_tokens = model.generate(**batch, max_new_tokens=50)
75
+
76
+ print('\n\n', tokenizer.decode(output_tokens[0], skip_special_tokens=True))
77
  ```
78
 
79
  ## Training Details