Summarization
Transformers
Safetensors
English
phi
text-generation
arxiv
custom_code
text-generation-inference
Instructions to use AlgorithmicResearchGroup/phi-metamath with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AlgorithmicResearchGroup/phi-metamath with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "summarization" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # pip install "transformers<5.0.0" from transformers import pipeline pipe = pipeline("summarization", model="AlgorithmicResearchGroup/phi-metamath", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("AlgorithmicResearchGroup/phi-metamath", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("AlgorithmicResearchGroup/phi-metamath", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download handler.py from AlgorithmicResearchGroup/phi-metamath: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/AlgorithmicResearchGroup/phi-metamath/resolve/main/handler.py
- Command line
-
hf download hf://AlgorithmicResearchGroup/phi-metamath/handler.py
-
curl -L -o handler.py https://huggingface.co/AlgorithmicResearchGroup/phi-metamath/resolve/main/handler.py
1.38 kB
| from typing import Dict, List, Any | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig | |
| import torch | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| self.base_model = path | |
| bitsandbytes= BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_use_double_quant=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.float16) | |
| self.model = AutoModelForCausalLM.from_pretrained(self.base_model, device_map={"":0},quantization_config= bitsandbytes, trust_remote_code= True) | |
| self.tokenizer = AutoTokenizer.from_pretrained(self.base_model, trust_remote_code=True) | |
| self.tokenizer.pad_token = self.tokenizer.eos_token | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| inputs = data.pop("inputs",data) | |
| prompt = f"Below is an instruction that describes a task. Write a response that appropriately completes the request. ### Instruction: {inputs} ### Response:" | |
| model_inputs = self.tokenizer([prompt], return_tensors="pt", padding=True).to("cuda") | |
| generated_ids = self.model.generate(**model_inputs, max_length=200) | |
| output = self.tokenizer.batch_decode(generated_ids, skip_special_tokens=True) | |
| answer_without_prompt = output[0].split("### Response:")[1].strip() | |
| prediction = answer_without_prompt.split("###")[0].strip() | |
| return [{"generated_text": prediction}] |