Jay24-AI commited on
Commit
dd35727
·
verified ·
1 Parent(s): a720bda

updating the inference section

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