Instructions to use MCS12/llama-3-xml-presentation-generator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MCS12/llama-3-xml-presentation-generator with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("MCS12/llama-3-xml-presentation-generator", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload handler.py
Browse files- handler.py +30 -4
handler.py
CHANGED
|
@@ -1,11 +1,37 @@
|
|
| 1 |
from typing import Dict, List, Any
|
| 2 |
-
from transformers import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
class EndpointHandler:
|
| 5 |
def __init__(self, path=""):
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 11 |
"""
|
|
@@ -22,7 +48,7 @@ class EndpointHandler:
|
|
| 22 |
|
| 23 |
prompt = self.apply_chat_template_for_presentation(self.tokenizer, inputs, tone, length)
|
| 24 |
input_ids = self.tokenizer(prompt, return_tensors="pt")
|
| 25 |
-
|
| 26 |
outputs = self.model.generate(
|
| 27 |
**input_ids,
|
| 28 |
max_new_tokens=8192,
|
|
|
|
| 1 |
from typing import Dict, List, Any
|
| 2 |
+
from transformers import (
|
| 3 |
+
AutoModelForCausalLM,
|
| 4 |
+
AutoTokenizer,
|
| 5 |
+
BitsAndBytesConfig,
|
| 6 |
+
TrainingArguments,
|
| 7 |
+
pipeline
|
| 8 |
+
)
|
| 9 |
|
| 10 |
class EndpointHandler:
|
| 11 |
def __init__(self, path=""):
|
| 12 |
|
| 13 |
+
bnb_config = BitsAndBytesConfig(
|
| 14 |
+
load_in_4bit=True,
|
| 15 |
+
bnb_4bit_quant_type="nf4",
|
| 16 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 17 |
+
bnb_4bit_use_double_quant=True
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
self.model = AutoModelForCausalLM.from_pretrained(
|
| 21 |
+
model_name,
|
| 22 |
+
quantization_config=bnb_config,
|
| 23 |
+
device_map="auto",
|
| 24 |
+
trust_remote_code=True,
|
| 25 |
+
use_auth_token=True
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
self.tokenizer = AutoTokenizer.from_pretrained(
|
| 29 |
+
model_name,
|
| 30 |
+
trust_remote_code=True,
|
| 31 |
+
use_auth_token=True
|
| 32 |
+
)
|
| 33 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 34 |
+
tokenizer.padding_side = "right"
|
| 35 |
|
| 36 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 37 |
"""
|
|
|
|
| 48 |
|
| 49 |
prompt = self.apply_chat_template_for_presentation(self.tokenizer, inputs, tone, length)
|
| 50 |
input_ids = self.tokenizer(prompt, return_tensors="pt")
|
| 51 |
+
|
| 52 |
outputs = self.model.generate(
|
| 53 |
**input_ids,
|
| 54 |
max_new_tokens=8192,
|