Upload 3 files
Browse files- config (1).json +29 -0
- handler (1).py +33 -0
- requirements (2).txt +7 -0
config (1).json
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "tiiuae/falcon-7b-instruct",
|
3 |
+
"alibi": false,
|
4 |
+
"apply_residual_connection_post_layernorm": false,
|
5 |
+
"architectures": [
|
6 |
+
"RWForCausalLM"
|
7 |
+
],
|
8 |
+
"attention_dropout": 0.0,
|
9 |
+
"auto_map": {
|
10 |
+
"AutoConfig": "configuration_RW.RWConfig",
|
11 |
+
"AutoModelForCausalLM": "modelling_RW.RWForCausalLM"
|
12 |
+
},
|
13 |
+
"bias": false,
|
14 |
+
"bos_token_id": 11,
|
15 |
+
"eos_token_id": 11,
|
16 |
+
"hidden_dropout": 0.0,
|
17 |
+
"hidden_size": 4544,
|
18 |
+
"initializer_range": 0.02,
|
19 |
+
"layer_norm_epsilon": 1e-05,
|
20 |
+
"model_type": "RefinedWebModel",
|
21 |
+
"multi_query": true,
|
22 |
+
"n_head": 71,
|
23 |
+
"n_layer": 32,
|
24 |
+
"parallel_attn": true,
|
25 |
+
"torch_dtype": "bfloat16",
|
26 |
+
"transformers_version": "4.27.4",
|
27 |
+
"use_cache": true,
|
28 |
+
"vocab_size": 65024
|
29 |
+
}
|
handler (1).py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
|
3 |
+
from typing import Any, Dict
|
4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
+
|
6 |
+
|
7 |
+
class EndpointHandler:
|
8 |
+
def __init__(self, path=""):
|
9 |
+
# load model and tokenizer from path
|
10 |
+
self.tokenizer = AutoTokenizer.from_pretrained(path)
|
11 |
+
self.model = AutoModelForCausalLM.from_pretrained(
|
12 |
+
path, device_map="auto", torch_dtype=torch.float16, trust_remote_code=True
|
13 |
+
)
|
14 |
+
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
15 |
+
|
16 |
+
def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
|
17 |
+
# process input
|
18 |
+
inputs = data.pop("inputs", data)
|
19 |
+
parameters = data.pop("parameters", None)
|
20 |
+
|
21 |
+
# preprocess
|
22 |
+
inputs = self.tokenizer(inputs, return_tensors="pt").to(self.device)
|
23 |
+
|
24 |
+
# pass inputs with all kwargs in data
|
25 |
+
if parameters is not None:
|
26 |
+
outputs = self.model.generate(**inputs, **parameters)
|
27 |
+
else:
|
28 |
+
outputs = self.model.generate(**inputs)
|
29 |
+
|
30 |
+
# postprocess the prediction
|
31 |
+
prediction = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
32 |
+
|
33 |
+
return [{"generated_text": prediction}]
|
requirements (2).txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
bitsandbytes==0.39.0
|
2 |
+
torch==2.0.1
|
3 |
+
transformers==4.30.2
|
4 |
+
accelerate==0.20.3
|
5 |
+
loralib==0.1.1
|
6 |
+
einops==0.6.1
|
7 |
+
|