Instructions to use Moses25/Mistral-7B-Base-V1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Moses25/Mistral-7B-Base-V1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Moses25/Mistral-7B-Base-V1") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Moses25/Mistral-7B-Base-V1") model = AutoModelForCausalLM.from_pretrained("Moses25/Mistral-7B-Base-V1") 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-Base-V1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Moses25/Mistral-7B-Base-V1" # 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-Base-V1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Moses25/Mistral-7B-Base-V1
- SGLang
How to use Moses25/Mistral-7B-Base-V1 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-Base-V1" \ --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-Base-V1", "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-Base-V1" \ --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-Base-V1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Moses25/Mistral-7B-Base-V1 with Docker Model Runner:
docker model run hf.co/Moses25/Mistral-7B-Base-V1
This model is trained on 60G chinese and english instruction,a base model which enhances chiense capacity. You can dowload Moses25/Instruct-dataset11M dataset to train your own model with 32K context length. My Moses25/Mistral-7B-chat-32k is trained based on Moses25/Instruct-dataset11M dataset
git clone https://github.com/moseshu/llama-recipes
sh ft.sh
from transformers import GenerationConfig, LlamaForCausalLM, LlamaTokenizer,AutoTokenizer,AutoModelForCausalLM,MistralForCausalLM
import torch
model = AutoModelForCausalLM.from_pretrained(model_id,torch_dtype=torch.bfloat16,device_map="auto",)
from transformers import GenerationConfig, LlamaForCausalLM, LlamaTokenizer,AutoTokenizer,AutoModelForCausalLM,MistralForCausalLM
import torch
model_id=Moses25/Mistral-7B-chat-32k
tokenizer = AutoTokenizer.from_pretrained(model_id)
mistral_template="{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if loop.index0 == 0 and system_message != false %}{% set content = '<<SYS>>\\n' + system_message + '\\n<</SYS>>\\n\\n' + message['content'] %}{% else %}{% set content = message['content'] %}{% endif %}{% if message['role'] == 'user' %}{{ bos_token + '[INST] ' + content.strip() + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ ' ' + content.strip() + ' ' + eos_token }}{% endif %}{% endfor %}"
llama3_template="{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}"
def chat_format(conversation:list,tokenizer,chat_type="mistral"):
system_prompt = "You are a helpful, respectful and honest assistant.Help humman as much as you can."
ap = [{"role":"system","content":system_prompt}] + conversation
if chat_type=='mistral':
id = tokenizer.apply_chat_template(ap,chat_template=mistral_template,tokenize=False)
elif chat_type=='llama3':
id = tokenizer.apply_chat_template(ap,chat_template=llama3_template,tokenize=False)
id = id.rstrip("<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n")
return id
user_chat=[{"role":"user","content":"In a basket, there are 20 oranges, 60 apples, and 40 bananas. If 15 pears were added, and half of the oranges were removed, what would be the new ratio of oranges to apples, bananas, and pears combined within the basket?"}]
text = chat_format(user_chat,tokenizer,'mistral')
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:"""Let's break down the steps to find the new ratio of oranges to apples, bananas, and pears combined:
Calculate the total number of fruits initially in the basket: Oranges: 20 Apples: 60 Bananas: 40 Total Fruits = 20 + 60 + 40 = 120
Add 15 pears: Total Fruits after adding pears = 120 + 15 = 135
Remove half of the oranges: Oranges remaining = 20 / 2 = 10
Calculate the total number of fruits remaining in the basket after removing half of the oranges: Total Remaining Fruits = 10 (oranges) + 60 (apples) + 40 (bananas) + 15 (pears) = 125
Find the ratio of oranges to apples, bananas, and pears combined: Ratio of Oranges to (Apples, Bananas, Pears) Combined = Oranges / (Apples + Bananas + Pears) = 10 / (60 + 40 + 15) = 10 / 115
So, the new ratio of oranges to apples, bananas, and pears combined within the basket is 10:115.
However, I should note that the actual fruit distribution in your basket may vary depending on how you decide to count and categorize the fruits. The example calculation provides a theoretical ratio based on the initial quantities mentioned."""
- Downloads last month
- 7