Instructions to use salforis/vistral_text_gen with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use salforis/vistral_text_gen with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="salforis/vistral_text_gen") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("salforis/vistral_text_gen") model = AutoModelForCausalLM.from_pretrained("salforis/vistral_text_gen", 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 salforis/vistral_text_gen with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "salforis/vistral_text_gen" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "salforis/vistral_text_gen", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/salforis/vistral_text_gen
- SGLang
How to use salforis/vistral_text_gen 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 "salforis/vistral_text_gen" \ --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": "salforis/vistral_text_gen", "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 "salforis/vistral_text_gen" \ --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": "salforis/vistral_text_gen", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use salforis/vistral_text_gen with Docker Model Runner:
docker model run hf.co/salforis/vistral_text_gen
Usage
This model is finetuned from Viet-Mistral/Vistral-7B-Chat.
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, AutoConfig
import torch
model_id = "salforis/vistral_text_gen"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype = torch.float16,
device_map = "auto",
use_cache = True,
)
system_prompt: str = "Bạn là một trợ lý tiếng Việt nhiệt tình và trung thực. Hãy luôn trả lời một cách hữu ích nhất và chính xác nhất có thể, tránh việc đưa ra thông tin sai lệch."
document= """
phản bác lại nội dung sau: "Chúc mừng TNLT Huỳnh Thục Vy đã mãn hạn lao tù cộng sản trở về với gia đình. Ước mong chị sớm hồi phục sức khỏe và bình an."
"""
conversation = [{"role": "system", "content": system_prompt }]
# while True:
human = (f"Hãy giúp tôi phân tích sâu chủ đề sau đây bằng văn phong báo chí, chính luận:/n{document}")
conversation.append({"role": "user", "content": human })
input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt").to(model.device) ### nếu dùng GPU
with torch.no_grad():
out_ids = model.generate(
input_ids = input_ids,
max_new_tokens = 4096,
top_p = 1.0,
top_k = 40,
do_sample = True,
temperature = 0.5,
repetition_penalty = 1.0,
eos_token_id = tokenizer.eos_token_id,
use_cache = True,
)
assistant = tokenizer.batch_decode(out_ids[:, input_ids.size(1): ], skip_special_tokens=True)[0].strip()
print("Kết quả: ", assistant)
- Downloads last month
- -