ChirathD commited on
Commit
3115ce7
1 Parent(s): ebcbd5a

Create handler.py

Browse files
Files changed (1) hide show
  1. handler.py +29 -0
handler.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Any
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, GemmaTokenizer
3
+ import torch
4
+ from peft import PeftModel
5
+ import json
6
+ import os
7
+
8
+ class EndpointHandler():
9
+ def __init__(self, path=""):
10
+
11
+ bnb_config = BitsAndBytesConfig(
12
+ load_in_8bit=True,
13
+ bnb_8bit_quant_type="nf4",
14
+ bnb_8bit_compute_dtype=torch.bfloat16
15
+ )
16
+
17
+ tokenizer = AutoTokenizer.from_pretrained('LexiconShiftInnovations/Gemma_Dental_it_07_merged')
18
+ model = AutoModelForCausalLM.from_pretrained('LexiconShiftInnovations/Gemma_Dental_it_07_merged', quantization_config=bnb_config, device_map={"":0})
19
+
20
+ self.pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
21
+
22
+ def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
23
+ inputs = data.pop("inputs", data)
24
+ parameters = data.pop("parameters", None)
25
+ if parameters is not None:
26
+ prediction = self.pipeline(inputs, **parameters)
27
+ else:
28
+ prediction = self.pipeline(inputs)
29
+ return prediction