Text Generation
Transformers
Safetensors
Vietnamese
mistral
LLMs
NLP
Vietnamese
conversational
text-generation-inference
Instructions to use LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2") model = AutoModelForCausalLM.from_pretrained("LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2", 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 LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2
- SGLang
How to use LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2 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 "LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2" \ --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": "LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2", "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 "LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2" \ --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": "LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2 with Docker Model Runner:
docker model run hf.co/LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2
Download run.py from LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2: direct link, hf CLI and curl.
- Browser
- Download file 2.31 kB
-
https://huggingface.co/LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2/resolve/main/run.py
- Command line
-
hf download hf://LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2/run.py
-
curl -L -o run.py https://huggingface.co/LoneStriker/Vistral-7B-ChatML-4.0bpw-h6-exl2/resolve/main/run.py
2.31 kB
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, HfArgumentParser, TrainingArguments, pipeline, logging, TextStreamer | |
| from peft import LoraConfig, PeftModel, prepare_model_for_kbit_training, get_peft_model | |
| import os, torch, wandb, platform, warnings | |
| from datasets import load_dataset | |
| from trl import SFTTrainer | |
| hf_token = '..........' | |
| tokenizer = AutoTokenizer.from_pretrained('./vistral-tokenizer') | |
| bnb_config = BitsAndBytesConfig( | |
| load_in_4bit=True, | |
| bnb_4bit_quant_type="nf4", | |
| bnb_4bit_compute_dtype=torch.bfloat16, | |
| bnb_4bit_use_double_quant=True, | |
| ) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| 'Viet-Mistral/Vistral-7B-Chat', | |
| device_map="auto", | |
| token=hf_token, | |
| quantization_config=bnb_config, | |
| ) | |
| ft_model = PeftModel.from_pretrained(model, CHECKPOINT_PATH) | |
| #torch.backends.cuda.enable_mem_efficient_sdp(False) | |
| #torch.backends.cuda.enable_flash_sdp(False) | |
| system_prompt = "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 có thể, đồng thời giữ an toàn." | |
| stop_tokens = [tokenizer.eos_token_id, tokenizer('<|im_end|>')['input_ids'].pop()] | |
| def chat_test(): | |
| conversation = [{"role": "system", "content": system_prompt }] | |
| while True: | |
| human = input("Human: ") | |
| if human.lower() == "reset": | |
| conversation = [{"role": "system", "content": system_prompt }] | |
| print("The chat history has been cleared!") | |
| continue | |
| if human.lower() == "exit": | |
| break | |
| conversation.append({"role": "user", "content": human }) | |
| formatted = tokenizer.apply_chat_template(conversation, tokenize=False) + "<|im_start|>assistant" | |
| tok = tokenizer(formatted, return_tensors="pt").to(ft_model.device) | |
| input_ids = tok['input_ids'] | |
| out_ids = ft_model.generate( | |
| input_ids=input_ids, | |
| attention_mask=tok['attention_mask'], | |
| eos_token_id=stop_tokens, | |
| max_new_tokens=50, | |
| do_sample=True, | |
| top_p=0.95, | |
| top_k=40, | |
| temperature=0.1, | |
| repetition_penalty=1.05, | |
| ) | |
| assistant = tokenizer.batch_decode(out_ids[:, input_ids.size(1): ], skip_special_tokens=True)[0].strip() | |
| print("Assistant: ", assistant) | |
| conversation.append({"role": "assistant", "content": assistant }) | |
| chat_test() |