Instructions to use mohommed/Testing with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use mohommed/Testing with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-1.3B") model = PeftModel.from_pretrained(base_model, "mohommed/Testing") - Transformers
How to use mohommed/Testing with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mohommed/Testing")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("mohommed/Testing", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use mohommed/Testing with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mohommed/Testing" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mohommed/Testing", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/mohommed/Testing
- SGLang
How to use mohommed/Testing 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 "mohommed/Testing" \ --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": "mohommed/Testing", "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 "mohommed/Testing" \ --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": "mohommed/Testing", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use mohommed/Testing with Docker Model Runner:
docker model run hf.co/mohommed/Testing
Create Main.py
Browse files
Main.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Install dependencies
|
| 2 |
+
!pip install transformers accelerate peft
|
| 3 |
+
|
| 4 |
+
# Import libraries
|
| 5 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 6 |
+
from peft import PeftModel, PeftConfig
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
# Load base model and PEFT adapter
|
| 10 |
+
base_model_name = "EleutherAI/gpt-neo-1.3B"
|
| 11 |
+
peft_model_name = "mohommed/Testing"
|
| 12 |
+
|
| 13 |
+
# Load tokenizer and base model
|
| 14 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
|
| 15 |
+
base_model = AutoModelForCausalLM.from_pretrained(base_model_name, device_map="auto", torch_dtype=torch.float16)
|
| 16 |
+
|
| 17 |
+
# Apply the PEFT adapter
|
| 18 |
+
model = PeftModel.from_pretrained(base_model, peft_model_name)
|
| 19 |
+
model.eval()
|
| 20 |
+
|
| 21 |
+
# Define generation function
|
| 22 |
+
def generate_article(prompt, max_new_tokens=700):
|
| 23 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 24 |
+
with torch.no_grad():
|
| 25 |
+
outputs = model.generate(
|
| 26 |
+
**inputs,
|
| 27 |
+
max_new_tokens=max_new_tokens,
|
| 28 |
+
temperature=0.8,
|
| 29 |
+
top_p=0.95,
|
| 30 |
+
do_sample=True,
|
| 31 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 32 |
+
)
|
| 33 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 34 |
+
|
| 35 |
+
# Example prompt
|
| 36 |
+
prompt = "Write a 600-word Medium article about how to stay motivated as a writer. Use a personal tone and clear structure."
|
| 37 |
+
|
| 38 |
+
# Generate article
|
| 39 |
+
output = generate_article(prompt)
|
| 40 |
+
print(output)
|