Instructions to use Moses25/Mistral-7B-Instruct-V0.3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Moses25/Mistral-7B-Instruct-V0.3 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Moses25/Mistral-7B-Instruct-V0.3") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Moses25/Mistral-7B-Instruct-V0.3") model = AutoModelForCausalLM.from_pretrained("Moses25/Mistral-7B-Instruct-V0.3") 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
- vLLM
How to use Moses25/Mistral-7B-Instruct-V0.3 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Moses25/Mistral-7B-Instruct-V0.3" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Moses25/Mistral-7B-Instruct-V0.3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Moses25/Mistral-7B-Instruct-V0.3
- SGLang
How to use Moses25/Mistral-7B-Instruct-V0.3 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 "Moses25/Mistral-7B-Instruct-V0.3" \ --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": "Moses25/Mistral-7B-Instruct-V0.3", "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 "Moses25/Mistral-7B-Instruct-V0.3" \ --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": "Moses25/Mistral-7B-Instruct-V0.3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Moses25/Mistral-7B-Instruct-V0.3 with Docker Model Runner:
docker model run hf.co/Moses25/Mistral-7B-Instruct-V0.3
This model is trained from Mistral-7B-Instruct-V0.2 with 90% chinese dataset and 10% english dataset
github Web-UI
from transformers import GenerationConfig, LlamaForCausalLM, LlamaTokenizer,AutoTokenizer,AutoModelForCausalLM,MistralForCausalLM
import torch
model_id=Mistral-7B-Instruct-v0.3
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id,torch_dtype=torch.bfloat16,device_map="auto",)
prompt = "[INST] <<SYS>>\nYou are a helpful, respectful and honest assistant.Help humman as much as you can.\n<</SYS>>\n\n{instruction} [/INST]"
text = prompt.format_map({"instruction":"你好,最近干嘛呢"})
def predict(content_prompt):
inputs = tokenizer(content_prompt,return_tensors="pt",add_special_tokens=True)
input_ids = inputs["input_ids"].to("cuda:0")
# print(f"input length:{len(input_ids[0])}")
with torch.no_grad():
generation_output = model.generate(
input_ids=input_ids,
#generation_config=generation_config,
return_dict_in_generate=True,
output_scores=True,
max_new_tokens=2048,
top_p=0.9,
num_beams=1,
do_sample=True,
repetition_penalty=1.0,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
)
s = generation_output.sequences[0]
output = tokenizer.decode(s,skip_special_tokens=True)
output1 = output.split("[/INST]")[-1].strip()
# print(output1)
return output1
predict(text)
output:你好!作为一个大型语言模型,我一直在学习和提高自己的能力。最近,我一直在努力学习新知识、改进算法,以便更好地回答用户的问题并提供帮助。同时,我也会定期接受人工智能专家的指导和评估,以确保我的表现不断提升。希望这些信息对你有所帮助!
- Downloads last month
- 11
