remove handler
#2
by
booksouls - opened
- 4-bit/config.json +85 -0
- 4-bit/generation_config.json +16 -0
- 4-bit/model.safetensors +3 -0
- handler.py +43 -0
4-bit/config.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "bart-large-cnn",
|
| 3 |
+
"_num_labels": 3,
|
| 4 |
+
"activation_dropout": 0.0,
|
| 5 |
+
"activation_function": "gelu",
|
| 6 |
+
"add_final_layer_norm": false,
|
| 7 |
+
"architectures": [
|
| 8 |
+
"BartForConditionalGeneration"
|
| 9 |
+
],
|
| 10 |
+
"attention_dropout": 0.0,
|
| 11 |
+
"bos_token_id": 0,
|
| 12 |
+
"classif_dropout": 0.0,
|
| 13 |
+
"classifier_dropout": 0.0,
|
| 14 |
+
"d_model": 1024,
|
| 15 |
+
"decoder_attention_heads": 16,
|
| 16 |
+
"decoder_ffn_dim": 4096,
|
| 17 |
+
"decoder_layerdrop": 0.0,
|
| 18 |
+
"decoder_layers": 12,
|
| 19 |
+
"decoder_start_token_id": 2,
|
| 20 |
+
"dropout": 0.1,
|
| 21 |
+
"early_stopping": true,
|
| 22 |
+
"encoder_attention_heads": 16,
|
| 23 |
+
"encoder_ffn_dim": 4096,
|
| 24 |
+
"encoder_layerdrop": 0.0,
|
| 25 |
+
"encoder_layers": 12,
|
| 26 |
+
"eos_token_id": 2,
|
| 27 |
+
"force_bos_token_to_be_generated": true,
|
| 28 |
+
"forced_bos_token_id": 0,
|
| 29 |
+
"forced_eos_token_id": 2,
|
| 30 |
+
"gradient_checkpointing": false,
|
| 31 |
+
"id2label": {
|
| 32 |
+
"0": "LABEL_0",
|
| 33 |
+
"1": "LABEL_1",
|
| 34 |
+
"2": "LABEL_2"
|
| 35 |
+
},
|
| 36 |
+
"init_std": 0.02,
|
| 37 |
+
"is_encoder_decoder": true,
|
| 38 |
+
"label2id": {
|
| 39 |
+
"LABEL_0": 0,
|
| 40 |
+
"LABEL_1": 1,
|
| 41 |
+
"LABEL_2": 2
|
| 42 |
+
},
|
| 43 |
+
"length_penalty": 2.0,
|
| 44 |
+
"max_length": 256,
|
| 45 |
+
"max_position_embeddings": 1024,
|
| 46 |
+
"min_length": 56,
|
| 47 |
+
"model_type": "bart",
|
| 48 |
+
"no_repeat_ngram_size": 3,
|
| 49 |
+
"normalize_before": false,
|
| 50 |
+
"num_beams": 4,
|
| 51 |
+
"num_hidden_layers": 12,
|
| 52 |
+
"output_past": true,
|
| 53 |
+
"pad_token_id": 1,
|
| 54 |
+
"prefix": " ",
|
| 55 |
+
"quantization_config": {
|
| 56 |
+
"_load_in_4bit": true,
|
| 57 |
+
"_load_in_8bit": false,
|
| 58 |
+
"bnb_4bit_compute_dtype": "bfloat16",
|
| 59 |
+
"bnb_4bit_quant_storage": "uint8",
|
| 60 |
+
"bnb_4bit_quant_type": "fp4",
|
| 61 |
+
"bnb_4bit_use_double_quant": false,
|
| 62 |
+
"llm_int8_enable_fp32_cpu_offload": false,
|
| 63 |
+
"llm_int8_has_fp16_weight": false,
|
| 64 |
+
"llm_int8_skip_modules": null,
|
| 65 |
+
"llm_int8_threshold": 6.0,
|
| 66 |
+
"load_in_4bit": true,
|
| 67 |
+
"load_in_8bit": false,
|
| 68 |
+
"quant_method": "bitsandbytes"
|
| 69 |
+
},
|
| 70 |
+
"scale_embedding": false,
|
| 71 |
+
"task_specific_params": {
|
| 72 |
+
"summarization": {
|
| 73 |
+
"early_stopping": true,
|
| 74 |
+
"length_penalty": 2.0,
|
| 75 |
+
"max_length": 142,
|
| 76 |
+
"min_length": 56,
|
| 77 |
+
"no_repeat_ngram_size": 3,
|
| 78 |
+
"num_beams": 4
|
| 79 |
+
}
|
| 80 |
+
},
|
| 81 |
+
"torch_dtype": "float16",
|
| 82 |
+
"transformers_version": "4.41.2",
|
| 83 |
+
"use_cache": true,
|
| 84 |
+
"vocab_size": 50264
|
| 85 |
+
}
|
4-bit/generation_config.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 0,
|
| 4 |
+
"decoder_start_token_id": 2,
|
| 5 |
+
"early_stopping": true,
|
| 6 |
+
"eos_token_id": 2,
|
| 7 |
+
"forced_bos_token_id": 0,
|
| 8 |
+
"forced_eos_token_id": 2,
|
| 9 |
+
"length_penalty": 2.0,
|
| 10 |
+
"max_length": 256,
|
| 11 |
+
"min_length": 56,
|
| 12 |
+
"no_repeat_ngram_size": 3,
|
| 13 |
+
"num_beams": 4,
|
| 14 |
+
"pad_token_id": 1,
|
| 15 |
+
"transformers_version": "4.41.2"
|
| 16 |
+
}
|
4-bit/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dadcc379c74fc48b0b2395f42794326901c92f98902ced7ebb9c7d369d486db5
|
| 3 |
+
size 306379320
|
handler.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, BitsAndBytesConfig
|
| 3 |
+
from typing import Any
|
| 4 |
+
|
| 5 |
+
class EndpointHandler():
|
| 6 |
+
def __init__(self, path=""):
|
| 7 |
+
self.model = AutoModelForSeq2SeqLM.from_pretrained(f"{path}/4-bit", device_map="auto")
|
| 8 |
+
self.tokenizer = AutoTokenizer.from_pretrained(path)
|
| 9 |
+
|
| 10 |
+
def __call__(self, data: dict[str, Any]) -> dict[str, Any]:
|
| 11 |
+
inputs = data.get("inputs")
|
| 12 |
+
parameters = data.get("parameters")
|
| 13 |
+
|
| 14 |
+
if inputs is None:
|
| 15 |
+
raise ValueError(f"'inputs' is missing from the request body")
|
| 16 |
+
|
| 17 |
+
if not isinstance(inputs, str):
|
| 18 |
+
raise ValueError(f"Expected 'inputs' to be a str, but found {type(inputs)}")
|
| 19 |
+
|
| 20 |
+
if parameters is not None and not isinstance(parameters, dict):
|
| 21 |
+
raise ValueError(f"Expected 'parameters' to be a dict, but found {type(parameters)}")
|
| 22 |
+
|
| 23 |
+
# Truncate the tokens to 1024 to prevent errors with BART and long text.
|
| 24 |
+
tokens = self.tokenizer(
|
| 25 |
+
inputs,
|
| 26 |
+
max_length=1024,
|
| 27 |
+
truncation=True,
|
| 28 |
+
return_tensors="pt",
|
| 29 |
+
return_attention_mask=False,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Ensure the input_ids and the model are both on the GPU to prevent errors.
|
| 33 |
+
input_ids = tokens.input_ids.to("cuda")
|
| 34 |
+
|
| 35 |
+
# Gradient calculation is not needed for inference.
|
| 36 |
+
with torch.no_grad():
|
| 37 |
+
if parameters is None:
|
| 38 |
+
output = self.model.generate(input_ids)
|
| 39 |
+
else:
|
| 40 |
+
output = self.model.generate(input_ids, **parameters)
|
| 41 |
+
|
| 42 |
+
generated_text = self.tokenizer.decode(output[0], skip_special_tokens=True)
|
| 43 |
+
return {"generated_text": generated_text}
|