Instructions to use shunjdy/soa-GS with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shunjdy/soa-GS with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("shunjdy/soa-GS", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Desktop
Download handler.py from shunjdy/soa-GS: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/shunjdy/soa-GS/resolve/main/handler.py
- Command line
-
hf download hf://shunjdy/soa-GS/handler.py
-
curl -L -o handler.py https://huggingface.co/shunjdy/soa-GS/resolve/main/handler.py
1.28 kB
| from typing import Dict, Any | |
| import torch | |
| from peft import PeftModel | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| BASE_MODEL_ID = "unsloth/DeepSeek-R1-Distill-Llama-70B-unsloth-bnb-4bit" | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| self.tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID) | |
| base_model = AutoModelForCausalLM.from_pretrained( | |
| BASE_MODEL_ID, | |
| torch_dtype=torch.bfloat16, | |
| device_map="auto", | |
| ) | |
| self.model = PeftModel.from_pretrained(base_model, path) | |
| self.model.eval() | |
| def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]: | |
| inputs = data.get("inputs", "") | |
| parameters = data.get("parameters", {}) | |
| input_ids = self.tokenizer( | |
| inputs, return_tensors="pt" | |
| ).input_ids.to(self.model.device) | |
| with torch.no_grad(): | |
| output_ids = self.model.generate( | |
| input_ids, | |
| max_new_tokens=parameters.get("max_new_tokens", 256), | |
| temperature=parameters.get("temperature", 0.7), | |
| ) | |
| generated_text = self.tokenizer.decode( | |
| output_ids[0], skip_special_tokens=True | |
| ) | |
| return {"generated_text": generated_text} |