Instructions to use AnalyticsIntelligence/PIDGIN_gemma3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AnalyticsIntelligence/PIDGIN_gemma3 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("AnalyticsIntelligence/PIDGIN_gemma3", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Desktop
Update handler.py
Browse files- handler.py +30 -9
handler.py
CHANGED
|
@@ -6,6 +6,9 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
| 6 |
from huggingface_inference_toolkit.logging import logger
|
| 7 |
|
| 8 |
model_dir = 'Ephraimmm/PIDGIN_gemma-3'
|
|
|
|
|
|
|
|
|
|
| 9 |
class EndpointHandler:
|
| 10 |
"""
|
| 11 |
Custom handler for Hugging Face Inference Endpoints.
|
|
@@ -19,16 +22,34 @@ class EndpointHandler:
|
|
| 19 |
logger.info(f"Initializing EndpointHandler with model_dir = {model_dir}")
|
| 20 |
|
| 21 |
# load tokenizer and model from the model_dir or hub
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# we assume model files are present in model_dir
|
| 23 |
-
try:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
except Exception as e:
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
| 33 |
# put the model on GPU if available
|
| 34 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 6 |
from huggingface_inference_toolkit.logging import logger
|
| 7 |
|
| 8 |
model_dir = 'Ephraimmm/PIDGIN_gemma-3'
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
class EndpointHandler:
|
| 13 |
"""
|
| 14 |
Custom handler for Hugging Face Inference Endpoints.
|
|
|
|
| 22 |
logger.info(f"Initializing EndpointHandler with model_dir = {model_dir}")
|
| 23 |
|
| 24 |
# load tokenizer and model from the model_dir or hub
|
| 25 |
+
base_model_name = "unsloth/gemma-3-4b-it-unsloth-bnb-4bit"
|
| 26 |
+
base_model, tokenizer = FastLanguageModel.from_pretrained(
|
| 27 |
+
model_name=base_model_name,
|
| 28 |
+
max_seq_length=2048,
|
| 29 |
+
dtype=torch.float16,
|
| 30 |
+
load_in_4bit=True,
|
| 31 |
+
r = 8, # Larger = higher accuracy, but might overfit
|
| 32 |
+
lora_alpha = 8, # Recommended alpha == r at least
|
| 33 |
+
lora_dropout = 0,
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# -----------------------------
|
| 37 |
+
# 3️⃣ Load LoRA
|
| 38 |
+
# -----------------------------
|
| 39 |
+
lora_repo = "Ephraimmm/PIDGIN_gemma-3" #"Ephraimmm/pigin-gemma-3-0.2" #"Ephraimmm/Pidgin_llamma_model"
|
| 40 |
+
lora_model = PeftModel.from_pretrained(base_model, lora_repo, adapter_name="adapter_model")
|
| 41 |
+
FastLanguageModel.for_inference(lora_model)
|
| 42 |
+
|
| 43 |
# we assume model files are present in model_dir
|
| 44 |
+
# try:
|
| 45 |
+
# self.tokenizer = AutoTokenizer.from_pretrained(model_dir, use_fast=False)
|
| 46 |
+
# self.model = AutoModelForCausalLM.from_pretrained(model_dir)
|
| 47 |
+
# except Exception as e:
|
| 48 |
+
# # fallback: try loading from hub name
|
| 49 |
+
# hf_model_id = "Ephraimmm/PIDGIN_gemma-3"
|
| 50 |
+
# logger.warn(f"Loading model from hub id {hf_model_id} because fallback. Exception: {e}")
|
| 51 |
+
# self.tokenizer = AutoTokenizer.from_pretrained(hf_model_id, use_fast=False)
|
| 52 |
+
# self.model = AutoModelForCausalLM.from_pretrained(hf_model_id)
|
| 53 |
|
| 54 |
# put the model on GPU if available
|
| 55 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|