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 +20 -14
handler.py
CHANGED
|
@@ -12,24 +12,30 @@ from transformers import (
|
|
| 12 |
class EndpointHandler:
|
| 13 |
def __init__(self, path=""):
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
self.model =
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
self.tokenizer = AutoTokenizer.from_pretrained(
|
| 35 |
path,
|
|
|
|
| 12 |
class EndpointHandler:
|
| 13 |
def __init__(self, path=""):
|
| 14 |
|
| 15 |
+
peft_config = PeftConfig.from_pretrained(path)
|
| 16 |
+
|
| 17 |
+
# Load the base model with quantization
|
| 18 |
+
bnb_config = BitsAndBytesConfig(
|
| 19 |
+
load_in_4bit=True,
|
| 20 |
+
bnb_4bit_quant_type="nf4",
|
| 21 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 22 |
+
bnb_4bit_use_double_quant=True,
|
| 23 |
)
|
| 24 |
|
| 25 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 26 |
+
peft_config.base_model_name_or_path,
|
| 27 |
+
quantization_config=bnb_config,
|
| 28 |
+
device_map="auto",
|
| 29 |
+
trust_remote_code=True,
|
| 30 |
+
torch_dtype=torch.float16,
|
| 31 |
)
|
| 32 |
|
| 33 |
+
# Load the LoRA adapter with the correct configuration
|
| 34 |
+
self.model = PeftModel.from_pretrained(
|
| 35 |
+
base_model,
|
| 36 |
+
path,
|
| 37 |
+
torch_dtype=torch.float16,
|
| 38 |
+
)
|
| 39 |
|
| 40 |
self.tokenizer = AutoTokenizer.from_pretrained(
|
| 41 |
path,
|