File size: 808 Bytes
034457d
7d4aad0
bb6d908
034457d
 
 
 
dd0166e
034457d
 
 
 
 
c709ed6
034457d
 
dd0166e
034457d
 
 
 
dd0166e
034457d
 
 
 
 
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
28
from typing import Any, Dict
from transformers import AutoTokenizer, AutoModel
import torch


class EndpointHandler:
    def __init__(self, model_dir: str, **kwargs: Any) -> None:
        self.model = AutoModel.from_pretrained(
            model_dir,
            torch_dtype=torch.bfloat16,
            low_cpu_mem_usage=True,
            use_flash_attn=False,
            trust_remote_code=True,
            device_map="auto",
        ).eval()

        self.tokenizer = AutoTokenizer.from_pretrained(
            model_dir, trust_remote_code=True, use_fast=False
        )

    def __call__(self, data: Dict[str, Any]) -> Any:
        logger.info(f"Received incoming request with {data=}")


if __name__ == "__main__":
    handler = EndpointHandler(model_dir="GSAI-ML/LLaDA-8B-Instruct")
    print(handler)