Instructions to use BucketOfFish/simplified_phi2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use BucketOfFish/simplified_phi2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="BucketOfFish/simplified_phi2", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("BucketOfFish/simplified_phi2", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use BucketOfFish/simplified_phi2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "BucketOfFish/simplified_phi2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BucketOfFish/simplified_phi2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/BucketOfFish/simplified_phi2
- SGLang
How to use BucketOfFish/simplified_phi2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "BucketOfFish/simplified_phi2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BucketOfFish/simplified_phi2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "BucketOfFish/simplified_phi2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BucketOfFish/simplified_phi2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use BucketOfFish/simplified_phi2 with Docker Model Runner:
docker model run hf.co/BucketOfFish/simplified_phi2
Commit ·
16cc769
1
Parent(s): a420fe7
Updated imports in script
Browse files- streaming_inference.py +6 -6
streaming_inference.py
CHANGED
|
@@ -3,8 +3,8 @@ from threading import Thread
|
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 4 |
import torch
|
| 5 |
|
| 6 |
-
from .
|
| 7 |
-
from .
|
| 8 |
|
| 9 |
|
| 10 |
# This works, but is not streaming
|
|
@@ -12,8 +12,8 @@ from .modeling_phi import PhiForCausalLM
|
|
| 12 |
if __name__ == "__main__":
|
| 13 |
device = "cuda"
|
| 14 |
|
| 15 |
-
model_config =
|
| 16 |
-
model =
|
| 17 |
phi_model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", trust_remote_code=True)
|
| 18 |
model.load_state_dict(phi_model.state_dict())
|
| 19 |
|
|
@@ -45,8 +45,8 @@ if __name__ == "__main__":
|
|
| 45 |
|
| 46 |
# make model and run model.generate(streamer=TextIteratorStreamer) on a thread
|
| 47 |
device = "cuda"
|
| 48 |
-
model_config =
|
| 49 |
-
model =
|
| 50 |
phi_model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", trust_remote_code=True)
|
| 51 |
model.load_state_dict(phi_model.state_dict())
|
| 52 |
thread = Thread(
|
|
|
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
from .phi2_configuration import Phi2Config
|
| 7 |
+
from .phi2_model import Phi2ModelForCausalLM
|
| 8 |
|
| 9 |
|
| 10 |
# This works, but is not streaming
|
|
|
|
| 12 |
if __name__ == "__main__":
|
| 13 |
device = "cuda"
|
| 14 |
|
| 15 |
+
model_config = Phi2Config(**json.load(open("simplified_phi2/config.json")))
|
| 16 |
+
model = Phi2ModelForCausalLM(model_config).to(device)
|
| 17 |
phi_model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", trust_remote_code=True)
|
| 18 |
model.load_state_dict(phi_model.state_dict())
|
| 19 |
|
|
|
|
| 45 |
|
| 46 |
# make model and run model.generate(streamer=TextIteratorStreamer) on a thread
|
| 47 |
device = "cuda"
|
| 48 |
+
model_config = Phi2Config(**json.load(open("simplified_phi2/config.json")))
|
| 49 |
+
model = Phi2ModelForCausalLM(model_config).to(device)
|
| 50 |
phi_model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", trust_remote_code=True)
|
| 51 |
model.load_state_dict(phi_model.state_dict())
|
| 52 |
thread = Thread(
|