Instructions to use BinaryLight1011/Context with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use BinaryLight1011/Context with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("BinaryLight1011/Context", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Desktop
Jefferson de Azevedo commited on
Create handle.py
Browse files
handle.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from unsloth import FastLanguageModel
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
class EndpointHandler:
|
| 5 |
+
def __init__(self, path=""):
|
| 6 |
+
self.model, self.tokenizer = FastLanguageModel.from_pretrained(
|
| 7 |
+
model_name=path,
|
| 8 |
+
max_seq_length=2048,
|
| 9 |
+
dtype=None,
|
| 10 |
+
load_in_4bit=True,
|
| 11 |
+
)
|
| 12 |
+
FastLanguageModel.for_inference(self.model)
|
| 13 |
+
|
| 14 |
+
def __call__(self, data: dict):
|
| 15 |
+
inputs_text = data.pop("inputs", "")
|
| 16 |
+
parameters = data.pop("parameters", {})
|
| 17 |
+
|
| 18 |
+
inputs = self.tokenizer(
|
| 19 |
+
inputs_text,
|
| 20 |
+
return_tensors="pt"
|
| 21 |
+
).to("cuda")
|
| 22 |
+
|
| 23 |
+
outputs = self.model.generate(
|
| 24 |
+
**inputs,
|
| 25 |
+
max_new_tokens=parameters.get("max_new_tokens", 256),
|
| 26 |
+
temperature=parameters.get("temperature", 0.7),
|
| 27 |
+
do_sample=True,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
return self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|