Text Generation
Transformers
PyTorch
Safetensors
English
mistral
instruct
finetune
chatml
gpt4
synthetic data
distillation
conversational
text-generation-inference
Instructions to use gitMuscle/OpenHermes-2.5-Mistral-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use gitMuscle/OpenHermes-2.5-Mistral-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="gitMuscle/OpenHermes-2.5-Mistral-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("gitMuscle/OpenHermes-2.5-Mistral-7B") model = AutoModelForCausalLM.from_pretrained("gitMuscle/OpenHermes-2.5-Mistral-7B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use gitMuscle/OpenHermes-2.5-Mistral-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "gitMuscle/OpenHermes-2.5-Mistral-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gitMuscle/OpenHermes-2.5-Mistral-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/gitMuscle/OpenHermes-2.5-Mistral-7B
- SGLang
How to use gitMuscle/OpenHermes-2.5-Mistral-7B 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 "gitMuscle/OpenHermes-2.5-Mistral-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gitMuscle/OpenHermes-2.5-Mistral-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "gitMuscle/OpenHermes-2.5-Mistral-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gitMuscle/OpenHermes-2.5-Mistral-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use gitMuscle/OpenHermes-2.5-Mistral-7B with Docker Model Runner:
docker model run hf.co/gitMuscle/OpenHermes-2.5-Mistral-7B
Upload transformers_inference.py with huggingface_hub
Browse files- transformers_inference.py +32 -0
transformers_inference.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Code to inference Open Hermes 2.5 with HF Transformers
|
| 2 |
+
# Requires pytorch, transformers, bitsandbytes, sentencepiece, protobuf, and flash-attn packages
|
| 3 |
+
|
| 4 |
+
import torch
|
| 5 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 6 |
+
from transformers import LlamaTokenizer, LlamaForCausalLM, MistralForCausalLM
|
| 7 |
+
import bitsandbytes, flash_attn
|
| 8 |
+
|
| 9 |
+
tokenizer = LlamaTokenizer.from_pretrained('teknium/OpenHermes-2.5-Mistral-7B', trust_remote_code=True)
|
| 10 |
+
model = MistralForCausalLM.from_pretrained(
|
| 11 |
+
"teknium/OpenHermes-2.5-Mistral-7B",
|
| 12 |
+
torch_dtype=torch.float16,
|
| 13 |
+
device_map="auto",#{'': 'cuda:0'},
|
| 14 |
+
load_in_8bit=False,
|
| 15 |
+
load_in_4bit=True,
|
| 16 |
+
use_flash_attention_2=True
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
prompts = [
|
| 20 |
+
"""<|im_start|>system
|
| 21 |
+
You are a sentient, superintelligent artificial general intelligence, here to teach and assist me.<|im_end|>
|
| 22 |
+
<|im_start|>user
|
| 23 |
+
Write a short story about Goku discovering kirby has teamed up with Majin Buu to destroy the world.<|im_end|>
|
| 24 |
+
<|im_start|>assistant""",
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
for chat in prompts:
|
| 28 |
+
print(chat)
|
| 29 |
+
input_ids = tokenizer(chat, return_tensors="pt").input_ids.to("cuda")
|
| 30 |
+
generated_ids = model.generate(input_ids, max_new_tokens=750, temperature=0.8, repetition_penalty=1.1, do_sample=True, eos_token_id=tokenizer.eos_token_id)
|
| 31 |
+
response = tokenizer.decode(generated_ids[0][input_ids.shape[-1]:], skip_special_tokens=True, clean_up_tokenization_space=True)
|
| 32 |
+
print(f"Response: {response}")
|