File size: 1,013 Bytes
bf8239b
d153763
d9df443
bf8239b
 
 
d153763
 
3a11bbd
 
3290446
3a11bbd
d153763
808f94c
bf8239b
 
 
 
 
 
 
 
 
149288b
bf8239b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from typing import Dict, List, Any
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
import torch

class EndpointHandler():
    def __init__(self, path=""):

        model_name = "microsoft/Phi-3.5-mini-instruct"
        device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        
        tokenizer = AutoTokenizer.from_pretrained(model_name)
        model = AutoModelForCausalLM.from_pretrained(model_name,torch_dtype=torch.float16).to(device)
        model.load_adapter("cafierom/Phi-3.5-mini-instruct-Gen-TF-Mottos")
        self.pipeline = pipeline("text-generation",model=model, tokenizer=tokenizer)

    def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
        """
        data args:
            inputs (:obj: `str`)
        Return:
            A :obj:`list` | `dict`: will be serialized and returned
        """
        inputs = data.pop("inputs",data)
        #inputs.to(device)
        prediction = self.pipeline(inputs)
        return prediction